mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04:00
Make Maloja export file recognition more resilient, fix GH-309
This commit is contained in:
parent
966739e677
commit
472281230c
@ -12,11 +12,12 @@ def export(targetfolder=None):
|
|||||||
targetfolder = os.getcwd()
|
targetfolder = os.getcwd()
|
||||||
|
|
||||||
timestr = time.strftime("%Y_%m_%d_%H_%M_%S")
|
timestr = time.strftime("%Y_%m_%d_%H_%M_%S")
|
||||||
|
timestamp = int(time.time()) # ok this is technically a separate time get from above, but those ms are not gonna matter, and im too lazy to change it all to datetime
|
||||||
filename = f"maloja_export_{timestr}.json"
|
filename = f"maloja_export_{timestr}.json"
|
||||||
outputfile = os.path.join(targetfolder,filename)
|
outputfile = os.path.join(targetfolder,filename)
|
||||||
assert not os.path.exists(outputfile)
|
assert not os.path.exists(outputfile)
|
||||||
|
|
||||||
data = {'scrobbles':get_scrobbles()}
|
data = {'maloja':{'export_time': timestamp },'scrobbles':get_scrobbles()}
|
||||||
with open(outputfile,'w') as outfd:
|
with open(outputfile,'w') as outfd:
|
||||||
json.dump(data,outfd,indent=3)
|
json.dump(data,outfd,indent=3)
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ def import_scrobbles(inputf):
|
|||||||
}
|
}
|
||||||
|
|
||||||
filename = os.path.basename(inputf)
|
filename = os.path.basename(inputf)
|
||||||
|
importfunc = None
|
||||||
|
|
||||||
|
|
||||||
if re.match(r".*\.csv",filename):
|
if re.match(r".*\.csv",filename):
|
||||||
typeid,typedesc = "lastfm","Last.fm"
|
typeid,typedesc = "lastfm","Last.fm"
|
||||||
@ -62,7 +64,17 @@ def import_scrobbles(inputf):
|
|||||||
typeid,typedesc = "rockbox","Rockbox"
|
typeid,typedesc = "rockbox","Rockbox"
|
||||||
importfunc = parse_rockbox
|
importfunc = parse_rockbox
|
||||||
|
|
||||||
else:
|
elif re.match(r".*\.json",filename):
|
||||||
|
try:
|
||||||
|
with open(filename,'r') as fd:
|
||||||
|
data = json.load(fd)
|
||||||
|
if 'maloja' in data:
|
||||||
|
typeid,typedesc = "maloja","Maloja"
|
||||||
|
importfunc = parse_maloja
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not importfunc:
|
||||||
print("File",inputf,"could not be identified as a valid import source.")
|
print("File",inputf,"could not be identified as a valid import source.")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user