mirror of
https://github.com/gordielachance/plugin.audio.subsonic
synced 2024-12-28 01:01:37 +01:00
Refresh info by alpha index to avoid blocking
This commit is contained in:
parent
607bb52158
commit
f587d3d4d6
@ -1,5 +1,6 @@
|
||||
import sqlite3 as sql
|
||||
import time
|
||||
import xbmc
|
||||
|
||||
tbl_artist_info_ddl = str('CREATE TABLE artist_info ('
|
||||
'artist_id TEXT NOT NULL PRIMARY KEY,'
|
||||
@ -23,24 +24,24 @@ class SQLiteDatabase(object):
|
||||
|
||||
def connect(self):
|
||||
try:
|
||||
#xbmc.log("Trying connection to the database %s"%self.db_filename, xbmc.LOGINFO)
|
||||
print("Trying connection to the database %s"%self.db_filename)
|
||||
xbmc.log("Trying connection to the database %s"%self.db_filename, xbmc.LOGINFO)
|
||||
#print("Trying connection to the database %s"%self.db_filename)
|
||||
self.conn = sql.connect(self.db_filename)
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute(str('SELECT SQLITE_VERSION()'))
|
||||
#xbmc.log("Connection %s was successful %s"%(self.db_filename, cursor.fetchone()[0]), xbmc.LOGINFO)
|
||||
print("Connection %s was successful %s"%(self.db_filename, cursor.fetchone()[0]))
|
||||
xbmc.log("Connection %s was successful %s"%(self.db_filename, cursor.fetchone()[0]), xbmc.LOGINFO)
|
||||
#print("Connection %s was successful %s"%(self.db_filename, cursor.fetchone()[0]))
|
||||
cursor.row_factory = lambda cursor, row: row[0]
|
||||
cursor.execute(str('SELECT name FROM sqlite_master WHERE type=\'table\' ''AND name NOT LIKE \'sqlite_%\''))
|
||||
list_tables = cursor.fetchall()
|
||||
if not list_tables:
|
||||
# If no tables exist create a new one
|
||||
#xbmc.log("Creating Subsonic local DB", xbmc.LOGINFO)
|
||||
print("Creating Subsonic local DB")
|
||||
xbmc.log("Creating Subsonic local DB", xbmc.LOGINFO)
|
||||
#print("Creating Subsonic local DB")
|
||||
cursor.execute(tbl_artist_info_ddl)
|
||||
except sql.Error as e:
|
||||
#xbmc.log("SQLite error %s"%e.args[0], xbmc.LOGINFO)
|
||||
print("SQLite error %s"%e.args[0])
|
||||
xbmc.log("SQLite error %s"%e.args[0], xbmc.LOGINFO)
|
||||
#print("SQLite error %s"%e.args[0])
|
||||
|
||||
def get_cursor(self):
|
||||
return self.conn.cursor()
|
||||
|
@ -2816,7 +2816,7 @@ class Connection(object):
|
||||
req = urllib.request.Request(url, urlencode(qdict).encode('utf-8'))
|
||||
if(self._useGET or ('getCoverArt' in viewName) or ('stream' in viewName)):
|
||||
url += '?%s' % urlencode(qdict)
|
||||
#xbmc.log("UseGET URL %s"%(url), xbmc.LOGDEBUG)
|
||||
xbmc.log("UseGET URL %s"%(url), xbmc.LOGDEBUG)
|
||||
#print(url)
|
||||
req = urllib.request.Request(url)
|
||||
return req
|
||||
|
20
main.py
20
main.py
@ -63,6 +63,7 @@ def get_connection():
|
||||
insecure=Addon().get_setting('insecure'),
|
||||
legacyAuth=Addon().get_setting('legacyauth'),
|
||||
useGET=Addon().get_setting('useget'),
|
||||
appName="Kodi-Subsonic",
|
||||
)
|
||||
connected = connection.ping()
|
||||
except Exception as e:
|
||||
@ -764,13 +765,16 @@ def get_image(item):
|
||||
if Addon().get_setting('enhanced_info'):
|
||||
image = db.get_value(item.get('id'), 'wikipedia_image')[0][0]
|
||||
#print("Checking image type %s %s %s"%(item.get('id'), image, type(image)))
|
||||
if (image is None) or (image =='') or (image =='None'):
|
||||
connection = get_connection()
|
||||
#print("Using coverart tag from item %s is it same as %s ?"%(item.get('coverArt'),item.get('id')))
|
||||
image = connection.getCoverArtUrl(item.get('coverArt'))
|
||||
return image
|
||||
except:
|
||||
except IndexError:
|
||||
print("Wiki image not available for artist %s" % item.get('name'))
|
||||
except Exception as e:
|
||||
print("Error getting image for %s %s"%(item.get('name'),e))
|
||||
return image
|
||||
if (image is None) or (image =='') or (image =='None'):
|
||||
connection = get_connection()
|
||||
#print("Using coverart tag from item %s is it same as %s ?"%(item.get('coverArt'),item.get('id')))
|
||||
image = connection.getCoverArtUrl(item.get('coverArt'))
|
||||
return image
|
||||
|
||||
def get_artist_info(artist_id, forced=False):
|
||||
db = get_db()
|
||||
@ -789,8 +793,10 @@ def get_artist_info(artist_id, forced=False):
|
||||
if(artist_info is None):
|
||||
print("artist_info is None making empty string")
|
||||
artist_info = ""
|
||||
except IndexError:
|
||||
print("Enhanced info not available for artist %s" % artist_id)
|
||||
except Exception as e:
|
||||
print("Error get info from DB %s"%e)
|
||||
print("Error getting artist info from DB %s"%e)
|
||||
return artist_info
|
||||
|
||||
def get_entry_artist(item,params):
|
||||
|
46
service.py
46
service.py
@ -19,12 +19,13 @@ mb = None
|
||||
|
||||
serviceEnabled = True
|
||||
|
||||
refresh_age = 86400 #multiple of random to age info records - needs some validation
|
||||
check_freq = 300#3600 #How often to run a refresh cycle - needs some validation
|
||||
refresh_age = 3600 #multiple of random to age info records - needs some validation
|
||||
check_freq = 30 #How often to run a refresh cycle - needs some validation
|
||||
|
||||
db_filename = "subsonic_sqlite.db"
|
||||
|
||||
last_db_check = 0
|
||||
current_artist_index = 0
|
||||
|
||||
from simpleplugin import Plugin
|
||||
from simpleplugin import Addon
|
||||
@ -73,6 +74,7 @@ def get_connection():
|
||||
insecure=Addon().get_setting('insecure'),
|
||||
legacyAuth=Addon().get_setting('legacyauth'),
|
||||
useGET=Addon().get_setting('useget'),
|
||||
appName="Kodi-Subsonic",
|
||||
)
|
||||
connected = connection.ping()
|
||||
except:
|
||||
@ -104,6 +106,7 @@ def refresh_artist(artist_id):
|
||||
connection = get_connection()
|
||||
artist = connection.getArtist(artist_id)#['subsonic-response']
|
||||
artist_name = artist['artist']['name']
|
||||
db.update_value(artist_id, 'artist_name', artist_name)
|
||||
artist_info = connection.getArtistInfo2(artist_id)
|
||||
try:
|
||||
artist_info = artist_info['artistInfo2']['biography']
|
||||
@ -112,14 +115,13 @@ def refresh_artist(artist_id):
|
||||
plugin.log("subbed: %s"%artist_info)
|
||||
except:
|
||||
artist_info = ""
|
||||
if enhancedInfo:
|
||||
mb = get_mb()
|
||||
if(enhancedInfo):
|
||||
mb = get_mb()
|
||||
mb_artist_id = mb.get_artist_id(artist_name)
|
||||
artist_image_url = mb.get_artist_image(mb_artist_id)
|
||||
wikipedia_url = mb.get_artist_wikpedia(mb_artist_id)
|
||||
artist_wiki_extract = mb.get_wiki_extract(wikipedia_url)
|
||||
wikipedia_image = mb.get_wiki_image(wikipedia_url)
|
||||
db.update_value(artist_id, 'artist_name', artist_name)
|
||||
db.update_value(artist_id, 'artist_info', artist_info)
|
||||
db.update_value(artist_id, 'mb_artist_id', mb_artist_id)
|
||||
db.update_value(artist_id, 'image_url', artist_image_url)
|
||||
@ -127,32 +129,37 @@ def refresh_artist(artist_id):
|
||||
db.update_value(artist_id, 'wikipedia_extract', artist_wiki_extract)
|
||||
db.update_value(artist_id, 'wikipedia_image', wikipedia_image)
|
||||
|
||||
def check_db_status(forced=False):
|
||||
def check_db_status():
|
||||
global last_db_check
|
||||
refresh_single_flag = False
|
||||
global current_artist_index
|
||||
try:
|
||||
if(time.time()-check_freq > last_db_check) or forced:
|
||||
#popup("DB Check Starting")
|
||||
if(time.time()-check_freq > last_db_check): #Won't check on every run uses check_freq
|
||||
plugin.log("DB check starting %s %s" % (time.time(), last_db_check))
|
||||
db = get_db()
|
||||
connection = get_connection()
|
||||
response = connection.getArtists()
|
||||
for index in response["artists"]["index"]:
|
||||
for artist in index["artist"]:
|
||||
artist_id = artist['id']
|
||||
record_age = db.get_record_age(artist_id)
|
||||
if(forced or not record_age or (record_age > (random.randint(1,111)*refresh_age))) and not refresh_single_flag:
|
||||
#plugin.log("Record age %s vs %s for %s"%(record_age, (random.randint(1,111)*refresh_age), artist_id))
|
||||
#popup("Refreshing %s" % artist_id)
|
||||
refresh_artist(artist_id)
|
||||
if(record_age>0):refresh_single_flag = True
|
||||
current_index_content = response["artists"]["index"][current_artist_index] #Completes refresh for alpha index
|
||||
plugin.log("Starting info load for index %s"%current_index_content['name'])
|
||||
for artist in current_index_content["artist"]:
|
||||
artist_id = artist['id']
|
||||
record_age = db.get_record_age(artist_id)
|
||||
plugin.log("Record age %s vs %s for %s"%(record_age, (random.randint(1,111)*refresh_age), artist_id))
|
||||
if(not record_age or (record_age > (random.randint(1,111)*refresh_age))):
|
||||
plugin.log("Record age %s vs %s for %s"%(record_age, (random.randint(1,111)*refresh_age), artist_id))
|
||||
plugin.log("Refreshing %s" % (artist_id))
|
||||
refresh_artist(artist_id)
|
||||
plugin.log("Refresh complete for %s" % (artist_id))
|
||||
plugin.log("Finished info loading for index %s"%current_index_content['name'])
|
||||
current_artist_index+=1
|
||||
if(current_artist_index>=len(response["artists"]["index"])):current_artist_index=0
|
||||
last_db_check = time.time()
|
||||
except Exception as e:
|
||||
plugin.log("DB status check failed %s"%e)
|
||||
plugin.log("Refresh check failed %s"%e)
|
||||
|
||||
return
|
||||
|
||||
def check_player_status():
|
||||
global scrobbled
|
||||
if (scrobbleEnabled and xbmc.getCondVisibility("Player.HasMedia")):
|
||||
try:
|
||||
currentFileName = xbmc.getInfoLabel("Player.Filenameandpath")
|
||||
@ -187,6 +194,7 @@ def scrobble_track(track_id):
|
||||
return True
|
||||
else:
|
||||
popup("Scrobble failed")
|
||||
xbmc.log("Scrobble failed", xbmc.LOGERROR)
|
||||
return False
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user