1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Finally refactored lastfm import

This commit is contained in:
Krateng 2019-12-15 15:27:16 +01:00
parent dbc23ca73c
commit e50cce28fa
4 changed files with 68 additions and 50 deletions

View File

@ -2,7 +2,7 @@ import tarfile
from datetime import datetime
import glob
import os
from globalconf import datadir
from .globalconf import datadir
user_files = {

View File

@ -25,8 +25,17 @@ class CleanerAgent:
#self.rules_regextitle = [[b,c] for [a,b,c,d] in raw if a=="regextitle"]
# TODO
#self.plugin_artistparsers = []
#self.plugin_titleparsers = []
#if settings.get_settings("USE_PARSE_PLUGINS"):
# for ep in pkg_resources.iter_entry_points(group='maloja.artistparsers'):
# self.plugin_artistparsers.append(ep.load())
# for ep in pkg_resources.iter_entry_points(group='maloja.titleparsers'):
# self.plugin_titleparsers.append(ep.load())
# we always need to be able to tell if our current database is made with the current rules
self.checksums = utilities.checksumTSV("rules")
self.checksums = utilities.checksumTSV(datadir("rules"))
@ -125,9 +134,12 @@ class CleanerAgent:
for s in settings.get_settings("REMOVE_FROM_TITLE"):
if s in t:
t = t.replace(s,"").strip()
t = t.replace(s,"")
return t.strip()
t = t.strip()
#for p in self.plugin_titleparsers:
# t = p(t).strip()
return t
def parseTitleForArtists(self,t):
for d in self.delimiters_feat:

View File

@ -144,10 +144,8 @@ def stop():
def loadlastfm(filename):
try:
filename = os.path.join(origpath,filename)
except:
print("Please specify a file!")
if not os.path.exists(filename):
print("File could not be found.")
return
if os.path.exists(datadir("scrobbles/lastfmimport.tsv")):
@ -157,7 +155,9 @@ def loadlastfm(filename):
else:
return
print("Please wait...")
os.system("python3 -m maloja.lastfmconverter " + filename + " " + datadir("scrobbles/lastfmimport.tsv"))
from .lastfmconverter import convert
convert(filename,datadir("scrobbles/lastfmimport.tsv"))
#os.system("python3 -m maloja.lastfmconverter " + filename + " " + datadir("scrobbles/lastfmimport.tsv"))
print("Successfully imported your Last.FM scrobbles!")
def direct():

View File

@ -1,17 +1,23 @@
import sys, os, datetime, re, cleanup
import os, datetime, re
from .cleanup import *
from .utilities import *
log = open(sys.argv[1])
outputlog = open(sys.argv[2],"w")
checksumfile = open(sys.argv[2] + ".rulestate","w") #this file stores an identifier for all rules that were in place when the corresponding file was created
c = CleanerAgent()
stamps = [99999999999999]
for l in log:
def convert(input,output):
log = open(input,"r")
outputlog = open(output,"w")
checksumfile = open(output + ".rulestate","w") #this file stores an identifier for all rules that were in place when the corresponding file was created
stamps = [99999999999999]
for l in log:
l = l.replace("\n","")
data = l.split(",")
@ -56,8 +62,8 @@ for l in log:
outputlog.write(entry)
outputlog.write("\n")
checksumfile.write(c.checksums)
checksumfile.write(c.checksums)
log.close()
outputlog.close()
checksumfile.close()
log.close()
outputlog.close()
checksumfile.close()