fix musly sort order and filter out dupes

This commit is contained in:
bassdart 2019-01-27 16:56:52 +01:00
parent 053d5b2ae5
commit c02b950902

View file

@ -668,17 +668,21 @@ def sortTitlesBy(limit, sort, start):
# xbmc.log(msg=str(start), level=xbmc.LOGNOTICE) # xbmc.log(msg=str(start), level=xbmc.LOGNOTICE)
for entry in data: for entry in data:
if entry['slug'] == start: if entry['slug'] == start:
slugs = []
# add slug for which the playlist should be shown # add slug for which the playlist should be shown
result.append(entry) slugs.extend(entry['slug'].split(", "))
slugs = "" # and add all related slugs
slugs = entry['related'] slugs.extend(entry['related'].split(", "))
# xbmc.log(msg=slugs, level=xbmc.LOGNOTICE) #xbmc.log(msg=str(slugs), level=xbmc.LOGNOTICE)
for entry in data: for entry in data:
# add all related slugs # add all related slugs
if entry['slug'] in slugs: if entry['slug'] in slugs:
# xbmc.log(msg=str(entry), level=xbmc.LOGNOTICE) #xbmc.log(msg=str(result['artists']), level=xbmc.LOGNOTICE)
# hm, doesn't work # filter out tracks with the same title, where only the video differs.
if entry['artist'] not in result: # if a related slug is listed earlier in data (= newer video) the
# main slug will be filtered out.
# In this case we add it again later, after sorting the result
if not filter(lambda result: result['title'] == entry['title'], result):
if videoselection != "2" and relatedselection != "true": if videoselection != "2" and relatedselection != "true":
if videoselection == "0": if videoselection == "0":
if "true" in entry['official']: if "true" in entry['official']:
@ -688,8 +692,20 @@ def sortTitlesBy(limit, sort, start):
result.append(entry) result.append(entry)
else: else:
result.append(entry) result.append(entry)
# slugs are sorted newest first because that's how they occur in the json
# so we have to sort the result to the order in related aka the musly order (with prepended main slug)
order_dict = {slug: index for index, slug in enumerate(slugs)}
result.sort(key=lambda x: order_dict[x["slug"]])
# check if the first entries slug is the main slug
# if not remove it and add back the main entry.
# I know, this is really ugly :-(
if result[0]['slug'] != start:
result.pop(0)
for entry in data:
if entry['slug'] == start:
result.insert(0, entry)
maximum = len(result) maximum = len(result)
# related is a list with max 21 entries, so we have to set start always to 0
start = 0 start = 0
# "more from..." artists # "more from..." artists