forked from MediaBrowser/plugin.video.emby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.py
More file actions
190 lines (147 loc) · 5.95 KB
/
default.py
File metadata and controls
190 lines (147 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# -*- coding: utf-8 -*-
#################################################################################################
import logging
import os
import sys
import urlparse
import xbmc
import xbmcaddon
import xbmcplugin
#################################################################################################
_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
import loghandler
from utils import window, dialog, language as lang
#from ga_client import GoogleAnalytics
import database
#################################################################################################
loghandler.config()
log = logging.getLogger("EMBY.default")
#################################################################################################
class Main(object):
# MAIN ENTRY POINT
#@utils.profiling()
def __init__(self):
# Parse parameters
base_url = sys.argv[0]
path = sys.argv[2]
params = urlparse.parse_qs(path[1:])
log.warn("Parameter string: %s params: %s", path, params)
try:
mode = params['mode'][0]
except (IndexError, KeyError):
mode = ""
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)')
elif mode in ('manualsync', 'fastsync', 'repair', 'refreshboxsets'):
self._library_sync(mode)
elif mode == 'texturecache':
import artwork
artwork.Artwork().texture_cache_sync()
else:
entrypoint.doMainListing()
if sys.argv:
xbmcplugin.endOfDirectory(int(sys.argv[1]))
@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,
'getsubfolders': entrypoint.GetSubFolders,
'nextup': entrypoint.getNextUpEpisodes,
'inprogressepisodes': entrypoint.getInProgressEpisodes,
'recentepisodes': entrypoint.getRecentEpisodes,
'refreshplaylist': entrypoint.refreshPlaylist,
'deviceid': entrypoint.resetDeviceId,
'delete': entrypoint.deleteItem,
'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
}
if mode in modes:
# Simple functions
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])
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]
action(item_id, folderid)
else:
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))
log.warn("Not connected to the emby server")
elif window('emby_dbScan') != "true":
import librarysync
library_sync = librarysync.LibrarySync()
if mode == 'manualsync':
librarysync.ManualSync().sync()
elif mode == 'fastsync':
library_sync.startSync()
elif mode == 'refreshboxsets':
librarysync.ManualSync().sync('boxsets')
else:
library_sync.fullSync(repair=True)
else:
log.warn("Database scan is already running")
if __name__ == "__main__":
log.info("plugin.video.emby started")
try:
Main()
except Exception as error:
"""
if not (hasattr(error, 'quiet') and error.quiet):
ga = GoogleAnalytics()
errStrings = ga.formatException()
ga.sendEventData("Exception", errStrings[0], errStrings[1])
"""
log.exception(error)
raise
log.info("plugin.video.emby stopped")