-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.py
142 lines (107 loc) · 4.4 KB
/
plugin.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
import sys
from urllib.parse import parse_qsl
import xbmcgui
import xbmcplugin
from lib import tver
from lib import Cache, Favourites, Watcher, MyList
from lib import log, show_info, check_if_kodi_supports_manifest, extract_info, extract_manifest_url_from_info, get_url, refresh, get_adaptive_type_from_url, localize, clear_thumbnails
_HANDLE = int(sys.argv[1])
def list_videos(category):
xbmcplugin.setPluginCategory(_HANDLE, category)
xbmcplugin.setContent(_HANDLE, 'videos')
videos = []
context = None
if category == 'mylist':
mylist = MyList()
mylist.build()
videos = mylist.get()
context = (localize(30020),'delist')
elif category == 'watching':
videos = Watcher().get_watching_episodes()
else:
videos = Cache().get_episodes(category)
context = (localize(30021),'mylist')
for video in videos:
label = video['name']
list_item = xbmcgui.ListItem(label=label)
vid_info = list_item.getVideoInfoTag()
vid_info.setTitle(label)
vid_info.setGenres([video['genre']])
vid_info.setTvShowTitle(video['series'])
vid_info.setMediaType('video')
list_item.setArt({'thumb': video['thumb'], 'icon': video['thumb'], 'fanart': video['thumb']})
list_item.setProperty('IsPlayable', 'true')
if context:
context_menu_item = (context[0], 'RunPlugin({})'.format(get_url(action=context[1], series=video['series'], category=video['genre'], series_title=video['series_title'])))
list_item.addContextMenuItems([context_menu_item])
url = get_url(action='play', video=video['video'])
is_folder = False
xbmcplugin.addDirectoryItem(_HANDLE, url, list_item, is_folder)
xbmcplugin.addSortMethod(_HANDLE, xbmcplugin.SORT_METHOD_NONE)
xbmcplugin.endOfDirectory(_HANDLE)
def get_categories():
cats = tver.get_categories()
if Watcher().is_watching():
cats.insert(0,("watching", localize(30003), None))
mylist_pic = MyList().get_random_pic()
if mylist_pic:
cats.insert(0,("mylist", localize(30002), mylist_pic))
return cats
def list_categories():
xbmcplugin.setPluginCategory(_HANDLE, '...')
xbmcplugin.setContent(_HANDLE, 'videos')
categories = get_categories()
for (name, display, pic) in categories:
list_item = xbmcgui.ListItem(label=display)
list_item.setArt({'thumb': pic,
'icon': pic,
'fanart': pic})
vid_info = list_item.getVideoInfoTag()
vid_info.setTitle(display)
vid_info.setGenres([name])
vid_info.setMediaType('video')
url = get_url(action='listing', category=name)
is_folder = True
xbmcplugin.addDirectoryItem(_HANDLE, url, list_item, is_folder)
xbmcplugin.addSortMethod(_HANDLE, xbmcplugin.SORT_METHOD_NONE)
xbmcplugin.endOfDirectory(_HANDLE)
def play_video(video):
info = extract_info(video)
url = extract_manifest_url_from_info(info)
adaptive_type = False
if url:
adaptive_type = get_adaptive_type_from_url(url)
if not url or not check_if_kodi_supports_manifest(adaptive_type):
err_msg = localize(33000)
log(err_msg)
show_info(err_msg)
raise Exception(err_msg)
list_item = xbmcgui.ListItem(info['title'], path=url)
list_item.setProperty("IsPlayable","true")
if adaptive_type:
list_item.setProperty('inputstream', 'inputstream.adaptive')
list_item.setProperty('inputstream.adaptive.manifest_type', adaptive_type)
xbmcplugin.setResolvedUrl(_HANDLE, True, listitem=list_item)
def router(paramstring):
params = dict(parse_qsl(paramstring))
if params:
action = params['action']
if action == 'listing':
list_videos(params['category'])
elif action == 'play':
play_video(params['video'])
elif action == 'mylist':
MyList().add(params['category'], params['series'], params['series_title'])
elif action == 'delist':
MyList().remove(params['series'])
refresh()
elif action == 'thumbnails':
clear_thumbnails()
elif action == 'favourites':
Favourites().list()
else:
raise ValueError('Invalid paramstring: {}!'.format(paramstring))
else:
list_categories()
if __name__ == '__main__':
router(sys.argv[2][1:])