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

Fixed continued scrobble import after error

This commit is contained in:
krateng 2022-03-29 17:41:16 +02:00
parent 38f2173bde
commit 3108b368ef

View File

@ -5,14 +5,16 @@ import json, csv
from ...cleanup import * from ...cleanup import *
from doreah.io import col, ask from doreah.io import col, ask
from ...globalconf import data_dir from ...globalconf import data_dir
#from ...utilities import *
c = CleanerAgent() c = CleanerAgent()
def warn(msg):
print(col['orange'](msg))
def err(msg):
print(col['red'](msg))
def import_scrobbles(inputf): def import_scrobbles(inputf):
@ -45,7 +47,7 @@ def import_scrobbles(inputf):
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: elif scrobble is False:
warning += 1 warning += 1
else: else:
success += 1 success += 1
@ -88,15 +90,15 @@ def parse_spotify(inputf):
sec = int(entry['ms_played'] / 1000) sec = int(entry['ms_played'] / 1000)
if entry['master_metadata_track_name'] is None: if entry['master_metadata_track_name'] is None:
print(col['orange'](f"{entry} has no title, skipping...")) warn(f"{entry} has no title, skipping...")
yield False yield False
continue continue
if entry['master_metadata_album_artist_name'] is None: if entry['master_metadata_album_artist_name'] is None:
print(col['orange'](f"{entry} has no artist, skipping...")) warn(f"{entry} has no artist, skipping...")
yield False yield False
continue continue
if sec < 30: if sec < 30:
print(col['orange'](f"{entry} is shorter than 30 seconds, skipping...")) warn(f"{entry} is shorter than 30 seconds, skipping...")
yield False yield False
continue continue
@ -112,7 +114,7 @@ def parse_spotify(inputf):
'duration':sec 'duration':sec
} }
except Exception as e: except Exception as e:
print(col['red'](f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")) err(f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
yield None yield None
continue continue
@ -125,7 +127,7 @@ def parse_lastfm(inputf):
try: try:
artist,album,title,time = row artist,album,title,time = row
except ValueError: except ValueError:
print(col['red'](f"{row} does not look like a valid entry. Scrobble not imported.")) warn(f"{row} does not look like a valid entry. Scrobble not imported.")
yield None yield None
continue continue
@ -141,6 +143,6 @@ def parse_lastfm(inputf):
'duration':None 'duration':None
} }
except Exception as e: except Exception as e:
print(col['red'](f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")) err(f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
yield None yield None
continue continue