mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Improved import feedback output logic
This commit is contained in:
parent
c150a57090
commit
ca2596cfc9
@ -9,13 +9,13 @@ from ...globalconf import data_dir
|
|||||||
|
|
||||||
c = CleanerAgent()
|
c = CleanerAgent()
|
||||||
|
|
||||||
|
outputs = {
|
||||||
def warn(msg):
|
"CONFIDENT_IMPORT": lambda msg: None,
|
||||||
print(col['orange'](msg))
|
"UNCERTAIN_IMPORT": lambda msg: print(col['orange'](msg)),
|
||||||
def skip(msg):
|
"CONFIDENT_SKIP": lambda msg: print(col['ffcba4'](msg)),
|
||||||
print(col['#ffcba4'](msg))
|
"UNCERTAIN_SKIP": lambda msg: print(col['orange'](msg)),
|
||||||
def err(msg):
|
"FAIL": lambda msg: print(col['red'](msg)),
|
||||||
print(col['red'](msg))
|
}
|
||||||
|
|
||||||
|
|
||||||
def import_scrobbles(inputf):
|
def import_scrobbles(inputf):
|
||||||
@ -74,8 +74,9 @@ def import_scrobbles(inputf):
|
|||||||
|
|
||||||
timestamps = set()
|
timestamps = set()
|
||||||
|
|
||||||
for status,scrobble in importfunc(inputf):
|
for status,scrobble,msg in importfunc(inputf):
|
||||||
result[status] += 1
|
result[status] += 1
|
||||||
|
outputs[status](msg)
|
||||||
if status in ['CONFIDENT_IMPORT','UNCERTAIN_IMPORT']:
|
if status in ['CONFIDENT_IMPORT','UNCERTAIN_IMPORT']:
|
||||||
|
|
||||||
while scrobble['timestamp'] in timestamps:
|
while scrobble['timestamp'] in timestamps:
|
||||||
@ -130,8 +131,7 @@ def parse_spotify_lite(inputf):
|
|||||||
title = entry['trackName']
|
title = entry['trackName']
|
||||||
|
|
||||||
if played < 30:
|
if played < 30:
|
||||||
skip(f"{entry} is shorter than 30 seconds, skipping...")
|
yield ('CONFIDENT_SKIP',None,f"{entry} is shorter than 30 seconds, skipping...")
|
||||||
yield ('CONFIDENT_SKIP',None)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield ("CONFIDENT_IMPORT",{
|
yield ("CONFIDENT_IMPORT",{
|
||||||
@ -140,10 +140,9 @@ def parse_spotify_lite(inputf):
|
|||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'duration':played,
|
'duration':played,
|
||||||
'album': None
|
'album': None
|
||||||
})
|
},'')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err(f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
|
yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
|
||||||
yield ('FAIL',None)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
@ -182,16 +181,13 @@ def parse_spotify_full(inputf):
|
|||||||
|
|
||||||
|
|
||||||
if title is None:
|
if title is None:
|
||||||
skip(f"{entry} has no title, skipping...")
|
yield ('CONFIDENT_SKIP',None,f"{entry} has no title, skipping...")
|
||||||
yield ('CONFIDENT_SKIP',None)
|
|
||||||
continue
|
continue
|
||||||
if artist is None:
|
if artist is None:
|
||||||
skip(f"{entry} has no artist, skipping...")
|
yield ('CONFIDENT_SKIP',None,f"{entry} has no artist, skipping...")
|
||||||
yield ('CONFIDENT_SKIP',None)
|
|
||||||
continue
|
continue
|
||||||
if played < 30:
|
if played < 30:
|
||||||
skip(f"{entry} is shorter than 30 seconds, skipping...")
|
yield ('CONFIDENT_SKIP',None,f"{entry} is shorter than 30 seconds, skipping...")
|
||||||
yield ('CONFIDENT_SKIP',None)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# if offline_timestamp is a proper number, we treat it as
|
# if offline_timestamp is a proper number, we treat it as
|
||||||
@ -199,11 +195,11 @@ def parse_spotify_full(inputf):
|
|||||||
if timestamp != 0:
|
if timestamp != 0:
|
||||||
|
|
||||||
if timestamp in timestamps and (artist,title) in timestamps[timestamp]:
|
if timestamp in timestamps and (artist,title) in timestamps[timestamp]:
|
||||||
skip(f"{entry} seems to be a duplicate, skipping...")
|
yield ('CONFIDENT_SKIP',None,f"{entry} seems to be a duplicate, skipping...")
|
||||||
yield ('CONFIDENT_SKIP',None)
|
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
status = 'CONFIDENT_IMPORT'
|
status = 'CONFIDENT_IMPORT'
|
||||||
|
msg = ''
|
||||||
timestamps.setdefault(timestamp,[]).append((artist,title))
|
timestamps.setdefault(timestamp,[]).append((artist,title))
|
||||||
|
|
||||||
# if it's 0, we use ts instead, but identify duplicates differently
|
# if it's 0, we use ts instead, but identify duplicates differently
|
||||||
@ -227,14 +223,13 @@ def parse_spotify_full(inputf):
|
|||||||
# - exact same track uri
|
# - exact same track uri
|
||||||
# - exact same ms_played
|
# - exact same ms_played
|
||||||
if (abs(scr[0] - timestamp) < 30) and scr[1:] == scrobble_describe[1:]:
|
if (abs(scr[0] - timestamp) < 30) and scr[1:] == scrobble_describe[1:]:
|
||||||
warn(f"{entry} might be a duplicate, skipping...")
|
yield ('UNCERTAIN_SKIP',None,f"{entry} might be a duplicate, skipping...")
|
||||||
yield ('UNCERTAIN_SKIP',None)
|
|
||||||
found_similar = True
|
found_similar = True
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# no duplicates, assume proper scrobble but warn
|
# no duplicates, assume proper scrobble but warn
|
||||||
status = 'UNCERTAIN_IMPORT'
|
status = 'UNCERTAIN_IMPORT'
|
||||||
warn(f"{entry} might have an inaccurate timestamp.")
|
msg = f"{entry} might have an inaccurate timestamp."
|
||||||
inaccurate_timestamps.setdefault(ts_group,[]).append(scrobble_describe)
|
inaccurate_timestamps.setdefault(ts_group,[]).append(scrobble_describe)
|
||||||
|
|
||||||
if found_similar:
|
if found_similar:
|
||||||
@ -247,10 +242,9 @@ def parse_spotify_full(inputf):
|
|||||||
'album': album,
|
'album': album,
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'duration':played
|
'duration':played
|
||||||
})
|
},msg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err(f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
|
yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
|
||||||
yield ('FAIL',None)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print()
|
print()
|
||||||
@ -264,8 +258,7 @@ def parse_lastfm(inputf):
|
|||||||
try:
|
try:
|
||||||
artist,album,title,time = row
|
artist,album,title,time = row
|
||||||
except ValueError:
|
except ValueError:
|
||||||
err(f"{row} does not look like a valid entry. Scrobble not imported.")
|
yield ('FAIL',None,f"{row} does not look like a valid entry. Scrobble not imported.")
|
||||||
yield ('FAIL',None)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -278,8 +271,7 @@ def parse_lastfm(inputf):
|
|||||||
"%d %b %Y %H:%M%z"
|
"%d %b %Y %H:%M%z"
|
||||||
).timestamp()),
|
).timestamp()),
|
||||||
'duration':None
|
'duration':None
|
||||||
})
|
},'')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
err(f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
|
yield ('FAIL',None,f"{entry} could not be parsed. Scrobble not imported. ({repr(e)})")
|
||||||
yield ('FAIL',None)
|
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user