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)
for entry in data:
if entry['slug'] == start:
slugs = []
# add slug for which the playlist should be shown
result.append(entry)
slugs = ""
slugs = entry['related']
# xbmc.log(msg=slugs, level=xbmc.LOGNOTICE)
slugs.extend(entry['slug'].split(", "))
# and add all related slugs
slugs.extend(entry['related'].split(", "))
#xbmc.log(msg=str(slugs), level=xbmc.LOGNOTICE)
for entry in data:
# add all related slugs
if entry['slug'] in slugs:
# xbmc.log(msg=str(entry), level=xbmc.LOGNOTICE)
# hm, doesn't work
if entry['artist'] not in result:
#xbmc.log(msg=str(result['artists']), level=xbmc.LOGNOTICE)
# filter out tracks with the same title, where only the video differs.
# 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 == "0":
if "true" in entry['official']:
@ -688,8 +692,20 @@ def sortTitlesBy(limit, sort, start):
result.append(entry)
else:
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)
# related is a list with max 21 entries, so we have to set start always to 0
start = 0
# "more from..." artists