Change DatabaseConn to return the cursor instead

This commit is contained in:
angelblue05 2016-11-07 17:32:40 -06:00
parent 13e4ff5128
commit 6d0b2b96bc
8 changed files with 218 additions and 244 deletions

View file

@ -15,7 +15,6 @@ import requests
import image_cache_thread import image_cache_thread
from utils import window, settings, dialog, language as lang, JSONRPC from utils import window, settings, dialog, language as lang, JSONRPC
from database import DatabaseConn from database import DatabaseConn
from contextlib import closing
################################################################################################## ##################################################################################################
@ -166,49 +165,47 @@ class Artwork(object):
def _cache_all_video_entries(self, pdialog): def _cache_all_video_entries(self, pdialog):
with DatabaseConn('video') as conn: with DatabaseConn('video') as cursor_video:
with closing(conn.cursor()) as cursor_video:
cursor_video.execute("SELECT url FROM art WHERE media_type != 'actor'") # dont include actors cursor_video.execute("SELECT url FROM art WHERE media_type != 'actor'") # dont include actors
result = cursor_video.fetchall() result = cursor_video.fetchall()
total = len(result) total = len(result)
log.info("Image cache sync about to process %s images", total) log.info("Image cache sync about to process %s images", total)
cursor_video.close() cursor_video.close()
count = 0 count = 0
for url in result: for url in result:
if pdialog.iscanceled(): if pdialog.iscanceled():
break break
percentage = int((float(count) / float(total))*100) percentage = int((float(count) / float(total))*100)
message = "%s of %s (%s)" % (count, total, len(self.image_cache_threads)) message = "%s of %s (%s)" % (count, total, len(self.image_cache_threads))
pdialog.update(percentage, "%s %s" % (lang(33045), message)) pdialog.update(percentage, "%s %s" % (lang(33045), message))
self.cache_texture(url[0]) self.cache_texture(url[0])
count += 1 count += 1
def _cache_all_music_entries(self, pdialog): def _cache_all_music_entries(self, pdialog):
with DatabaseConn('music') as conn: with DatabaseConn('music') as cursor_music:
with closing(conn.cursor()) as cursor_music:
cursor_music.execute("SELECT url FROM art") cursor_music.execute("SELECT url FROM art")
result = cursor_music.fetchall() result = cursor_music.fetchall()
total = len(result) total = len(result)
log.info("Image cache sync about to process %s images", total) log.info("Image cache sync about to process %s images", total)
count = 0 count = 0
for url in result: for url in result:
if pdialog.iscanceled(): if pdialog.iscanceled():
break break
percentage = int((float(count) / float(total))*100) percentage = int((float(count) / float(total))*100)
message = "%s of %s" % (count, total) message = "%s of %s" % (count, total)
pdialog.update(percentage, "%s %s" % (lang(33045), message)) pdialog.update(percentage, "%s %s" % (lang(33045), message))
self.cache_texture(url[0]) self.cache_texture(url[0])
count += 1 count += 1
@classmethod @classmethod
def delete_cache(cls): def delete_cache(cls):
@ -230,14 +227,13 @@ class Artwork(object):
log.debug("deleted: %s", filename) log.debug("deleted: %s", filename)
# remove all existing data from texture DB # remove all existing data from texture DB
with DatabaseConn('texture') as conn: with DatabaseConn('texture') as cursor_texture:
with closing(conn.cursor()) as cursor_texture: cursor_texture.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
cursor_texture.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"') rows = cursor_texture.fetchall()
rows = cursor_texture.fetchall() for row in rows:
for row in rows: table_name = row[0]
table_name = row[0] if table_name != "version":
if table_name != "version": cursor_texture.execute("DELETE FROM " + table_name)
cursor_texture.execute("DELETE FROM " + table_name)
def _add_worker_image_thread(self, url): def _add_worker_image_thread(self, url):
@ -431,28 +427,26 @@ class Artwork(object):
@classmethod @classmethod
def delete_cached_artwork(cls, url): def delete_cached_artwork(cls, url):
# Only necessary to remove and apply a new backdrop or poster # Only necessary to remove and apply a new backdrop or poster
with DatabaseConn('texture') as conn: with DatabaseConn('texture') as cursor_texture:
with closing(conn.cursor()) as cursor_texture: try:
cursor_texture.execute("SELECT cachedurl FROM texture WHERE url = ?", (url,))
cached_url = cursor_texture.fetchone()[0]
except TypeError:
log.info("Could not find cached url")
except OperationalError:
log.info("Database is locked. Skip deletion process.")
else: # Delete thumbnail as well as the entry
thumbnails = xbmc.translatePath("special://thumbnails/%s" % cached_url).decode('utf-8')
log.info("Deleting cached thumbnail: %s", thumbnails)
xbmcvfs.delete(thumbnails)
try: try:
cursor_texture.execute("SELECT cachedurl FROM texture WHERE url = ?", (url,)) cursor_texture.execute("DELETE FROM texture WHERE url = ?", (url,))
cached_url = cursor_texture.fetchone()[0]
except TypeError:
log.info("Could not find cached url")
except OperationalError: except OperationalError:
log.info("Database is locked. Skip deletion process.") log.debug("Issue deleting url from cache. Skipping.")
else: # Delete thumbnail as well as the entry
thumbnails = xbmc.translatePath("special://thumbnails/%s" % cached_url).decode('utf-8')
log.info("Deleting cached thumbnail: %s", thumbnails)
xbmcvfs.delete(thumbnails)
try:
cursor_texture.execute("DELETE FROM texture WHERE url = ?", (url,))
except OperationalError:
log.debug("Issue deleting url from cache. Skipping.")
def get_people_artwork(self, people): def get_people_artwork(self, people):
# append imageurl if existing # append imageurl if existing

View file

@ -14,7 +14,6 @@ import musicutils as musicutils
from utils import settings, dialog, language as lang from utils import settings, dialog, language as lang
from dialogs import context from dialogs import context
from database import DatabaseConn from database import DatabaseConn
from contextlib import closing
################################################################################################# #################################################################################################
@ -89,14 +88,13 @@ class ContextMenu(object):
if not item_id and kodi_id and item_type: if not item_id and kodi_id and item_type:
with DatabaseConn('emby') as conn: with DatabaseConn('emby') as cursor:
with closing(conn.cursor()) as cursor: emby_db = embydb.Embydb_Functions(cursor)
emby_db = embydb.Embydb_Functions(cursor) item = emby_db.getItem_byKodiId(kodi_id, item_type)
item = emby_db.getItem_byKodiId(kodi_id, item_type) try:
try: item_id = item[0]
item_id = item[0] except TypeError:
except TypeError: pass
pass
return item_id return item_id
@ -165,28 +163,27 @@ class ContextMenu(object):
def _rate_song(self): def _rate_song(self):
with DatabaseConn('music') as conn: with DatabaseConn('music') as cursor_music:
with closing(conn.cursor()) as cursor_music: query = "SELECT rating FROM song WHERE idSong = ?"
query = "SELECT rating FROM song WHERE idSong = ?" cursor_music.execute(query, (self.kodi_id,))
cursor_music.execute(query, (self.kodi_id,)) try:
try: value = cursor_music.fetchone()[0]
value = cursor_music.fetchone()[0] current_value = int(round(float(value), 0))
current_value = int(round(float(value), 0)) except TypeError:
except TypeError: pass
pass else:
else: new_value = dialog("numeric", 0, lang(30411), str(current_value))
new_value = dialog("numeric", 0, lang(30411), str(current_value)) if new_value > -1:
if new_value > -1:
new_value = int(new_value) new_value = int(new_value)
if new_value > 5: if new_value > 5:
new_value = 5 new_value = 5
if settings('enableUpdateSongRating') == "true": if settings('enableUpdateSongRating') == "true":
musicutils.updateRatingToFile(new_value, self.api.get_file_path()) musicutils.updateRatingToFile(new_value, self.api.get_file_path())
query = "UPDATE song SET rating = ? WHERE idSong = ?" query = "UPDATE song SET rating = ? WHERE idSong = ?"
cursor_music.execute(query, (new_value, self.kodi_id,)) cursor_music.execute(query, (new_value, self.kodi_id,))
def _delete_item(self): def _delete_item(self):

View file

@ -4,7 +4,6 @@
import logging import logging
import sqlite3 import sqlite3
from contextlib import closing
import sys import sys
import traceback import traceback
@ -98,7 +97,8 @@ class DatabaseConn(object):
self.conn = sqlite3.connect(self.path, timeout=self.timeout) self.conn = sqlite3.connect(self.path, timeout=self.timeout)
log.info("opened: %s - %s", self.path, id(self.conn)) log.info("opened: %s - %s", self.path, id(self.conn))
return self.conn self.cursor = self.conn.cursor()
return self.conn.cursor()
def _SQL(self, media_type): def _SQL(self, media_type):
@ -126,6 +126,7 @@ class DatabaseConn(object):
log.info("commit: %s", self.path) log.info("commit: %s", self.path)
log.info("closing: %s - %s", self.path, id(self.conn)) log.info("closing: %s - %s", self.path, id(self.conn))
self.cursor.close()
self.conn.close() self.conn.close()
@ -156,39 +157,36 @@ def db_reset():
# Wipe the kodi databases # Wipe the kodi databases
log.warn("Resetting the Kodi video database.") log.warn("Resetting the Kodi video database.")
with DatabaseConn('video') as conn: with DatabaseConn('video') as cursor:
with closing(conn.cursor()) as cursor: cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"') rows = cursor.fetchall()
rows = cursor.fetchall() for row in rows:
for row in rows: tablename = row[0]
tablename = row[0] if tablename != "version":
if tablename != "version": cursor.execute("DELETE FROM " + tablename)
cursor.execute("DELETE FROM " + tablename)
if settings('enableMusic') == "true": if settings('enableMusic') == "true":
log.warn("Resetting the Kodi music database.") log.warn("Resetting the Kodi music database.")
with DatabaseConn('music') as conn: with DatabaseConn('music') as cursor:
with closing(conn.cursor()) as cursor:
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
rows = cursor.fetchall()
for row in rows:
tablename = row[0]
if tablename != "version":
cursor.execute("DELETE FROM " + tablename)
# Wipe the emby database
log.warn("Resetting the Emby database.")
with DatabaseConn('emby') as conn:
with closing(conn.cursor()) as cursor:
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"') cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
rows = cursor.fetchall() rows = cursor.fetchall()
for row in rows: for row in rows:
tablename = row[0] tablename = row[0]
if tablename != "version": if tablename != "version":
cursor.execute("DELETE FROM " + tablename) cursor.execute("DELETE FROM " + tablename)
cursor.execute('DROP table IF EXISTS emby')
cursor.execute('DROP table IF EXISTS view') # Wipe the emby database
cursor.execute("DROP table IF EXISTS version") log.warn("Resetting the Emby database.")
with DatabaseConn('emby') as cursor:
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
rows = cursor.fetchall()
for row in rows:
tablename = row[0]
if tablename != "version":
cursor.execute("DELETE FROM " + tablename)
cursor.execute('DROP table IF EXISTS emby')
cursor.execute('DROP table IF EXISTS view')
cursor.execute("DROP table IF EXISTS version")
# Offer to wipe cached thumbnails # Offer to wipe cached thumbnails
if dialog.yesno(language(29999), language(33086)): if dialog.yesno(language(29999), language(33086)):

View file

@ -30,7 +30,6 @@ import api
from views import Playlist, VideoNodes from views import Playlist, VideoNodes
from utils import window, settings, dialog, language as lang from utils import window, settings, dialog, language as lang
from database import DatabaseConn from database import DatabaseConn
from contextlib import closing
################################################################################################# #################################################################################################
@ -235,10 +234,9 @@ def deleteItem():
log.info("Unknown type, unable to proceed.") log.info("Unknown type, unable to proceed.")
return return
with DatabaseConn('emby') as conn: with DatabaseConn('emby') as cursor:
with closing(conn.cursor()) as cursor: emby_db = embydb.Embydb_Functions(cursor)
emby_db = embydb.Embydb_Functions(cursor) item = emby_db.getItem_byKodiId(dbId, itemType)
item = emby_db.getItem_byKodiId(dbId, itemType)
try: try:
itemId = item[0] itemId = item[0]
@ -422,10 +420,9 @@ def getThemeMedia():
return return
# Get every user view Id # Get every user view Id
with DatabaseConn('emby') as conn: with DatabaseConn('emby') as cursor:
with closing(conn.cursor()) as cursor: emby_db = embydb.Embydb_Functions(cursor)
emby_db = embydb.Embydb_Functions(cursor) viewids = emby_db.getViews()
viewids = emby_db.getViews()
# Get Ids with Theme Videos # Get Ids with Theme Videos
itemIds = {} itemIds = {}

View file

@ -8,7 +8,6 @@ import read_embyserver as embyserver
from objects import Movies, MusicVideos, TVShows, Music from objects import Movies, MusicVideos, TVShows, Music
from utils import settings from utils import settings
from database import DatabaseConn from database import DatabaseConn
from contextlib import closing
################################################################################################# #################################################################################################
@ -62,38 +61,37 @@ class Items(object):
# this is going to open a music connection even if it is not needed but # this is going to open a music connection even if it is not needed but
# I feel that is better than trying to sort out the login yourself # I feel that is better than trying to sort out the login yourself
with DatabaseConn('music') as conn: with DatabaseConn('music') as cursor_music:
with closing(conn.cursor()) as cursor_music:
for itemtype in items: for itemtype in items:
# Safety check # Safety check
if not itemtypes.get(itemtype): if not itemtypes.get(itemtype):
# We don't process this type of item # We don't process this type of item
continue continue
itemlist = items[itemtype] itemlist = items[itemtype]
if not itemlist: if not itemlist:
# The list to process is empty # The list to process is empty
continue continue
if itemtype in ('MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio'): if itemtype in ('MusicAlbum', 'MusicArtist', 'AlbumArtist', 'Audio'):
if self.music_enabled: if self.music_enabled:
items_process = itemtypes[itemtype](embycursor, cursor_music, pdialog) # see note above items_process = itemtypes[itemtype](embycursor, cursor_music, pdialog) # see note above
else:
# Music is not enabled, do not proceed with itemtype
continue
else: else:
update_videolibrary = True # Music is not enabled, do not proceed with itemtype
items_process = itemtypes[itemtype](embycursor, kodicursor, pdialog) continue
else:
update_videolibrary = True
items_process = itemtypes[itemtype](embycursor, kodicursor, pdialog)
if process == "added": if process == "added":
items_process.add_all(itemtype, itemlist) items_process.add_all(itemtype, itemlist)
elif process == "remove": elif process == "remove":
items_process.remove_all(itemtype, itemlist) items_process.remove_all(itemtype, itemlist)
else: else:
process_items = self.emby.getFullItems(itemlist) process_items = self.emby.getFullItems(itemlist)
items_process.process_all(itemtype, process, process_items, total) items_process.process_all(itemtype, process, process_items, total)
return (True, update_videolibrary) return (True, update_videolibrary)

View file

@ -14,7 +14,6 @@ import playbackutils as pbutils
from utils import window, settings from utils import window, settings
from ga_client import log_error from ga_client import log_error
from database import DatabaseConn from database import DatabaseConn
from contextlib import closing
################################################################################################# #################################################################################################
@ -167,10 +166,9 @@ class KodiMonitor(xbmc.Monitor):
item_id = None item_id = None
with DatabaseConn('emby') as conn: with DatabaseConn('emby') as cursor:
with closing(conn.cursor()) as cursor: emby_db = embydb.Embydb_Functions(cursor)
emby_db = embydb.Embydb_Functions(cursor) db_item = emby_db.getItem_byKodiId(kodi_id, item_type)
db_item = emby_db.getItem_byKodiId(kodi_id, item_type)
try: try:
item_id = db_item[0] item_id = db_item[0]

View file

@ -14,6 +14,7 @@ import xbmcvfs
import api import api
import utils import utils
import clientinfo import clientinfo
import database
import downloadutils import downloadutils
import itemtypes import itemtypes
import embydb_functions as embydb import embydb_functions as embydb
@ -23,8 +24,6 @@ import views
from objects import Movies, MusicVideos, TVShows, Music from objects import Movies, MusicVideos, TVShows, Music
from utils import window, settings, language as lang, should_stop from utils import window, settings, language as lang, should_stop
from ga_client import GoogleAnalytics from ga_client import GoogleAnalytics
import database
from contextlib import closing
################################################################################################## ##################################################################################################
@ -233,8 +232,8 @@ class LibrarySync(threading.Thread):
utils.sourcesXML() utils.sourcesXML()
# use emby and video DBs # use emby and video DBs
with database.DatabaseConn('emby') as conn_emby, database.DatabaseConn('video') as conn_video: with database.DatabaseConn('emby') as cursor_emby:
with closing(conn_emby.cursor()) as cursor_emby, closing(conn_video.cursor()) as cursor_video: with database.DatabaseConn('video') as cursor_video:
# content sync: movies, tvshows, musicvideos, music # content sync: movies, tvshows, musicvideos, music
if manualrun: if manualrun:
@ -275,7 +274,7 @@ class LibrarySync(threading.Thread):
# Set views # Set views
views.Views(cursor_emby, cursor_video).maintain() views.Views(cursor_emby, cursor_video).maintain()
conn_emby.commit() cursor_emby.connection.commit()
#self.maintainViews(cursor_emby, cursor_video) #self.maintainViews(cursor_emby, cursor_video)
# Sync video library # Sync video library
@ -312,8 +311,8 @@ class LibrarySync(threading.Thread):
if repair and 'music' not in repair_list: if repair and 'music' not in repair_list:
pass pass
else: else:
with database.DatabaseConn('emby') as conn_emby, database.DatabaseConn('music') as conn_music: with database.DatabaseConn('emby') as cursor_emby:
with closing(conn_emby.cursor()) as cursor_emby, closing(conn_music.cursor()) as cursor_music: with database.DatabaseConn('music') as cursor_music:
startTime = datetime.now() startTime = datetime.now()
completed = self.music(cursor_emby, cursor_music, pDialog) completed = self.music(cursor_emby, cursor_music, pDialog)
if not completed: if not completed:
@ -332,10 +331,9 @@ class LibrarySync(threading.Thread):
if pDialog: if pDialog:
pDialog.close() pDialog.close()
with database.DatabaseConn('emby') as conn_emby: with database.DatabaseConn('emby') as cursor_emby:
with closing(conn_emby.cursor()) as cursor_emby: emby_db = embydb.Embydb_Functions(cursor_emby)
emby_db = embydb.Embydb_Functions(cursor_emby) current_version = emby_db.get_version(self.clientInfo.get_version())
current_version = emby_db.get_version(self.clientInfo.get_version())
window('emby_version', current_version) window('emby_version', current_version)
@ -362,8 +360,8 @@ class LibrarySync(threading.Thread):
def refreshViews(self): def refreshViews(self):
with database.DatabaseConn('emby') as conn_emby, database.DatabaseConn() as conn_video: with database.DatabaseConn('emby') as cursor_emby:
with closing(conn_emby.cursor()) as cursor_emby, closing(conn_video.cursor()) as cursor_video: with database.DatabaseConn() as cursor_video:
# Compare views, assign correct tags to items # Compare views, assign correct tags to items
views.Views(cursor_emby, cursor_video).maintain() views.Views(cursor_emby, cursor_video).maintain()
@ -515,8 +513,8 @@ class LibrarySync(threading.Thread):
# do a lib update if any items in list # do a lib update if any items in list
totalUpdates = len(self.addedItems) + len(self.updateItems) + len(self.userdataItems) + len(self.removeItems) totalUpdates = len(self.addedItems) + len(self.updateItems) + len(self.userdataItems) + len(self.removeItems)
if totalUpdates > 0: if totalUpdates > 0:
with database.DatabaseConn('emby') as conn_emby, database.DatabaseConn('video') as conn_video: with database.DatabaseConn('emby') as cursor_emby:
with closing(conn_emby.cursor()) as cursor_emby, closing(conn_video.cursor()) as cursor_video: with database.DatabaseConn('video') as cursor_video:
emby_db = embydb.Embydb_Functions(cursor_emby) emby_db = embydb.Embydb_Functions(cursor_emby)
@ -610,18 +608,17 @@ class LibrarySync(threading.Thread):
def _verify_emby_database(self): def _verify_emby_database(self):
# Create the tables for the emby database # Create the tables for the emby database
with database.DatabaseConn('emby') as conn: with database.DatabaseConn('emby') as cursor:
with closing(conn.cursor()) as cursor: # emby, view, version
# emby, view, version cursor.execute(
cursor.execute( """CREATE TABLE IF NOT EXISTS emby(
"""CREATE TABLE IF NOT EXISTS emby( emby_id TEXT UNIQUE, media_folder TEXT, emby_type TEXT, media_type TEXT,
emby_id TEXT UNIQUE, media_folder TEXT, emby_type TEXT, media_type TEXT, kodi_id INTEGER, kodi_fileid INTEGER, kodi_pathid INTEGER, parent_id INTEGER,
kodi_id INTEGER, kodi_fileid INTEGER, kodi_pathid INTEGER, parent_id INTEGER, checksum INTEGER)""")
checksum INTEGER)""") cursor.execute(
cursor.execute( """CREATE TABLE IF NOT EXISTS view(
"""CREATE TABLE IF NOT EXISTS view( view_id TEXT UNIQUE, view_name TEXT, media_type TEXT, kodi_tagid INTEGER)""")
view_id TEXT UNIQUE, view_name TEXT, media_type TEXT, kodi_tagid INTEGER)""") cursor.execute("CREATE TABLE IF NOT EXISTS version(idVersion TEXT)")
cursor.execute("CREATE TABLE IF NOT EXISTS version(idVersion TEXT)")
def run(self): def run(self):
@ -669,16 +666,14 @@ class LibrarySync(threading.Thread):
if (window('emby_dbCheck') != "true" and settings('SyncInstallRunDone') == "true"): if (window('emby_dbCheck') != "true" and settings('SyncInstallRunDone') == "true"):
# Verify the validity of the database # Verify the validity of the database
log.info("Doing DB Version Check") log.info("Doing DB Version Check")
with database.DatabaseConn('emby') as conn: with database.DatabaseConn('emby') as cursor:
with closing(conn.cursor()) as cursor: emby_db = embydb.Embydb_Functions(cursor)
currentVersion = emby_db.get_version()
emby_db = embydb.Embydb_Functions(cursor) ###$ Begin migration $###
currentVersion = emby_db.get_version() if not currentVersion:
###$ Begin migration $### currentVersion = emby_db.get_version(settings('dbCreatedWithVersion') or self.clientInfo.get_version())
if not currentVersion: log.info("Migration of database version completed")
currentVersion = emby_db.get_version(settings('dbCreatedWithVersion') or self.clientInfo.get_version()) ###$ End migration $###
log.info("Migration of database version completed")
###$ End migration $###
window('emby_version', value=currentVersion) window('emby_version', value=currentVersion)

View file

@ -13,7 +13,6 @@ import embydb_functions as embydb
import read_embyserver as embyserver import read_embyserver as embyserver
from utils import window, JSONRPC from utils import window, JSONRPC
from database import DatabaseConn from database import DatabaseConn
from contextlib import closing
################################################################################################# #################################################################################################
@ -31,75 +30,73 @@ class Playlist(object):
def play_all(self, item_ids, start_at): def play_all(self, item_ids, start_at):
with DatabaseConn('emby') as conn: with DatabaseConn('emby') as cursor:
with closing(conn.cursor()) as cursor: emby_db = embydb.Embydb_Functions(cursor)
emby_db = embydb.Embydb_Functions(cursor)
player = xbmc.Player() player = xbmc.Player()
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear() playlist.clear()
log.info("---*** PLAY ALL ***---") log.info("---*** PLAY ALL ***---")
log.info("Items: %s and start at: %s", item_ids, start_at) log.info("Items: %s and start at: %s", item_ids, start_at)
started = False started = False
window('emby_customplaylist', value="true") window('emby_customplaylist', value="true")
if start_at: if start_at:
# Seek to the starting position # Seek to the starting position
window('emby_customplaylist.seektime', str(start_at)) window('emby_customplaylist.seektime', str(start_at))
for item_id in item_ids: for item_id in item_ids:
log.info("Adding %s to playlist", item_id) log.info("Adding %s to playlist", item_id)
item = emby_db.getItem_byId(item_id) item = emby_db.getItem_byId(item_id)
try: try:
db_id = item[0] db_id = item[0]
media_type = item[4] media_type = item[4]
except TypeError: except TypeError:
# Item is not found in our database, add item manually # Item is not found in our database, add item manually
log.info("Item was not found in the database, manually adding item") log.info("Item was not found in the database, manually adding item")
item = self.emby.getItem(item_id) item = self.emby.getItem(item_id)
self.add_to_xbmc_playlist(playlist, item) self.add_to_xbmc_playlist(playlist, item)
else: # Add to playlist else: # Add to playlist
self.add_to_playlist(db_id, media_type) self.add_to_playlist(db_id, media_type)
if not started: if not started:
started = True started = True
player.play(playlist) player.play(playlist)
self.verify_playlist() self.verify_playlist()
def modify_playlist(self, item_ids): def modify_playlist(self, item_ids):
with DatabaseConn('emby') as conn: with DatabaseConn('emby') as cursor:
with closing(conn.cursor()) as cursor: emby_db = embydb.Embydb_Functions(cursor)
emby_db = embydb.Embydb_Functions(cursor)
log.info("---*** ADD TO PLAYLIST ***---") log.info("---*** ADD TO PLAYLIST ***---")
log.info("Items: %s", item_ids) log.info("Items: %s", item_ids)
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
for item_id in item_ids: for item_id in item_ids:
log.info("Adding %s to playlist", item_id) log.info("Adding %s to playlist", item_id)
item = emby_db.getItem_byId(item_id) item = emby_db.getItem_byId(item_id)
try: try:
db_id = item[0] db_id = item[0]
media_type = item[4] media_type = item[4]
except TypeError: except TypeError:
# Item is not found in our database, add item manually # Item is not found in our database, add item manually
item = self.emby.getItem(item_id) item = self.emby.getItem(item_id)
self.add_to_xbmc_playlist(playlist, item) self.add_to_xbmc_playlist(playlist, item)
else: # Add to playlist else: # Add to playlist
self.add_to_playlist(db_id, media_type) self.add_to_playlist(db_id, media_type)
self.verify_playlist() self.verify_playlist()
return playlist return playlist