mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-01-24 17:06:11 +00:00
Change DatabaseConn to return the cursor instead
This commit is contained in:
parent
13e4ff5128
commit
6d0b2b96bc
8 changed files with 218 additions and 244 deletions
|
@ -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,8 +165,7 @@ 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()
|
||||||
|
@ -189,8 +187,7 @@ class Artwork(object):
|
||||||
|
|
||||||
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()
|
||||||
|
@ -230,8 +227,7 @@ 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:
|
||||||
|
@ -431,8 +427,7 @@ 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:
|
try:
|
||||||
cursor_texture.execute("SELECT cachedurl FROM texture WHERE url = ?", (url,))
|
cursor_texture.execute("SELECT cachedurl FROM texture WHERE url = ?", (url,))
|
||||||
cached_url = cursor_texture.fetchone()[0]
|
cached_url = cursor_texture.fetchone()[0]
|
||||||
|
@ -453,7 +448,6 @@ class Artwork(object):
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
log.debug("Issue deleting url from cache. Skipping.")
|
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
|
||||||
for person in people:
|
for person in people:
|
||||||
|
|
|
@ -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,8 +88,7 @@ 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:
|
||||||
|
@ -165,8 +163,7 @@ 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:
|
||||||
|
|
|
@ -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,8 +157,7 @@ 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:
|
||||||
|
@ -167,8 +167,7 @@ def db_reset():
|
||||||
|
|
||||||
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"')
|
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:
|
||||||
|
@ -178,8 +177,7 @@ def db_reset():
|
||||||
|
|
||||||
# Wipe the emby database
|
# Wipe the emby database
|
||||||
log.warn("Resetting the Emby database.")
|
log.warn("Resetting the Emby database.")
|
||||||
with DatabaseConn('emby') as conn:
|
with DatabaseConn('emby') 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:
|
||||||
|
|
|
@ -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,8 +234,7 @@ 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)
|
||||||
|
|
||||||
|
@ -422,8 +420,7 @@ 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()
|
||||||
|
|
||||||
|
|
|
@ -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,8 +61,7 @@ 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:
|
||||||
|
|
||||||
|
|
|
@ -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,8 +166,7 @@ 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)
|
||||||
|
|
||||||
|
|
|
@ -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,8 +331,7 @@ 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())
|
||||||
|
|
||||||
|
@ -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,8 +608,7 @@ 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(
|
||||||
|
@ -669,9 +666,7 @@ 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)
|
emby_db = embydb.Embydb_Functions(cursor)
|
||||||
currentVersion = emby_db.get_version()
|
currentVersion = emby_db.get_version()
|
||||||
###$ Begin migration $###
|
###$ Begin migration $###
|
||||||
|
|
|
@ -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,8 +30,7 @@ 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()
|
||||||
|
@ -74,8 +72,7 @@ class Playlist(object):
|
||||||
|
|
||||||
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 ***---")
|
||||||
|
|
Loading…
Reference in a new issue