Move get Kodi_id from filename to function
This commit is contained in:
parent
eec2c10cb4
commit
ee86f58a3f
2 changed files with 27 additions and 15 deletions
|
@ -1397,3 +1397,26 @@ class Kodidb_Functions():
|
|||
|
||||
query = "INSERT OR REPLACE INTO song_genre(idGenre, idSong) values(?, ?)"
|
||||
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)
|
||||
|
|
|
@ -10,10 +10,10 @@ import xbmcgui
|
|||
|
||||
import downloadutils
|
||||
import embydb_functions as embydb
|
||||
import kodidb_functions as kodidb
|
||||
import playbackutils as pbutils
|
||||
from utils import window, settings, CatchExceptions, tryDecode, tryEncode
|
||||
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
|
||||
if (kodiid is None and plexid is None and typus != 'song'
|
||||
and not currentFile.startswith('http')):
|
||||
try:
|
||||
filename = currentFile.rsplit('/', 1)[1]
|
||||
path = currentFile.rsplit('/', 1)[0] + '/'
|
||||
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
|
||||
(kodiid, typus) = get_kodiid_from_filename(currentFile)
|
||||
if kodiid is None:
|
||||
return
|
||||
|
||||
if plexid is None:
|
||||
# Get Plex' item id
|
||||
|
|
Loading…
Reference in a new issue