Use section for sync process
This commit is contained in:
parent
6a292d29f6
commit
ab5ab966e4
5 changed files with 37 additions and 46 deletions
|
@ -14,8 +14,7 @@ class Movie(ItemBase):
|
||||||
"""
|
"""
|
||||||
Used for plex library-type movies
|
Used for plex library-type movies
|
||||||
"""
|
"""
|
||||||
def add_update(self, xml, section_name=None, section_id=None,
|
def add_update(self, xml, section, children=None):
|
||||||
children=None):
|
|
||||||
"""
|
"""
|
||||||
Process single movie
|
Process single movie
|
||||||
"""
|
"""
|
||||||
|
@ -174,7 +173,7 @@ class Movie(ItemBase):
|
||||||
|
|
||||||
self.kodidb.modify_streams(file_id, api.mediastreams(), runtime)
|
self.kodidb.modify_streams(file_id, api.mediastreams(), runtime)
|
||||||
self.kodidb.modify_studios(kodi_id, v.KODI_TYPE_MOVIE, studios)
|
self.kodidb.modify_studios(kodi_id, v.KODI_TYPE_MOVIE, studios)
|
||||||
tags = [section_name]
|
tags = [section.name]
|
||||||
if collections:
|
if collections:
|
||||||
for plex_set_id, set_name in collections:
|
for plex_set_id, set_name in collections:
|
||||||
set_api = None
|
set_api = None
|
||||||
|
@ -189,7 +188,7 @@ class Movie(ItemBase):
|
||||||
# e.g. when added via websocket
|
# e.g. when added via websocket
|
||||||
LOG.debug('Costly looking up Plex collection %s: %s',
|
LOG.debug('Costly looking up Plex collection %s: %s',
|
||||||
plex_set_id, set_name)
|
plex_set_id, set_name)
|
||||||
for index, coll_plex_id in api.collections_match(section_id):
|
for index, coll_plex_id in api.collections_match(section.id):
|
||||||
# Get Plex artwork for collections - a pain
|
# Get Plex artwork for collections - a pain
|
||||||
if index == plex_set_id:
|
if index == plex_set_id:
|
||||||
set_xml = PF.GetPlexMetadata(coll_plex_id)
|
set_xml = PF.GetPlexMetadata(coll_plex_id)
|
||||||
|
@ -217,7 +216,7 @@ class Movie(ItemBase):
|
||||||
dateplayed)
|
dateplayed)
|
||||||
self.plexdb.add_movie(plex_id=plex_id,
|
self.plexdb.add_movie(plex_id=plex_id,
|
||||||
checksum=api.checksum(),
|
checksum=api.checksum(),
|
||||||
section_id=section_id,
|
section_id=section.id,
|
||||||
kodi_id=kodi_id,
|
kodi_id=kodi_id,
|
||||||
kodi_fileid=file_id,
|
kodi_fileid=file_id,
|
||||||
kodi_pathid=kodi_pathid,
|
kodi_pathid=kodi_pathid,
|
||||||
|
|
|
@ -154,8 +154,7 @@ class Artist(MusicMixin, ItemBase):
|
||||||
"""
|
"""
|
||||||
For Plex library-type artists
|
For Plex library-type artists
|
||||||
"""
|
"""
|
||||||
def add_update(self, xml, section_name=None, section_id=None,
|
def add_update(self, xml, section, children=None):
|
||||||
children=None):
|
|
||||||
"""
|
"""
|
||||||
Process a single artist
|
Process a single artist
|
||||||
"""
|
"""
|
||||||
|
@ -210,14 +209,13 @@ class Artist(MusicMixin, ItemBase):
|
||||||
v.KODI_TYPE_ARTIST)
|
v.KODI_TYPE_ARTIST)
|
||||||
self.plexdb.add_artist(plex_id,
|
self.plexdb.add_artist(plex_id,
|
||||||
api.checksum(),
|
api.checksum(),
|
||||||
section_id,
|
section.id,
|
||||||
kodi_id,
|
kodi_id,
|
||||||
self.last_sync)
|
self.last_sync)
|
||||||
|
|
||||||
|
|
||||||
class Album(MusicMixin, ItemBase):
|
class Album(MusicMixin, ItemBase):
|
||||||
def add_update(self, xml, section_name=None, section_id=None,
|
def add_update(self, xml, section, children=None, scan_children=True):
|
||||||
children=None, scan_children=True):
|
|
||||||
"""
|
"""
|
||||||
Process a single album
|
Process a single album
|
||||||
scan_children: set to False if you don't want to add children, e.g. to
|
scan_children: set to False if you don't want to add children, e.g. to
|
||||||
|
@ -250,8 +248,7 @@ class Album(MusicMixin, ItemBase):
|
||||||
Artist(self.last_sync,
|
Artist(self.last_sync,
|
||||||
plexdb=self.plexdb,
|
plexdb=self.plexdb,
|
||||||
kodidb=self.kodidb).add_update(artist_xml[0],
|
kodidb=self.kodidb).add_update(artist_xml[0],
|
||||||
section_name,
|
section=section)
|
||||||
section_id)
|
|
||||||
artist = self.plexdb.artist(parent_id)
|
artist = self.plexdb.artist(parent_id)
|
||||||
if not artist:
|
if not artist:
|
||||||
LOG.error('Adding artist %s failed for %s',
|
LOG.error('Adding artist %s failed for %s',
|
||||||
|
@ -363,7 +360,7 @@ class Album(MusicMixin, ItemBase):
|
||||||
v.KODI_TYPE_ALBUM)
|
v.KODI_TYPE_ALBUM)
|
||||||
self.plexdb.add_album(plex_id,
|
self.plexdb.add_album(plex_id,
|
||||||
api.checksum(),
|
api.checksum(),
|
||||||
section_id,
|
section.id,
|
||||||
artist_id,
|
artist_id,
|
||||||
parent_id,
|
parent_id,
|
||||||
kodi_id,
|
kodi_id,
|
||||||
|
@ -375,8 +372,7 @@ class Album(MusicMixin, ItemBase):
|
||||||
kodidb=self.kodidb)
|
kodidb=self.kodidb)
|
||||||
for song in children:
|
for song in children:
|
||||||
context.add_update(song,
|
context.add_update(song,
|
||||||
section_name=section_name,
|
section=section,
|
||||||
section_id=section_id,
|
|
||||||
album_xml=xml,
|
album_xml=xml,
|
||||||
genres=genres,
|
genres=genres,
|
||||||
genre=genre,
|
genre=genre,
|
||||||
|
@ -384,9 +380,8 @@ class Album(MusicMixin, ItemBase):
|
||||||
|
|
||||||
|
|
||||||
class Song(MusicMixin, ItemBase):
|
class Song(MusicMixin, ItemBase):
|
||||||
def add_update(self, xml, section_name=None, section_id=None,
|
def add_update(self, xml, section, children=None, album_xml=None,
|
||||||
children=None, album_xml=None, genres=None, genre=None,
|
genres=None, genre=None, compilation=None):
|
||||||
compilation=None):
|
|
||||||
"""
|
"""
|
||||||
Process single song/track
|
Process single song/track
|
||||||
"""
|
"""
|
||||||
|
@ -421,8 +416,7 @@ class Song(MusicMixin, ItemBase):
|
||||||
Artist(self.last_sync,
|
Artist(self.last_sync,
|
||||||
plexdb=self.plexdb,
|
plexdb=self.plexdb,
|
||||||
kodidb=self.kodidb).add_update(artist_xml[0],
|
kodidb=self.kodidb).add_update(artist_xml[0],
|
||||||
section_name,
|
section=section)
|
||||||
section_id)
|
|
||||||
artist = self.plexdb.artist(artist_id)
|
artist = self.plexdb.artist(artist_id)
|
||||||
if not artist:
|
if not artist:
|
||||||
LOG.error('Still could not find grandparent artist %s for %s',
|
LOG.error('Still could not find grandparent artist %s for %s',
|
||||||
|
@ -477,8 +471,7 @@ class Song(MusicMixin, ItemBase):
|
||||||
Album(self.last_sync,
|
Album(self.last_sync,
|
||||||
plexdb=self.plexdb,
|
plexdb=self.plexdb,
|
||||||
kodidb=self.kodidb).add_update(album_xml[0],
|
kodidb=self.kodidb).add_update(album_xml[0],
|
||||||
section_name,
|
section=section,
|
||||||
section_id,
|
|
||||||
children=[xml],
|
children=[xml],
|
||||||
scan_children=False)
|
scan_children=False)
|
||||||
album = self.plexdb.album(album_id)
|
album = self.plexdb.album(album_id)
|
||||||
|
@ -659,7 +652,7 @@ class Song(MusicMixin, ItemBase):
|
||||||
v.KODI_TYPE_ALBUM)
|
v.KODI_TYPE_ALBUM)
|
||||||
self.plexdb.add_song(plex_id,
|
self.plexdb.add_song(plex_id,
|
||||||
api.checksum(),
|
api.checksum(),
|
||||||
section_id,
|
section.id,
|
||||||
artist_id,
|
artist_id,
|
||||||
grandparent_id,
|
grandparent_id,
|
||||||
album_id,
|
album_id,
|
||||||
|
|
|
@ -143,8 +143,7 @@ class Show(TvShowMixin, ItemBase):
|
||||||
"""
|
"""
|
||||||
For Plex library-type TV shows
|
For Plex library-type TV shows
|
||||||
"""
|
"""
|
||||||
def add_update(self, xml, section_name=None, section_id=None,
|
def add_update(self, xml, section, children=None):
|
||||||
children=None):
|
|
||||||
"""
|
"""
|
||||||
Process a single show
|
Process a single show
|
||||||
"""
|
"""
|
||||||
|
@ -274,20 +273,19 @@ class Show(TvShowMixin, ItemBase):
|
||||||
# Process studios
|
# Process studios
|
||||||
self.kodidb.modify_studios(kodi_id, v.KODI_TYPE_SHOW, studios)
|
self.kodidb.modify_studios(kodi_id, v.KODI_TYPE_SHOW, studios)
|
||||||
# Process tags: view, PMS collection tags
|
# Process tags: view, PMS collection tags
|
||||||
tags = [section_name]
|
tags = [section.name]
|
||||||
tags.extend([i for _, i in api.collection_list()])
|
tags.extend([i for _, i in api.collection_list()])
|
||||||
self.kodidb.modify_tags(kodi_id, v.KODI_TYPE_SHOW, tags)
|
self.kodidb.modify_tags(kodi_id, v.KODI_TYPE_SHOW, tags)
|
||||||
self.plexdb.add_show(plex_id=plex_id,
|
self.plexdb.add_show(plex_id=plex_id,
|
||||||
checksum=api.checksum(),
|
checksum=api.checksum(),
|
||||||
section_id=section_id,
|
section_id=section.id,
|
||||||
kodi_id=kodi_id,
|
kodi_id=kodi_id,
|
||||||
kodi_pathid=kodi_pathid,
|
kodi_pathid=kodi_pathid,
|
||||||
last_sync=self.last_sync)
|
last_sync=self.last_sync)
|
||||||
|
|
||||||
|
|
||||||
class Season(TvShowMixin, ItemBase):
|
class Season(TvShowMixin, ItemBase):
|
||||||
def add_update(self, xml, section_name=None, section_id=None,
|
def add_update(self, xml, section, children=None):
|
||||||
children=None):
|
|
||||||
"""
|
"""
|
||||||
Process a single season of a certain tv show
|
Process a single season of a certain tv show
|
||||||
"""
|
"""
|
||||||
|
@ -315,8 +313,7 @@ class Season(TvShowMixin, ItemBase):
|
||||||
Show(self.last_sync,
|
Show(self.last_sync,
|
||||||
plexdb=self.plexdb,
|
plexdb=self.plexdb,
|
||||||
kodidb=self.kodidb).add_update(show_xml[0],
|
kodidb=self.kodidb).add_update(show_xml[0],
|
||||||
section_name,
|
section=section)
|
||||||
section_id)
|
|
||||||
show = self.plexdb.show(show_id)
|
show = self.plexdb.show(show_id)
|
||||||
if not show:
|
if not show:
|
||||||
LOG.error('Still could not find parent tv show %s', show_id)
|
LOG.error('Still could not find parent tv show %s', show_id)
|
||||||
|
@ -346,7 +343,7 @@ class Season(TvShowMixin, ItemBase):
|
||||||
v.KODI_TYPE_SEASON)
|
v.KODI_TYPE_SEASON)
|
||||||
self.plexdb.add_season(plex_id=plex_id,
|
self.plexdb.add_season(plex_id=plex_id,
|
||||||
checksum=api.checksum(),
|
checksum=api.checksum(),
|
||||||
section_id=section_id,
|
section_id=section.id,
|
||||||
show_id=show_id,
|
show_id=show_id,
|
||||||
parent_id=parent_id,
|
parent_id=parent_id,
|
||||||
kodi_id=kodi_id,
|
kodi_id=kodi_id,
|
||||||
|
@ -354,8 +351,7 @@ class Season(TvShowMixin, ItemBase):
|
||||||
|
|
||||||
|
|
||||||
class Episode(TvShowMixin, ItemBase):
|
class Episode(TvShowMixin, ItemBase):
|
||||||
def add_update(self, xml, section_name=None, section_id=None,
|
def add_update(self, xml, section, children=None):
|
||||||
children=None):
|
|
||||||
"""
|
"""
|
||||||
Process single episode
|
Process single episode
|
||||||
"""
|
"""
|
||||||
|
@ -402,8 +398,7 @@ class Episode(TvShowMixin, ItemBase):
|
||||||
Show(self.last_sync,
|
Show(self.last_sync,
|
||||||
plexdb=self.plexdb,
|
plexdb=self.plexdb,
|
||||||
kodidb=self.kodidb).add_update(show_xml[0],
|
kodidb=self.kodidb).add_update(show_xml[0],
|
||||||
section_name,
|
section=section)
|
||||||
section_id)
|
|
||||||
show = self.plexdb.show(show_id)
|
show = self.plexdb.show(show_id)
|
||||||
if not show:
|
if not show:
|
||||||
LOG.error('Still could not find grandparent tv show %s', show_id)
|
LOG.error('Still could not find grandparent tv show %s', show_id)
|
||||||
|
@ -423,8 +418,7 @@ class Episode(TvShowMixin, ItemBase):
|
||||||
Season(self.last_sync,
|
Season(self.last_sync,
|
||||||
plexdb=self.plexdb,
|
plexdb=self.plexdb,
|
||||||
kodidb=self.kodidb).add_update(season_xml[0],
|
kodidb=self.kodidb).add_update(season_xml[0],
|
||||||
section_name,
|
section=section)
|
||||||
section_id)
|
|
||||||
season = self.plexdb.season(season_id)
|
season = self.plexdb.season(season_id)
|
||||||
if not season:
|
if not season:
|
||||||
LOG.error('Still could not find parent season %s', season_id)
|
LOG.error('Still could not find parent season %s', season_id)
|
||||||
|
@ -543,7 +537,7 @@ class Episode(TvShowMixin, ItemBase):
|
||||||
userdata['LastPlayedDate'])
|
userdata['LastPlayedDate'])
|
||||||
self.plexdb.add_episode(plex_id=plex_id,
|
self.plexdb.add_episode(plex_id=plex_id,
|
||||||
checksum=api.checksum(),
|
checksum=api.checksum(),
|
||||||
section_id=section_id,
|
section_id=section.id,
|
||||||
show_id=show_id,
|
show_id=show_id,
|
||||||
grandparent_id=grandparent_id,
|
grandparent_id=grandparent_id,
|
||||||
season_id=season_id,
|
season_id=season_id,
|
||||||
|
@ -619,7 +613,7 @@ class Episode(TvShowMixin, ItemBase):
|
||||||
userdata['LastPlayedDate'])
|
userdata['LastPlayedDate'])
|
||||||
self.plexdb.add_episode(plex_id=plex_id,
|
self.plexdb.add_episode(plex_id=plex_id,
|
||||||
checksum=api.checksum(),
|
checksum=api.checksum(),
|
||||||
section_id=section_id,
|
section_id=section.id,
|
||||||
show_id=show_id,
|
show_id=show_id,
|
||||||
grandparent_id=grandparent_id,
|
grandparent_id=grandparent_id,
|
||||||
season_id=season_id,
|
season_id=season_id,
|
||||||
|
|
|
@ -140,8 +140,7 @@ class FullSync(common.fullsync_mixin):
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
if isinstance(item, dict):
|
if isinstance(item, dict):
|
||||||
context.add_update(item['xml'][0],
|
context.add_update(item['xml'][0],
|
||||||
section_name=section.name,
|
section=section,
|
||||||
section_id=section.id,
|
|
||||||
children=item['children'])
|
children=item['children'])
|
||||||
self.title = item['xml'][0].get('title')
|
self.title = item['xml'][0].get('title')
|
||||||
self.processed += 1
|
self.processed += 1
|
||||||
|
@ -233,8 +232,7 @@ class FullSync(common.fullsync_mixin):
|
||||||
if not itemtype.update_userdata(xml_item, section.plex_type):
|
if not itemtype.update_userdata(xml_item, section.plex_type):
|
||||||
# Somehow did not sync this item yet
|
# Somehow did not sync this item yet
|
||||||
itemtype.add_update(xml_item,
|
itemtype.add_update(xml_item,
|
||||||
section_name=section.name,
|
section=section)
|
||||||
section_id=section.section_id)
|
|
||||||
itemtype.plexdb.update_last_sync(int(xml_item.attrib['ratingKey']),
|
itemtype.plexdb.update_last_sync(int(xml_item.attrib['ratingKey']),
|
||||||
section.plex_type,
|
section.plex_type,
|
||||||
self.current_sync)
|
self.current_sync)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
|
from . import sections
|
||||||
from .common import update_kodi_library, PLAYLIST_SYNC_ENABLED
|
from .common import update_kodi_library, PLAYLIST_SYNC_ENABLED
|
||||||
from .fanart import SYNC_FANART, FanartTask
|
from .fanart import SYNC_FANART, FanartTask
|
||||||
from ..plex_api import API
|
from ..plex_api import API
|
||||||
|
@ -122,10 +123,16 @@ def process_new_item_message(message):
|
||||||
LOG.error('Could not download metadata for %s', message['plex_id'])
|
LOG.error('Could not download metadata for %s', message['plex_id'])
|
||||||
return False, False, False
|
return False, False, False
|
||||||
LOG.debug("Processing new/updated PMS item: %s", message['plex_id'])
|
LOG.debug("Processing new/updated PMS item: %s", message['plex_id'])
|
||||||
|
section_id = utils.cast(int, xml.get('librarySectionID'))
|
||||||
|
for section in sections.SECTIONS:
|
||||||
|
if section.id == section_id:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
LOG.error('Section id %s not yet encountered', section_id)
|
||||||
|
return False, False, False
|
||||||
with itemtypes.ITEMTYPE_FROM_PLEXTYPE[plex_type](timing.unix_timestamp()) as typus:
|
with itemtypes.ITEMTYPE_FROM_PLEXTYPE[plex_type](timing.unix_timestamp()) as typus:
|
||||||
typus.add_update(xml[0],
|
typus.add_update(xml[0],
|
||||||
section_name=xml.get('librarySectionTitle'),
|
section=section)
|
||||||
section_id=xml.get('librarySectionID'))
|
|
||||||
cache_artwork(message['plex_id'], plex_type)
|
cache_artwork(message['plex_id'], plex_type)
|
||||||
return True, plex_type in v.PLEX_VIDEOTYPES, plex_type in v.PLEX_AUDIOTYPES
|
return True, plex_type in v.PLEX_VIDEOTYPES, plex_type in v.PLEX_AUDIOTYPES
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue