Rename section.section_id to section.id

This commit is contained in:
croneter 2019-04-27 11:44:48 +02:00
parent e76fd03915
commit ab8089d3b1
2 changed files with 36 additions and 47 deletions

View file

@ -25,18 +25,16 @@ UPDATED_AT_SAFETY = 60 * 5
LAST_VIEWED_AT_SAFETY = 60 * 5 LAST_VIEWED_AT_SAFETY = 60 * 5
class InitNewSection(object): class InitNewSection(sections.Section):
""" """
Throw this into the queue used for ProcessMetadata to tell it which Throw this into the queue used for ProcessMetadata to tell it which
Plex library section we're looking at Plex library section we're looking at
""" """
def __init__(self, context, total_number_of_items, section_name, def __init__(self, total_number_of_items, section):
section_id, plex_type): super(InitNewSection, self).__init__()
self.context = context # Copy all section attributes to this instance
self.__dict__.update(section.__dict__)
self.total = total_number_of_items self.total = total_number_of_items
self.name = section_name
self.id = section_id
self.plex_type = plex_type
class FullSync(common.fullsync_mixin): class FullSync(common.fullsync_mixin):
@ -167,12 +165,7 @@ class FullSync(common.fullsync_mixin):
# Sync new, updated and deleted items # Sync new, updated and deleted items
iterator = section.iterator iterator = section.iterator
# Tell the processing thread about this new section # Tell the processing thread about this new section
queue_info = InitNewSection(section.context, queue_info = InitNewSection(iterator.total, section)
iterator.total,
iterator.get('librarySectionTitle',
iterator.get('title1')),
section.section_id,
section.plex_type)
self.queue.put(queue_info) self.queue.put(queue_info)
last = True last = True
# To keep track of the item-number in order to kill while loops # To keep track of the item-number in order to kill while loops
@ -210,11 +203,7 @@ class FullSync(common.fullsync_mixin):
# Sync new, updated and deleted items # Sync new, updated and deleted items
iterator = section.iterator iterator = section.iterator
# Tell the processing thread about this new section # Tell the processing thread about this new section
queue_info = InitNewSection(section.context, queue_info = InitNewSection(iterator.total, section)
iterator.total,
section.name,
section.section_id,
section.plex_type)
self.queue.put(queue_info) self.queue.put(queue_info)
self.total = iterator.total self.total = iterator.total
self.section_name = section.name self.section_name = section.name
@ -272,7 +261,7 @@ class FullSync(common.fullsync_mixin):
updated_at = section.last_sync - UPDATED_AT_SAFETY \ updated_at = section.last_sync - UPDATED_AT_SAFETY \
if section.last_sync else None if section.last_sync else None
try: try:
element.iterator = PF.SectionItems(section.section_id, element.iterator = PF.SectionItems(section.id,
plex_type=element.plex_type, plex_type=element.plex_type,
updated_at=updated_at, updated_at=updated_at,
last_viewed_at=None) last_viewed_at=None)
@ -329,7 +318,7 @@ class FullSync(common.fullsync_mixin):
# some items from the PMS # some items from the PMS
with PlexDB() as plexdb: with PlexDB() as plexdb:
# Set the new time mark for the next delta sync # Set the new time mark for the next delta sync
plexdb.update_section_last_sync(section.section_id, plexdb.update_section_last_sync(section.id,
self.current_sync) self.current_sync)
common.update_kodi_library(video=True, music=True) common.update_kodi_library(video=True, music=True)
# In order to not delete all your songs again # In order to not delete all your songs again

View file

@ -41,12 +41,12 @@ class Section(object):
""" """
def __init__(self, index=None, xml_element=None, section_db_element=None): def __init__(self, index=None, xml_element=None, section_db_element=None):
# Unique Plex id of this Plex library section # Unique Plex id of this Plex library section
self._section_id = None # int self._id = None # int
# Plex librarySectionUUID, unique for this section # Plex librarySectionUUID, unique for this section
self.uuid = None self.uuid = None
# Building block for window variable # Building block for window variable
self._node = None # unicode self._node = None # unicode
# Index of this section (as section_id might not be subsequent) # Index of this section (as id might not be subsequent)
# This follows 1:1 the sequence in with the PMS returns the sections # This follows 1:1 the sequence in with the PMS returns the sections
self._index = None # Codacy-bug self._index = None # Codacy-bug
self.index = index # int self.index = index # int
@ -93,7 +93,7 @@ class Section(object):
return ("{{" return ("{{"
"'index': {self.index}, " "'index': {self.index}, "
"'name': '{self.name}', " "'name': '{self.name}', "
"'section_id': {self.section_id}, " "'id': {self.id}, "
"'section_type': '{self.section_type}', " "'section_type': '{self.section_type}', "
"'sync_to_kodi': {self.sync_to_kodi}, " "'sync_to_kodi': {self.sync_to_kodi}, "
"'last_sync': {self.last_sync}, " "'last_sync': {self.last_sync}, "
@ -105,12 +105,12 @@ class Section(object):
__repr__ = __str__ __repr__ = __str__
def __nonzero__(self): def __nonzero__(self):
return (self.section_id is not None and return (self.id is not None and
self.name is not None and self.name is not None and
self.section_type is not None) self.section_type is not None)
def __eq__(self, section): def __eq__(self, section):
return (self.section_id == section.section_id and return (self.id == section.id and
self.name == section.name and self.name == section.name and
self.section_type == section.section_type) self.section_type == section.section_type)
@ -118,12 +118,12 @@ class Section(object):
return not self == section return not self == section
@property @property
def section_id(self): def id(self):
return self._section_id return self._id
@section_id.setter @id.setter
def section_id(self, value): def id(self, value):
self._section_id = value self._id = value
self._path = path_ops.path.join(LIBRARY_PATH, 'Plex-%s' % value, '') self._path = path_ops.path.join(LIBRARY_PATH, 'Plex-%s' % value, '')
self._playlist_path = path_ops.path.join(PLAYLISTS_PATH, self._playlist_path = path_ops.path.join(PLAYLISTS_PATH,
'Plex %s.xsp' % value) 'Plex %s.xsp' % value)
@ -166,7 +166,7 @@ class Section(object):
return self._playlist_path return self._playlist_path
def from_db_element(self, section_db_element): def from_db_element(self, section_db_element):
self.section_id = section_db_element['section_id'] self.id = section_db_element['section_id']
self.uuid = section_db_element['uuid'] self.uuid = section_db_element['uuid']
self.name = section_db_element['section_name'] self.name = section_db_element['section_name']
self.section_type = section_db_element['plex_type'] self.section_type = section_db_element['plex_type']
@ -178,7 +178,7 @@ class Section(object):
Reads section from a PMS xml (Plex id, name, Plex type) Reads section from a PMS xml (Plex id, name, Plex type)
""" """
api = API(xml_element) api = API(xml_element)
self.section_id = utils.cast(int, xml_element.get('key')) self.id = utils.cast(int, xml_element.get('key'))
self.uuid = xml_element.get('uuid') self.uuid = xml_element.get('uuid')
self.name = api.title() self.name = api.title()
self.section_type = api.plex_type() self.section_type = api.plex_type()
@ -207,7 +207,7 @@ class Section(object):
if not self: if not self:
raise RuntimeError('Section not clearly defined: %s' % self) raise RuntimeError('Section not clearly defined: %s' % self)
if plexdb: if plexdb:
plexdb.add_section(self.section_id, plexdb.add_section(self.id,
self.uuid, self.uuid,
self.name, self.name,
self.section_type, self.section_type,
@ -215,7 +215,7 @@ class Section(object):
self.last_sync) self.last_sync)
else: else:
with PlexDB(lock=False) as plexdb: with PlexDB(lock=False) as plexdb:
plexdb.add_section(self.section_id, plexdb.add_section(self.id,
self.uuid, self.uuid,
self.name, self.name,
self.section_type, self.section_type,
@ -245,21 +245,21 @@ class Section(object):
# nodes as "submenus" once the user navigates into this section # nodes as "submenus" once the user navigates into this section
args = { args = {
'mode': 'browseplex', 'mode': 'browseplex',
'key': '/library/sections/%s' % self.section_id, 'key': '/library/sections/%s' % self.id,
'plex_type': self.section_type, 'plex_type': self.section_type,
'section_id': unicode(self.section_id) 'section_id': unicode(self.id)
} }
if not self.sync_to_kodi: if not self.sync_to_kodi:
args['synched'] = 'false' args['synched'] = 'false'
addon_index = self.addon_path(args) addon_index = self.addon_path(args)
if self.sync_to_kodi and self.section_type in v.PLEX_VIDEOTYPES: if self.sync_to_kodi and self.section_type in v.PLEX_VIDEOTYPES:
path = 'library://video/Plex-{0}/{0}_all.xml' path = 'library://video/Plex-{0}/{0}_all.xml'
path = path.format(self.section_id) path = path.format(self.id)
index = 'library://video/Plex-%s' % self.section_id index = 'library://video/Plex-%s' % self.id
else: else:
# No xmls to link to - let's show the listings on the fly # No xmls to link to - let's show the listings on the fly
index = addon_index index = addon_index
args['key'] = '/library/sections/%s/all' % self.section_id args['key'] = '/library/sections/%s/all' % self.id
path = self.addon_path(args) path = self.addon_path(args)
# .index will list all possible nodes for this library # .index will list all possible nodes for this library
utils.window('%s.index' % self.node, value=index) utils.window('%s.index' % self.node, value=index)
@ -277,7 +277,7 @@ class Section(object):
# Pictures # Pictures
utils.window('%s.path' % self.node, utils.window('%s.path' % self.node,
value='ActivateWindow(pictures,%s,return)' % path) value='ActivateWindow(pictures,%s,return)' % path)
utils.window('%s.id' % self.node, value=str(self.section_id)) utils.window('%s.id' % self.node, value=str(self.id))
# To let the user navigate into this node when selecting widgets # To let the user navigate into this node when selecting widgets
utils.window('%s.addon_index' % self.node, value=addon_index) utils.window('%s.addon_index' % self.node, value=addon_index)
if not self.sync_to_kodi: if not self.sync_to_kodi:
@ -316,7 +316,7 @@ class Section(object):
def _build_node(self, node_type, node_name, args, content, pms_node): def _build_node(self, node_type, node_name, args, content, pms_node):
self.content = content self.content = content
node_name = node_name.format(self=self) node_name = node_name.format(self=self)
xml_name = '%s_%s.xml' % (self.section_id, node_type) xml_name = '%s_%s.xml' % (self.id, node_type)
path = path_ops.path.join(self.path, xml_name) path = path_ops.path.join(self.path, xml_name)
if not path_ops.exists(path): if not path_ops.exists(path):
if pms_node: if pms_node:
@ -327,7 +327,7 @@ class Section(object):
xml = getattr(nodes, 'node_%s' % node_type)(self, node_name) xml = getattr(nodes, 'node_%s' % node_type)(self, node_name)
self._write_xml(xml, xml_name) self._write_xml(xml, xml_name)
self.order += 1 self.order += 1
path = 'library://video/Plex-%s/%s' % (self.section_id, xml_name) path = 'library://video/Plex-%s/%s' % (self.id, xml_name)
self._window_node(path, node_name, node_type, pms_node) self._window_node(path, node_name, node_type, pms_node)
def _write_xml(self, xml, xml_name): def _write_xml(self, xml, xml_name):
@ -366,13 +366,13 @@ class Section(object):
# if node_type == 'all': # if node_type == 'all':
# var = self.node # var = self.node
# utils.window('%s.index' % var, # utils.window('%s.index' % var,
# value=path.replace('%s_all.xml' % self.section_id, '')) # value=path.replace('%s_all.xml' % self.id, ''))
# utils.window('%s.title' % var, value=self.name) # utils.window('%s.title' % var, value=self.name)
# else: # else:
var = '%s.%s' % (self.node, node_type) var = '%s.%s' % (self.node, node_type)
utils.window('%s.index' % var, value=path) utils.window('%s.index' % var, value=path)
utils.window('%s.title' % var, value=node_name) utils.window('%s.title' % var, value=node_name)
utils.window('%s.id' % var, value=str(self.section_id)) utils.window('%s.id' % var, value=str(self.id))
utils.window('%s.path' % var, value=window_path) utils.window('%s.path' % var, value=window_path)
utils.window('%s.type' % var, value=self.content) utils.window('%s.type' % var, value=self.content)
utils.window('%s.content' % var, value=path) utils.window('%s.content' % var, value=path)
@ -407,10 +407,10 @@ class Section(object):
Removes this sections completely from the Plex DB Removes this sections completely from the Plex DB
""" """
if plexdb: if plexdb:
plexdb.remove_section(self.section_id) plexdb.remove_section(self.id)
else: else:
with PlexDB(lock=False) as plexdb: with PlexDB(lock=False) as plexdb:
plexdb.remove_section(self.section_id) plexdb.remove_section(self.id)
def remove(self): def remove(self):
""" """
@ -473,7 +473,7 @@ def _delete_kodi_db_items(section):
for plex_type, context in types: for plex_type, context in types:
while True: while True:
with PlexDB() as plexdb: with PlexDB() as plexdb:
plex_ids = list(plexdb.plexid_by_sectionid(section.section_id, plex_ids = list(plexdb.plexid_by_sectionid(section.id,
plex_type, plex_type,
BATCH_SIZE)) BATCH_SIZE))
with kodi_context(texture_db=True) as kodidb: with kodi_context(texture_db=True) as kodidb: