Rename section.section_id to section.id
This commit is contained in:
parent
e76fd03915
commit
ab8089d3b1
2 changed files with 36 additions and 47 deletions
|
@ -25,18 +25,16 @@ UPDATED_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
|
||||
Plex library section we're looking at
|
||||
"""
|
||||
def __init__(self, context, total_number_of_items, section_name,
|
||||
section_id, plex_type):
|
||||
self.context = context
|
||||
def __init__(self, total_number_of_items, section):
|
||||
super(InitNewSection, self).__init__()
|
||||
# Copy all section attributes to this instance
|
||||
self.__dict__.update(section.__dict__)
|
||||
self.total = total_number_of_items
|
||||
self.name = section_name
|
||||
self.id = section_id
|
||||
self.plex_type = plex_type
|
||||
|
||||
|
||||
class FullSync(common.fullsync_mixin):
|
||||
|
@ -167,12 +165,7 @@ class FullSync(common.fullsync_mixin):
|
|||
# Sync new, updated and deleted items
|
||||
iterator = section.iterator
|
||||
# Tell the processing thread about this new section
|
||||
queue_info = InitNewSection(section.context,
|
||||
iterator.total,
|
||||
iterator.get('librarySectionTitle',
|
||||
iterator.get('title1')),
|
||||
section.section_id,
|
||||
section.plex_type)
|
||||
queue_info = InitNewSection(iterator.total, section)
|
||||
self.queue.put(queue_info)
|
||||
last = True
|
||||
# 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
|
||||
iterator = section.iterator
|
||||
# Tell the processing thread about this new section
|
||||
queue_info = InitNewSection(section.context,
|
||||
iterator.total,
|
||||
section.name,
|
||||
section.section_id,
|
||||
section.plex_type)
|
||||
queue_info = InitNewSection(iterator.total, section)
|
||||
self.queue.put(queue_info)
|
||||
self.total = iterator.total
|
||||
self.section_name = section.name
|
||||
|
@ -272,7 +261,7 @@ class FullSync(common.fullsync_mixin):
|
|||
updated_at = section.last_sync - UPDATED_AT_SAFETY \
|
||||
if section.last_sync else None
|
||||
try:
|
||||
element.iterator = PF.SectionItems(section.section_id,
|
||||
element.iterator = PF.SectionItems(section.id,
|
||||
plex_type=element.plex_type,
|
||||
updated_at=updated_at,
|
||||
last_viewed_at=None)
|
||||
|
@ -329,7 +318,7 @@ class FullSync(common.fullsync_mixin):
|
|||
# some items from the PMS
|
||||
with PlexDB() as plexdb:
|
||||
# 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)
|
||||
common.update_kodi_library(video=True, music=True)
|
||||
# In order to not delete all your songs again
|
||||
|
|
|
@ -41,12 +41,12 @@ class Section(object):
|
|||
"""
|
||||
def __init__(self, index=None, xml_element=None, section_db_element=None):
|
||||
# Unique Plex id of this Plex library section
|
||||
self._section_id = None # int
|
||||
self._id = None # int
|
||||
# Plex librarySectionUUID, unique for this section
|
||||
self.uuid = None
|
||||
# Building block for window variable
|
||||
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
|
||||
self._index = None # Codacy-bug
|
||||
self.index = index # int
|
||||
|
@ -93,7 +93,7 @@ class Section(object):
|
|||
return ("{{"
|
||||
"'index': {self.index}, "
|
||||
"'name': '{self.name}', "
|
||||
"'section_id': {self.section_id}, "
|
||||
"'id': {self.id}, "
|
||||
"'section_type': '{self.section_type}', "
|
||||
"'sync_to_kodi': {self.sync_to_kodi}, "
|
||||
"'last_sync': {self.last_sync}, "
|
||||
|
@ -105,12 +105,12 @@ class Section(object):
|
|||
__repr__ = __str__
|
||||
|
||||
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.section_type is not None)
|
||||
|
||||
def __eq__(self, section):
|
||||
return (self.section_id == section.section_id and
|
||||
return (self.id == section.id and
|
||||
self.name == section.name and
|
||||
self.section_type == section.section_type)
|
||||
|
||||
|
@ -118,12 +118,12 @@ class Section(object):
|
|||
return not self == section
|
||||
|
||||
@property
|
||||
def section_id(self):
|
||||
return self._section_id
|
||||
def id(self):
|
||||
return self._id
|
||||
|
||||
@section_id.setter
|
||||
def section_id(self, value):
|
||||
self._section_id = value
|
||||
@id.setter
|
||||
def id(self, value):
|
||||
self._id = value
|
||||
self._path = path_ops.path.join(LIBRARY_PATH, 'Plex-%s' % value, '')
|
||||
self._playlist_path = path_ops.path.join(PLAYLISTS_PATH,
|
||||
'Plex %s.xsp' % value)
|
||||
|
@ -166,7 +166,7 @@ class Section(object):
|
|||
return self._playlist_path
|
||||
|
||||
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.name = section_db_element['section_name']
|
||||
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)
|
||||
"""
|
||||
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.name = api.title()
|
||||
self.section_type = api.plex_type()
|
||||
|
@ -207,7 +207,7 @@ class Section(object):
|
|||
if not self:
|
||||
raise RuntimeError('Section not clearly defined: %s' % self)
|
||||
if plexdb:
|
||||
plexdb.add_section(self.section_id,
|
||||
plexdb.add_section(self.id,
|
||||
self.uuid,
|
||||
self.name,
|
||||
self.section_type,
|
||||
|
@ -215,7 +215,7 @@ class Section(object):
|
|||
self.last_sync)
|
||||
else:
|
||||
with PlexDB(lock=False) as plexdb:
|
||||
plexdb.add_section(self.section_id,
|
||||
plexdb.add_section(self.id,
|
||||
self.uuid,
|
||||
self.name,
|
||||
self.section_type,
|
||||
|
@ -245,21 +245,21 @@ class Section(object):
|
|||
# nodes as "submenus" once the user navigates into this section
|
||||
args = {
|
||||
'mode': 'browseplex',
|
||||
'key': '/library/sections/%s' % self.section_id,
|
||||
'key': '/library/sections/%s' % self.id,
|
||||
'plex_type': self.section_type,
|
||||
'section_id': unicode(self.section_id)
|
||||
'section_id': unicode(self.id)
|
||||
}
|
||||
if not self.sync_to_kodi:
|
||||
args['synched'] = 'false'
|
||||
addon_index = self.addon_path(args)
|
||||
if self.sync_to_kodi and self.section_type in v.PLEX_VIDEOTYPES:
|
||||
path = 'library://video/Plex-{0}/{0}_all.xml'
|
||||
path = path.format(self.section_id)
|
||||
index = 'library://video/Plex-%s' % self.section_id
|
||||
path = path.format(self.id)
|
||||
index = 'library://video/Plex-%s' % self.id
|
||||
else:
|
||||
# No xmls to link to - let's show the listings on the fly
|
||||
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)
|
||||
# .index will list all possible nodes for this library
|
||||
utils.window('%s.index' % self.node, value=index)
|
||||
|
@ -277,7 +277,7 @@ class Section(object):
|
|||
# Pictures
|
||||
utils.window('%s.path' % self.node,
|
||||
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
|
||||
utils.window('%s.addon_index' % self.node, value=addon_index)
|
||||
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):
|
||||
self.content = content
|
||||
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)
|
||||
if not path_ops.exists(path):
|
||||
if pms_node:
|
||||
|
@ -327,7 +327,7 @@ class Section(object):
|
|||
xml = getattr(nodes, 'node_%s' % node_type)(self, node_name)
|
||||
self._write_xml(xml, xml_name)
|
||||
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)
|
||||
|
||||
def _write_xml(self, xml, xml_name):
|
||||
|
@ -366,13 +366,13 @@ class Section(object):
|
|||
# if node_type == 'all':
|
||||
# var = self.node
|
||||
# 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)
|
||||
# else:
|
||||
var = '%s.%s' % (self.node, node_type)
|
||||
utils.window('%s.index' % var, value=path)
|
||||
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.type' % var, value=self.content)
|
||||
utils.window('%s.content' % var, value=path)
|
||||
|
@ -407,10 +407,10 @@ class Section(object):
|
|||
Removes this sections completely from the Plex DB
|
||||
"""
|
||||
if plexdb:
|
||||
plexdb.remove_section(self.section_id)
|
||||
plexdb.remove_section(self.id)
|
||||
else:
|
||||
with PlexDB(lock=False) as plexdb:
|
||||
plexdb.remove_section(self.section_id)
|
||||
plexdb.remove_section(self.id)
|
||||
|
||||
def remove(self):
|
||||
"""
|
||||
|
@ -473,7 +473,7 @@ def _delete_kodi_db_items(section):
|
|||
for plex_type, context in types:
|
||||
while True:
|
||||
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,
|
||||
BATCH_SIZE))
|
||||
with kodi_context(texture_db=True) as kodidb:
|
||||
|
|
Loading…
Reference in a new issue