mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
refactor the downloadutils a little
move emby DB verify to the database class and run it for the first time an emby db con is created refactor the play class playback started function a little
This commit is contained in:
parent
7a9e29c9b7
commit
0cf8f07daf
6 changed files with 181 additions and 171 deletions
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<addon id="plugin.video.emby"
|
||||
name="Emby"
|
||||
version="2.3.13"
|
||||
version="2.3.14"
|
||||
provider-name="Emby.media">
|
||||
<requires>
|
||||
<import addon="xbmc.python" version="2.19.0"/>
|
||||
|
|
|
@ -98,6 +98,11 @@ class DatabaseConn(object):
|
|||
|
||||
log.info("opened: %s - %s", self.path, id(self.conn))
|
||||
self.cursor = self.conn.cursor()
|
||||
|
||||
if self.db_file == "emby":
|
||||
verify_emby_database(self.cursor)
|
||||
self.conn.commit()
|
||||
|
||||
return self.cursor
|
||||
|
||||
def _SQL(self, media_type):
|
||||
|
@ -130,6 +135,23 @@ class DatabaseConn(object):
|
|||
self.conn.close()
|
||||
|
||||
|
||||
def verify_emby_database(cursor):
|
||||
# Create the tables for the emby database
|
||||
# emby, view, version
|
||||
|
||||
if window('emby_db_checked') != "true":
|
||||
log.info("Verifying emby DB")
|
||||
cursor.execute(
|
||||
"""CREATE TABLE IF NOT EXISTS emby(
|
||||
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,
|
||||
checksum INTEGER)""")
|
||||
cursor.execute(
|
||||
"""CREATE TABLE IF NOT EXISTS view(
|
||||
view_id TEXT UNIQUE, view_name TEXT, media_type TEXT, kodi_tagid INTEGER)""")
|
||||
cursor.execute("CREATE TABLE IF NOT EXISTS version(idVersion TEXT)")
|
||||
window('emby_db_checked', value="true")
|
||||
|
||||
def db_reset():
|
||||
|
||||
dialog = xbmcgui.Dialog()
|
||||
|
|
|
@ -209,7 +209,6 @@ class DownloadUtils(object):
|
|||
log.debug("===== ENTER downloadUrl =====")
|
||||
|
||||
kwargs = {}
|
||||
default_link = ""
|
||||
|
||||
try:
|
||||
# Ensure server info is loaded
|
||||
|
@ -247,18 +246,17 @@ class DownloadUtils(object):
|
|||
log.debug("====== 204 Success ======")
|
||||
# Read response to release connection
|
||||
response.content
|
||||
if action_type == "GET":
|
||||
raise Warning("Response Code 204: No Content for GET request")
|
||||
else:
|
||||
return None
|
||||
|
||||
elif response.status_code == requests.codes.ok:
|
||||
try:
|
||||
# UNICODE - JSON object
|
||||
response = response.json()
|
||||
json_data = response.json()
|
||||
log.debug("====== 200 Success ======")
|
||||
log.debug("Response: %s", response)
|
||||
return response
|
||||
|
||||
except Exception:
|
||||
if response.headers.get('content-type') != "text/html":
|
||||
log.info("Unable to convert the response for: %s", url)
|
||||
log.debug("Response: %s", json_data)
|
||||
return json_data
|
||||
|
||||
else: # Bad status code
|
||||
log.error("=== Bad status response: %s ===", response.status_code)
|
||||
|
@ -282,7 +280,7 @@ class DownloadUtils(object):
|
|||
|
||||
if response.status_code == 400:
|
||||
log.error("Malformed request: %s", error)
|
||||
raise Warning('400')
|
||||
raise Warning('400:' + str(error))
|
||||
|
||||
if response.status_code == 401:
|
||||
# Unauthorized
|
||||
|
@ -312,12 +310,13 @@ class DownloadUtils(object):
|
|||
xbmcgui.Dialog().notification(heading="Error connecting",
|
||||
message="Unauthorized.",
|
||||
icon=xbmcgui.NOTIFICATION_ERROR)
|
||||
raise Warning('401')
|
||||
raise Warning('401:' + str(error))
|
||||
|
||||
except requests.exceptions.RequestException as error:
|
||||
log.error("unknown error connecting to: %s", url)
|
||||
|
||||
return default_link
|
||||
# something went wrong so return a None as we have no valid data
|
||||
return None
|
||||
|
||||
def _ensure_server(self, server_id=None):
|
||||
|
||||
|
|
|
@ -606,20 +606,6 @@ class LibrarySync(threading.Thread):
|
|||
# Database out of date.
|
||||
return False
|
||||
|
||||
def _verify_emby_database(self):
|
||||
# Create the tables for the emby database
|
||||
with database.DatabaseConn('emby') as cursor:
|
||||
# emby, view, version
|
||||
cursor.execute(
|
||||
"""CREATE TABLE IF NOT EXISTS emby(
|
||||
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,
|
||||
checksum INTEGER)""")
|
||||
cursor.execute(
|
||||
"""CREATE TABLE IF NOT EXISTS view(
|
||||
view_id TEXT UNIQUE, view_name TEXT, media_type TEXT, kodi_tagid INTEGER)""")
|
||||
cursor.execute("CREATE TABLE IF NOT EXISTS version(idVersion TEXT)")
|
||||
|
||||
def run(self):
|
||||
|
||||
try:
|
||||
|
|
|
@ -66,9 +66,11 @@ class Player(xbmc.Player):
|
|||
break
|
||||
else: count += 1
|
||||
|
||||
# if we did not get the current file return
|
||||
if currentFile == "":
|
||||
return
|
||||
|
||||
if currentFile:
|
||||
|
||||
# process the playing file
|
||||
self.currentFile = currentFile
|
||||
|
||||
# We may need to wait for info to be set in kodi monitor
|
||||
|
@ -101,7 +103,11 @@ class Player(xbmc.Player):
|
|||
self.xbmcplayer.seekTime(int(customseek)/10000000.0)
|
||||
window('emby_customPlaylist.seektime', clear=True)
|
||||
|
||||
try:
|
||||
seekTime = self.xbmcplayer.getTime()
|
||||
except:
|
||||
# at this point we should be playing and if not then bail out
|
||||
return
|
||||
|
||||
# Get playback volume
|
||||
volume_query = {
|
||||
|
|
|
@ -100,9 +100,6 @@ class Service(object):
|
|||
self.websocket_thread = wsc.WebSocketClient()
|
||||
self.library_thread = librarysync.LibrarySync()
|
||||
|
||||
# Verify database structure, otherwise create it.
|
||||
self.library_thread._verify_emby_database()
|
||||
|
||||
while not self.monitor.abortRequested():
|
||||
|
||||
if window('emby_kodiProfile') != kodi_profile:
|
||||
|
|
Loading…
Reference in a new issue