mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added handling for invalid Spotify scrobbles
This commit is contained in:
parent
97aed7e73c
commit
38f2173bde
@ -4,7 +4,7 @@
|
|||||||
# you know what f*ck it
|
# you know what f*ck it
|
||||||
# this is hardcoded for now because of that damn project / package name discrepancy
|
# this is hardcoded for now because of that damn project / package name discrepancy
|
||||||
# i'll fix it one day
|
# i'll fix it one day
|
||||||
VERSION = "2.14.6"
|
VERSION = "2.14.7"
|
||||||
HOMEPAGE = "https://github.com/krateng/maloja"
|
HOMEPAGE = "https://github.com/krateng/maloja"
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,8 +14,10 @@ def loadexternal(filename):
|
|||||||
print("Please wait...")
|
print("Please wait...")
|
||||||
|
|
||||||
from .importer import import_scrobbles
|
from .importer import import_scrobbles
|
||||||
imported,failed = import_scrobbles(filename)
|
imported,failed,warning = import_scrobbles(filename)
|
||||||
print("Successfully imported",imported,"scrobbles!")
|
print("Successfully imported",imported,"scrobbles!")
|
||||||
|
if warning > 0:
|
||||||
|
print(col['orange'](str(warning) + " Warnings!"))
|
||||||
if failed > 0:
|
if failed > 0:
|
||||||
print(col['red'](str(failed) + " Errors!"))
|
print(col['red'](str(failed) + " Errors!"))
|
||||||
|
|
||||||
|
@ -39,11 +39,14 @@ def import_scrobbles(inputf):
|
|||||||
with open(outputf,"w") as outputfd:
|
with open(outputf,"w") as outputfd:
|
||||||
success = 0
|
success = 0
|
||||||
failed = 0
|
failed = 0
|
||||||
|
warning = 0
|
||||||
timestamps = set()
|
timestamps = set()
|
||||||
|
|
||||||
for scrobble in importfunc(inputf):
|
for scrobble in importfunc(inputf):
|
||||||
if scrobble is None:
|
if scrobble is None:
|
||||||
failed += 1
|
failed += 1
|
||||||
|
if scrobble is False:
|
||||||
|
warning += 1
|
||||||
else:
|
else:
|
||||||
success += 1
|
success += 1
|
||||||
|
|
||||||
@ -73,7 +76,7 @@ def import_scrobbles(inputf):
|
|||||||
if success % 100 == 0:
|
if success % 100 == 0:
|
||||||
print(f"Imported {success} scrobbles...")
|
print(f"Imported {success} scrobbles...")
|
||||||
|
|
||||||
return success,failed
|
return success,failed,warning
|
||||||
|
|
||||||
|
|
||||||
def parse_spotify(inputf):
|
def parse_spotify(inputf):
|
||||||
@ -84,22 +87,34 @@ def parse_spotify(inputf):
|
|||||||
|
|
||||||
sec = int(entry['ms_played'] / 1000)
|
sec = int(entry['ms_played'] / 1000)
|
||||||
|
|
||||||
if sec > 30:
|
if entry['master_metadata_track_name'] is None:
|
||||||
try:
|
print(col['orange'](f"{entry} has no title, skipping..."))
|
||||||
yield {
|
yield False
|
||||||
'title':entry['master_metadata_track_name'],
|
continue
|
||||||
'artiststr': entry['master_metadata_album_artist_name'],
|
if entry['master_metadata_album_artist_name'] is None:
|
||||||
'album': entry['master_metadata_album_album_name'],
|
print(col['orange'](f"{entry} has no artist, skipping..."))
|
||||||
'timestamp': int(datetime.datetime.strptime(
|
yield False
|
||||||
entry['ts'].replace('Z','+0000',),
|
continue
|
||||||
"%Y-%m-%dT%H:%M:%S%z"
|
if sec < 30:
|
||||||
).timestamp()),
|
print(col['orange'](f"{entry} is shorter than 30 seconds, skipping..."))
|
||||||
'duration':sec
|
yield False
|
||||||
}
|
continue
|
||||||
except:
|
|
||||||
print(col['red'](str(entry) + " could not be parsed. Scrobble not imported."))
|
try:
|
||||||
yield None
|
yield {
|
||||||
continue
|
'title':entry['master_metadata_track_name'],
|
||||||
|
'artiststr': entry['master_metadata_album_artist_name'],
|
||||||
|
'album': entry['master_metadata_album_album_name'],
|
||||||
|
'timestamp': int(datetime.datetime.strptime(
|
||||||
|
entry['ts'].replace('Z','+0000',),
|
||||||
|
"%Y-%m-%dT%H:%M:%S%z"
|
||||||
|
).timestamp()),
|
||||||
|
'duration':sec
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
print(col['red'](f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})"))
|
||||||
|
yield None
|
||||||
|
continue
|
||||||
|
|
||||||
def parse_lastfm(inputf):
|
def parse_lastfm(inputf):
|
||||||
|
|
||||||
@ -110,7 +125,7 @@ def parse_lastfm(inputf):
|
|||||||
try:
|
try:
|
||||||
artist,album,title,time = row
|
artist,album,title,time = row
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print(col['red'](str(row) + " does not look like a valid entry. Scrobble not imported."))
|
print(col['red'](f"{row} does not look like a valid entry. Scrobble not imported."))
|
||||||
yield None
|
yield None
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -125,7 +140,7 @@ def parse_lastfm(inputf):
|
|||||||
).timestamp()),
|
).timestamp()),
|
||||||
'duration':None
|
'duration':None
|
||||||
}
|
}
|
||||||
except:
|
except Exception as e:
|
||||||
print(col['red'](str(row) + " could not be parsed. Scrobble not imported."))
|
print(col['red'](f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})"))
|
||||||
yield None
|
yield None
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user