Add missing method
This commit is contained in:
parent
3a411cc36b
commit
b7aedca7fa
4 changed files with 90 additions and 2 deletions
|
@ -78,7 +78,7 @@ class FullSync(backgroundthread.KillableThread, common.libsync_mixin):
|
|||
"""
|
||||
plex_id = int(xml_item.get('ratingKey'))
|
||||
if self.new_items_only:
|
||||
if self.plex_db.check_plexid(plex_id) is None:
|
||||
if not self.plex_db.is_recorded(plex_id, self.plex_type):
|
||||
backgroundthread.BGThreader.addTask(
|
||||
GetMetadataTask().setup(self.queue,
|
||||
plex_id,
|
||||
|
|
|
@ -7,7 +7,8 @@ from .tvshows import TVShows
|
|||
from .movies import Movies
|
||||
from .music import Music
|
||||
from .playlists import Playlists
|
||||
from .sections import Sections
|
||||
|
||||
|
||||
class PlexDB(PlexDBBase, TVShows, Movies, Music, Playlists):
|
||||
class PlexDB(PlexDBBase, TVShows, Movies, Music, Playlists, Sections):
|
||||
pass
|
||||
|
|
|
@ -31,6 +31,14 @@ class PlexDBBase(object):
|
|||
self.plexconn.commit()
|
||||
self.plexconn.close()
|
||||
|
||||
def is_recorded(self, plex_id, plex_type):
|
||||
"""
|
||||
FAST method to check whether a plex_id has already been recorded
|
||||
"""
|
||||
query = 'SELECT plex_id FROM %s WHERE plex_id = ?' % plex_type
|
||||
self.cursor.execute(query, (plex_id, ))
|
||||
return self.cursor.fetchone() is not None
|
||||
|
||||
def item_by_id(self, plex_id, plex_type=None):
|
||||
"""
|
||||
Returns the item for plex_id or None.
|
||||
|
|
79
resources/lib/plex_db/sections.py
Normal file
79
resources/lib/plex_db/sections.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
|
||||
class Sections(object):
|
||||
def section_ids(self):
|
||||
"""
|
||||
Returns an iterator for section Plex ids for all sections
|
||||
"""
|
||||
self.cursor.execute('SELECT section_id FROM sections')
|
||||
return (x[0] for x in self.cursor)
|
||||
|
||||
def section_infos(self):
|
||||
"""
|
||||
Returns an iterator for dicts for all Plex libraries:
|
||||
{
|
||||
'section_id'
|
||||
'section_name'
|
||||
'plex_type'
|
||||
'kodi_tagid'
|
||||
'sync_to_kodi'
|
||||
}
|
||||
"""
|
||||
self.cursor.execute('SELECT * FROM sections')
|
||||
return ({'section_id': x[0],
|
||||
'section_name': x[1],
|
||||
'plex_type': x[2],
|
||||
'kodi_tagid': x[3],
|
||||
'sync_to_kodi': x[4]} for x in self.cursor)
|
||||
|
||||
def section(self, section_id):
|
||||
"""
|
||||
For section_id, returns the tuple (or None)
|
||||
section_id INTEGER PRIMARY KEY,
|
||||
section_name TEXT,
|
||||
plex_type TEXT,
|
||||
kodi_tagid INTEGER,
|
||||
sync_to_kodi INTEGER
|
||||
"""
|
||||
self.cursor.execute('SELECT * FROM sections WHERE section_id = ? LIMIT 1',
|
||||
(section_id, ))
|
||||
return self.cursor.fetchone()
|
||||
|
||||
def section_id_by_name(self, section_name):
|
||||
"""
|
||||
Returns the section_id for section_name (or None)
|
||||
"""
|
||||
self.cursor.execute('SELECT section_id FROM sections WHERE section_name = ? LIMIT 1,'
|
||||
(section_name, ))
|
||||
try:
|
||||
return self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
def add_section(self, section_id, section_name, plex_type, kodi_tagid,
|
||||
sync_to_kodi=True):
|
||||
"""
|
||||
Appends a Plex section to the Plex sections table
|
||||
sync=False: Plex library won't be synced to Kodi
|
||||
"""
|
||||
query = '''
|
||||
INSERT OR REPLACE INTO sections(
|
||||
section_id, section_name, plex_type, kodi_tagid, sync_to_kodi)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
'''
|
||||
self.cursor.execute(query,
|
||||
(section_id,
|
||||
section_name,
|
||||
plex_type,
|
||||
kodi_tagid,
|
||||
sync_to_kodi))
|
||||
|
||||
def remove_section(self, section_id):
|
||||
"""
|
||||
Removes the Plex db entry for the section with section_id
|
||||
"""
|
||||
self.cursor.execute('DELETE FROM sections WHERE section_id = ?',
|
||||
(section_id, ))
|
Loading…
Reference in a new issue