Get missing fanart on Kodi startup

This commit is contained in:
tomkat83 2017-02-01 19:56:06 +01:00
parent 6eb786416d
commit 1cc0f8a6c6
2 changed files with 50 additions and 4 deletions

View file

@ -347,6 +347,8 @@ class ProcessFanartThread(Thread):
cls.getfanart(xml[0], kodiId, item['mediaType'], allartworks) cls.getfanart(xml[0], kodiId, item['mediaType'], allartworks)
# signals to queue job is done # signals to queue job is done
log.debug('Done getting fanart for Plex id %s' % item['itemId']) log.debug('Done getting fanart for Plex id %s' % item['itemId'])
with plexdb.Get_Plex_DB() as plex_db:
plex_db.set_fanart_synched(item['itemId'])
queue.task_done() queue.task_done()
log.info("---===### Stopped FanartSync ###===---") log.info("---===### Stopped FanartSync ###===---")
@ -545,7 +547,8 @@ class LibrarySync(Thread):
kodi_fileid INTEGER, kodi_fileid INTEGER,
kodi_pathid INTEGER, kodi_pathid INTEGER,
parent_id INTEGER, parent_id INTEGER,
checksum INTEGER) checksum INTEGER,
fanart_synced INTEGER)
''') ''')
plex_db.plexcursor.execute(''' plex_db.plexcursor.execute('''
CREATE TABLE IF NOT EXISTS view( CREATE TABLE IF NOT EXISTS view(
@ -1833,6 +1836,20 @@ class LibrarySync(Thread):
for url in artwork.get_uncached_artwork(): for url in artwork.get_uncached_artwork():
artwork.ARTWORK_QUEUE.put( artwork.ARTWORK_QUEUE.put(
artwork.double_urlencode(tryEncode((url)))) artwork.double_urlencode(tryEncode((url))))
if settings('FanartTV') == 'true':
# Start getting additional missing artwork
with plexdb.Get_Plex_DB() as plex_db:
missing_fanart = plex_db.get_missing_fanart()
log.debug('Trying to get %s additional fanart'
% len(missing_fanart))
for item in missing_fanart:
self.fanartqueue.put({
'itemId': item['plex_id'],
'mediaType': item['kodi_type'],
'class': v.ITEMTYPE_FROM_KODITYPE[
item['kodi_type']],
'refresh': True
})
log.info('Refreshing video nodes and playlists now') log.info('Refreshing video nodes and playlists now')
deletePlaylists() deletePlaylists()
deleteNodes() deleteNodes()

View file

@ -4,6 +4,7 @@
from utils import kodiSQL from utils import kodiSQL
import logging import logging
import variables as v
############################################################################### ###############################################################################
@ -334,12 +335,12 @@ class Plex_DB_Functions():
query = ''' query = '''
INSERT OR REPLACE INTO plex( INSERT OR REPLACE INTO plex(
plex_id, kodi_id, kodi_fileid, kodi_pathid, plex_type, plex_id, kodi_id, kodi_fileid, kodi_pathid, plex_type,
kodi_type, parent_id, checksum, view_id) kodi_type, parent_id, checksum, view_id, fanart_synced)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''' '''
self.plexcursor.execute(query, (plex_id, kodi_id, kodi_fileid, self.plexcursor.execute(query, (plex_id, kodi_id, kodi_fileid,
kodi_pathid, plex_type, kodi_type, kodi_pathid, plex_type, kodi_type,
parent_id, checksum, view_id)) parent_id, checksum, view_id, 0))
def updateReference(self, plex_id, checksum): def updateReference(self, plex_id, checksum):
""" """
@ -416,3 +417,31 @@ class Plex_DB_Functions():
'plex_type': plex_type 'plex_type': plex_type
}) })
return result return result
def set_fanart_synched(self, plex_id):
"""
Sets the fanart_synced flag to 1 for plex_id
"""
query = '''UPDATE plex SET fanart_synced = 1 WHERE plex_id = ?'''
self.plexcursor.execute(query, (plex_id,))
def get_missing_fanart(self):
"""
Returns a list of {'plex_id': x, 'kodi_type': y} where fanart_synced
flag is set to 0
This only for plex_type is either movie or TV show
"""
query = '''
SELECT plex_id, kodi_type FROM plex
WHERE fanart_synced = ?
AND (plex_type = ? OR plex_type = ?)
'''
self.plexcursor.execute(query,
(0, v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_SHOW))
rows = self.plexcursor.fetchall()
result = []
for row in rows:
result.append({'plex_id': row[0],
'kodi_type': row[1]})
return result