Added artist info - some errors remaining

This commit is contained in:
warwickh 2021-09-04 16:00:49 +10:00
parent 34a7c249be
commit 56dffe70bc
2 changed files with 39 additions and 5 deletions

View File

@ -2485,6 +2485,8 @@ class Connection(object):
req = self._getRequest(viewName, q) req = self._getRequest(viewName, q)
res = self._doInfoReq(req) res = self._doInfoReq(req)
print(req.get_full_url())
print(res)
self._checkStatus(res) self._checkStatus(res)
return res return res

42
main.py
View File

@ -10,6 +10,8 @@ import json
import shutil import shutil
import time import time
import dateutil.parser import dateutil.parser
import hashlib
import random
from datetime import datetime from datetime import datetime
from collections.abc import MutableMapping from collections.abc import MutableMapping
from collections import namedtuple from collections import namedtuple
@ -755,12 +757,42 @@ def get_entry_playlist(item,params):
}} }}
} }
def get_artist_info(artist_id, forced=False):
print("Getting artist info for id: %s"%(artist_id))
popup("Getting artist info\nplease wait")
last_update = 0
artist_info = {}
cache_file = '%s'%hashlib.md5(artist_id.encode('utf-8')).hexdigest()
with plugin.get_storage(cache_file) as storage:
try:
last_update = storage['updated']
except KeyError as e:
plugin.log("Artist keyerror, is this a new cache file? %s"%cache_file)
if(time.time()-last_update>(random.randint(1,11)*360) or forced):
plugin.log("Artist cache expired, updating %s %s %s forced %s"%(time.time(),(random.randint(1,11)*360),last_update, forced))
try:
artist_info = connection.getArtistInfo2(artist_id).get('artistInfo2')
#.get('artistInfo')
storage['artist_info'] = artist_info
storage['updated']=time.time()
except AttributeError as e:
plugin.log("Attribute error, probably couldn't find any info")
else:
print("Cache ok for %s retrieving"%artist_id)
artist_info = storage['artist_info']
print(artist_info)
return artist_info
#artist_info = connection.getArtistInfo(item.get('id')).get('artistInfo')
#artist_bio = artist_info.get('biography')
#xbmc.log("Artist info: %s"%artist_info.get('biography'),xbmc.LOGINFO)
#star (or unstar) an item #star (or unstar) an item
#@plugin.cached(cachetime) #cache (in minutes) #@plugin.cached(cachetime) #cache (in minutes)
def get_entry_artist(item,params): def get_entry_artist(item,params):
image = connection.getCoverArtUrl(item.get('coverArt')) image = connection.getCoverArtUrl(item.get('coverArt'))
#artist_info = connection.getArtistInfo(item.get('id')).get('artistInfo') artist_info = get_artist_info(item.get('id'))
#artist_bio = artist_info.get('biography') artist_bio = artist_info.get('biography')
#xbmc.log("Artist info: %s"%artist_info.get('biography'),xbmc.LOGINFO) #xbmc.log("Artist info: %s"%artist_info.get('biography'),xbmc.LOGINFO)
return { return {
'label': get_starred_label(item.get('id'),item.get('name')), 'label': get_starred_label(item.get('id'),item.get('name')),
@ -776,11 +808,11 @@ def get_entry_artist(item,params):
'info': { 'info': {
'music': { ##http://romanvm.github.io/Kodistubs/_autosummary/xbmcgui.html#xbmcgui.ListItem.setInfo 'music': { ##http://romanvm.github.io/Kodistubs/_autosummary/xbmcgui.html#xbmcgui.ListItem.setInfo
'count': item.get('albumCount'), 'count': item.get('albumCount'),
'artist': item.get('name')#, 'artist': item.get('name'),
#'title': "testtitle", #'title': "testtitle",
#'album': "testalbum", #'album': "testalbum",
#'comment': "testcomment" #'comment': "testcomment"
# 'title': artist_info.get('biography') 'title': artist_info
} }
} }
} }
@ -1401,7 +1433,7 @@ def walk_directory(directory_id):
yield child yield child
else: else:
yield child yield child
except: except KeyError:
yield from () yield from ()
def walk_artist(artist_id): def walk_artist(artist_id):