jellyfin-kodi/default.py

191 lines
6.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
#################################################################################################
import logging
import os
import sys
import urlparse
2015-05-03 15:39:12 +00:00
import xbmc
import xbmcaddon
2018-03-12 06:58:48 +00:00
import xbmcplugin
#################################################################################################
2016-09-09 03:13:25 +00:00
_ADDON = xbmcaddon.Addon(id='plugin.video.emby')
_CWD = _ADDON.getAddonInfo('path').decode('utf-8')
_BASE_LIB = xbmc.translatePath(os.path.join(_CWD, 'resources', 'lib')).decode('utf-8')
sys.path.append(_BASE_LIB)
#################################################################################################
import entrypoint
2016-09-09 03:13:25 +00:00
import loghandler
from utils import window, dialog, language as lang
2018-05-13 03:56:53 +00:00
#from ga_client import GoogleAnalytics
import database
#################################################################################################
loghandler.config()
log = logging.getLogger("EMBY.default")
#################################################################################################
2016-09-09 03:13:25 +00:00
class Main(object):
# MAIN ENTRY POINT
2016-06-19 21:24:34 +00:00
#@utils.profiling()
2016-09-09 03:13:25 +00:00
def __init__(self):
# Parse parameters
base_url = sys.argv[0]
2016-09-09 03:13:25 +00:00
path = sys.argv[2]
params = urlparse.parse_qs(path[1:])
log.warn("Parameter string: %s params: %s", path, params)
try:
mode = params['mode'][0]
2016-09-09 03:13:25 +00:00
except (IndexError, KeyError):
mode = ""
2016-09-09 03:13:25 +00:00
if "/extrafanart" in base_url:
emby_path = path[1:]
emby_id = params.get('id', [""])[0]
entrypoint.getExtraFanArt(emby_id, emby_path)
elif "/Extras" in base_url or "/VideoFiles" in base_url:
emby_path = path[1:]
emby_id = params.get('id', [""])[0]
entrypoint.getVideoFiles(emby_id, emby_path)
elif not self._modes(mode, params):
# Other functions
if mode == 'settings':
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.emby)')
2017-11-03 03:34:41 +00:00
elif mode in ('manualsync', 'fastsync', 'repair', 'refreshboxsets'):
2016-09-09 03:13:25 +00:00
self._library_sync(mode)
2016-09-09 03:13:25 +00:00
elif mode == 'texturecache':
import artwork
2016-09-10 11:15:58 +00:00
artwork.Artwork().texture_cache_sync()
2016-09-09 03:13:25 +00:00
else:
entrypoint.doMainListing()
2018-03-12 06:58:48 +00:00
if sys.argv:
2017-11-03 03:34:41 +00:00
xbmcplugin.endOfDirectory(int(sys.argv[1]))
2016-09-09 03:13:25 +00:00
@classmethod
def _modes(cls, mode, params):
import utils
modes = {
'reset': database.db_reset,
'resetauth': entrypoint.resetAuth,
'play': entrypoint.doPlayback,
'passwords': utils.passwordsXML,
'adduser': entrypoint.addUser,
'thememedia': entrypoint.getThemeMedia,
'channels': entrypoint.BrowseChannels,
'channelsfolder': entrypoint.BrowseChannels,
'browsecontent': entrypoint.BrowseContent,
2016-01-22 10:10:42 +00:00
'getsubfolders': entrypoint.GetSubFolders,
'nextup': entrypoint.getNextUpEpisodes,
'inprogressepisodes': entrypoint.getInProgressEpisodes,
'recentepisodes': entrypoint.getRecentEpisodes,
2016-02-29 05:20:59 +00:00
'refreshplaylist': entrypoint.refreshPlaylist,
2018-05-10 23:21:08 +00:00
#'deviceid': entrypoint.resetDeviceId,
'delete': entrypoint.deleteItem,
2016-09-18 07:53:52 +00:00
'connect': entrypoint.emby_connect,
'backup': entrypoint.emby_backup,
'manuallogin': entrypoint.test_manual_login,
'connectlogin': entrypoint.test_connect_login,
'manualserver': entrypoint.test_manual_server,
'connectservers': entrypoint.test_connect_servers,
'connectusers': entrypoint.test_connect_users
}
2016-09-09 03:13:25 +00:00
if mode in modes:
# Simple functions
2016-09-09 03:13:25 +00:00
action = modes[mode]
item_id = params.get('id')
if item_id:
item_id = item_id[0]
if mode == 'play':
database_id = params.get('dbid')
action(item_id, database_id)
elif mode == 'recentepisodes':
limit = int(params['limit'][0])
action(item_id, limit, params.get('filters', [""])[0])
elif mode in ('nextup', 'inprogressepisodes'):
limit = int(params['limit'][0])
2016-09-09 03:13:25 +00:00
action(item_id, limit)
elif mode in ('channels', 'getsubfolders'):
action(item_id)
elif mode == 'browsecontent':
action(item_id, params.get('type', [""])[0], params.get('folderid', [""])[0])
elif mode == 'channelsfolder':
folderid = params['folderid'][0]
2016-09-09 03:13:25 +00:00
action(item_id, folderid)
else:
2016-09-09 03:13:25 +00:00
action()
return True
return False
@classmethod
def _library_sync(cls, mode):
if window('emby_online') != "true":
# Server is not online, do not run the sync
dialog(type_="ok",
heading="{emby}",
line1=lang(33034))
2016-09-10 11:15:58 +00:00
log.warn("Not connected to the emby server")
2016-09-09 03:13:25 +00:00
elif window('emby_dbScan') != "true":
import librarysync
library_sync = librarysync.LibrarySync()
if mode == 'manualsync':
librarysync.ManualSync().sync()
elif mode == 'fastsync':
library_sync.startSync()
2017-11-03 03:34:41 +00:00
elif mode == 'refreshboxsets':
librarysync.ManualSync().sync('boxsets')
else:
2016-09-09 03:13:25 +00:00
library_sync.fullSync(repair=True)
else:
2016-09-10 11:15:58 +00:00
log.warn("Database scan is already running")
2016-09-09 03:13:25 +00:00
2016-06-19 21:24:34 +00:00
if __name__ == "__main__":
2016-09-09 03:13:25 +00:00
log.info("plugin.video.emby started")
2016-10-10 11:14:10 +00:00
try:
Main()
except Exception as error:
2018-05-13 03:56:53 +00:00
"""
if not (hasattr(error, 'quiet') and error.quiet):
ga = GoogleAnalytics()
errStrings = ga.formatException()
ga.sendEventData("Exception", errStrings[0], errStrings[1])
2018-05-13 03:56:53 +00:00
"""
log.exception(error)
raise
2016-10-10 11:14:10 +00:00
2016-09-09 03:13:25 +00:00
log.info("plugin.video.emby stopped")