forked from alladdin/plugin.video.primaplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.py
223 lines (192 loc) · 8.31 KB
/
default.py
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# -*- coding: utf-8 -*-
import os
import sys
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import traceback
from xbmcplugin import addDirectoryItem
from libPrimaPlay import PrimaPlay
import urllib
from urlparse import parse_qs
_addon_ = xbmcaddon.Addon('plugin.video.primaplay')
_scriptname_ = _addon_.getAddonInfo('name')
_version_ = _addon_.getAddonInfo('version')
###############################################################################
def log(msg, level=xbmc.LOGDEBUG):
if type(msg).__name__ == 'unicode':
msg = msg.encode('utf-8')
xbmc.log("[%s] %s" % (_scriptname_, msg.__str__()), level)
def logDbg(msg):
log(msg, level=xbmc.LOGDEBUG)
def logErr(msg):
log(msg, level=xbmc.LOGERROR)
def _exception_log(exc_type, exc_value, exc_traceback):
logErr(traceback.format_exception(exc_type, exc_value, exc_traceback))
xbmcgui.Dialog().notification(_scriptname_, _toString(exc_value), xbmcgui.NOTIFICATION_ERROR)
def _toString(text):
if type(text).__name__ == 'unicode':
output = text.encode('utf-8')
else:
output = str(text)
return output
try:
_icon_ = xbmc.translatePath(os.path.join(_addon_.getAddonInfo('path'), 'icon.png'))
_handle_ = int(sys.argv[1])
_baseurl_ = sys.argv[0]
_hd_enabled = False;
if (_addon_.getSetting('hd_enabled') == 'true'): _hd_enabled = True
_play_parser = PrimaPlay.Parser(hd_enabled=_hd_enabled)
_play_account = None
if (_addon_.getSetting('account_enabled') == 'true'):
_play_account = PrimaPlay.Account( _addon_.getSetting('account_email'), _addon_.getSetting('account_password'), _play_parser )
xbmcplugin.setContent(_handle_, 'tvshows')
def main_menu(pageurl, list_only = False):
page = _play_parser.get_page(pageurl)
if not list_only:
if page.player:
add_player(page.player)
else:
add_search_menu()
add_account_menu()
add_filters(page, pageurl)
for video_list in page.video_lists:
if video_list.title: add_title(video_list)
add_item_list(video_list.item_list)
if video_list.next_link: add_next_link(video_list.next_link)
def next_menu(nexturl):
next_list = _play_parser.get_next_list(nexturl)
add_item_list(next_list.list)
if next_list.next_link: add_next_link(next_list.next_link)
def search():
keyboard = xbmc.Keyboard('',u'Hledej')
keyboard.doModal()
if (not keyboard.isConfirmed()): return
search_query = keyboard.getText()
if len(search_query) <= 1: return
main_menu(_play_parser.get_search_url(search_query))
def account():
if not _play_account.login():
li = list_item('[B]Chyba přihlášení![/B] Zkontrolujte e-mail a heslo.')
xbmcplugin.addDirectoryItem(handle=_handle_, url='#', listitem=li, isFolder=True)
return
main_menu(_play_account.video_list_url, True)
def remove_filter(removefilterurl):
link = _play_parser.get_redirect_from_remove_link(removefilterurl)
main_menu(link)
def manage_filter(pageurl, filterid):
if filterid is None:
main_menu(pageurl)
return
page = _play_parser.get_page(pageurl)
dlg = xbmcgui.Dialog()
filter_list = page.filter_lists[filterid]
add_id = dlg.select(filter_list.title, map(lambda x: x.title, filter_list.item_list))
if add_id < 0:
main_menu(pageurl)
return
main_menu(filter_list.item_list[add_id].link)
def add_filters(page, pageurl):
if page.current_filters:
li = list_item(u'[B]Odstranit nastavené filtry: [/B]' + ", ".join(map(lambda x: x.title, page.current_filters.item_list)))
url = get_menu_link( action = 'FILTER-REMOVE', linkurl = page.current_filters.link )
xbmcplugin.addDirectoryItem(handle=_handle_, url=url, listitem=li, isFolder=True)
for filterid, filter_list in enumerate(page.filter_lists):
li = list_item(u'[B]Nastav filtr: [/B]' + filter_list.title)
url = get_menu_link( action = 'FILTER-MANAGE', linkurl = pageurl, filterid = filterid )
xbmcplugin.addDirectoryItem(handle=_handle_, url=url, listitem=li, isFolder=True)
def add_search_menu():
li = list_item(u'[B]Hledej[/B]')
url = get_menu_link( action = 'SEARCH' )
xbmcplugin.addDirectoryItem(handle=_handle_, url=url, listitem=li, isFolder=True)
def add_account_menu():
if _play_account is None: return
li = list_item(u'[B]Můj PLAY[/B]')
url = get_menu_link( action = 'ACCOUNT' )
xbmcplugin.addDirectoryItem(handle=_handle_, url=url, listitem=li, isFolder=True)
def add_title(video_list):
li = list_item('[B]'+video_list.title+'[/B]')
url = '#'
if video_list.link:
url = get_menu_link( action = 'PAGE', linkurl = video_list.link )
xbmcplugin.addDirectoryItem(handle=_handle_, url=url, listitem=li, isFolder=True)
def add_item_list(item_list):
for item in item_list:
li = list_item(item.title, item.image_url, item.description, item.broadcast_date, item.year)
url = get_menu_link( action = 'PAGE', linkurl = item.link )
xbmcplugin.addDirectoryItem(handle=_handle_, url=url, listitem=li, isFolder=True)
def add_next_link(next_link):
li = list_item(u'Další stránka')
url = get_menu_link( action = 'PAGE-NEXT', linkurl = next_link )
xbmcplugin.addDirectoryItem(handle=_handle_, url=url, listitem=li, isFolder=True)
def add_player(player):
li = list_item(u"[B]Přehraj:[/B] "+player.title, player.image_url, player.description, player.broadcast_date, player.year)
xbmcplugin.addDirectoryItem(handle=_handle_, url=player.video_link, listitem=li, isFolder=False)
def list_item(label, thumbnail = None, description = None, broadcast_date = None, year = None):
li = xbmcgui.ListItem(label)
liVideo = {
'title': label,
'plot': description,
'year': year,
'aired': broadcast_date
}
if thumbnail:
li.setThumbnailImage(thumbnail)
li.setArt({'poster': thumbnail, 'fanart': thumbnail})
li.setInfo("video", liVideo)
return li
def get_menu_link(**kwargs):
return _baseurl_ + "?" + urllib.urlencode(kwargs)
def get_params():
if len(sys.argv[2])<2: return []
encoded_query = sys.argv[2].lstrip('?')
decoded_params = parse_qs(encoded_query)
param = {}
for key in decoded_params:
if len(decoded_params[key]) <= 0: continue
param[key] = decoded_params[key][0]
return param
def assign_params(params):
for param in params:
try:
globals()[param] = params[param]
except:
pass
action = None
linkurl = None
filterid = None
params = get_params()
assign_params(params)
logDbg("PrimaPlay Parameters!!!")
logDbg("action: "+str(action))
logDbg("linkurl: "+str(linkurl))
logDbg("filterid: "+str(filterid))
try:
if action == "FILTER-REMOVE":
remove_filter(linkurl)
xbmcplugin.endOfDirectory(_handle_, updateListing=True)
if action == "FILTER-MANAGE":
manage_filter(linkurl, int(filterid))
xbmcplugin.endOfDirectory(_handle_, updateListing=True)
elif action == "PAGE-NEXT":
next_menu(linkurl)
xbmcplugin.endOfDirectory(_handle_, updateListing=True)
elif action == "SEARCH":
search()
xbmcplugin.endOfDirectory(_handle_)
elif action == "ACCOUNT":
account()
xbmcplugin.endOfDirectory(_handle_)
elif action == "PAGE":
main_menu(linkurl)
xbmcplugin.endOfDirectory(_handle_)
else:
main_menu("http://play.iprima.cz")
xbmcplugin.endOfDirectory(_handle_)
except Exception as ex:
exc_type, exc_value, exc_traceback = sys.exc_info()
_exception_log(exc_type, exc_value, exc_traceback)
except Exception as ex:
exc_type, exc_value, exc_traceback = sys.exc_info()
_exception_log(exc_type, exc_value, exc_traceback)