Move get Kodi_id from filename to function

This commit is contained in:
tomkat83 2016-12-29 11:22:02 +01:00
parent eec2c10cb4
commit ee86f58a3f
2 changed files with 27 additions and 15 deletions

View file

@ -1397,3 +1397,26 @@ class Kodidb_Functions():
query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)" query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)"
self.cursor.execute(query, (genreid, kodiid)) self.cursor.execute(query, (genreid, kodiid))
def get_kodiid_from_filename(file):
"""
Returns the tuple (kodiid, type) if we have a video in the database with
said filename, or (None, None)
"""
kodiid = None
typus = None
try:
filename = file.rsplit('/', 1)[1]
path = file.rsplit('/', 1)[0] + '/'
except IndexError:
filename = file.rsplit('\\', 1)[1]
path = file.rsplit('\\', 1)[0] + '\\'
log.debug('Trying to figure out playing item from filename: %s '
'and path: %s' % (filename, path))
with GetKodiDB('video') as kodi_db:
try:
kodiid, typus = kodi_db.getIdFromFilename(filename, path)
except TypeError:
log.info('No kodi video element found with filename %s' % filename)
return (kodiid, typus)

View file

@ -10,10 +10,10 @@ import xbmcgui
import downloadutils import downloadutils
import embydb_functions as embydb import embydb_functions as embydb
import kodidb_functions as kodidb
import playbackutils as pbutils import playbackutils as pbutils
from utils import window, settings, CatchExceptions, tryDecode, tryEncode from utils import window, settings, CatchExceptions, tryDecode, tryEncode
from PlexFunctions import scrobble, REMAP_TYPE_FROM_PLEXTYPE from PlexFunctions import scrobble, REMAP_TYPE_FROM_PLEXTYPE
from kodidb_functions import get_kodiid_from_filename
############################################################################### ###############################################################################
@ -227,20 +227,9 @@ class KodiMonitor(xbmc.Monitor):
# When using Widgets, Kodi doesn't tell us shit so we need this hack # When using Widgets, Kodi doesn't tell us shit so we need this hack
if (kodiid is None and plexid is None and typus != 'song' if (kodiid is None and plexid is None and typus != 'song'
and not currentFile.startswith('http')): and not currentFile.startswith('http')):
try: (kodiid, typus) = get_kodiid_from_filename(currentFile)
filename = currentFile.rsplit('/', 1)[1] if kodiid is None:
path = currentFile.rsplit('/', 1)[0] + '/' return
except IndexError:
filename = currentFile.rsplit('\\', 1)[1]
path = currentFile.rsplit('\\', 1)[0] + '\\'
log.debug('Trying to figure out playing item from filename: %s '
'and path: %s' % (filename, path))
with kodidb.GetKodiDB('video') as kodi_db:
try:
kodiid, typus = kodi_db.getIdFromFilename(filename, path)
except TypeError:
log.info('Abort playback report, could not id kodi item')
return
if plexid is None: if plexid is None:
# Get Plex' item id # Get Plex' item id