-
Notifications
You must be signed in to change notification settings - Fork 6
/
default.py
101 lines (82 loc) · 3.16 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
import os
import sys
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import urllib
import urlparse
from resources.lib.popcorntv import PopcornTV
# plugin constants
__plugin__ = "plugin.video.popcorntv"
__author__ = "Nightflyer"
Addon = xbmcaddon.Addon(id=__plugin__)
# plugin handle
handle = int(sys.argv[1])
# utility functions
def parameters_string_to_dict(parameters):
''' Convert parameters encoded in a URL to a dict. '''
paramDict = dict(urlparse.parse_qsl(parameters[1:]))
return paramDict
def addDirectoryItem(parameters, li):
url = sys.argv[0] + '?' + urllib.urlencode(parameters)
return xbmcplugin.addDirectoryItem(handle=handle, url=url,
listitem=li, isFolder=True)
def addLinkItem(parameters, li):
li.setProperty('IsPlayable', 'true')
url = sys.argv[0] + '?' + urllib.urlencode(parameters)
return xbmcplugin.addDirectoryItem(handle=handle, url=url,
listitem=li, isFolder=False)
# UI builder functions
def show_root_folder():
popcorntv = PopcornTV()
items = popcorntv.getCategories()
for item in items:
liStyle=xbmcgui.ListItem(item["title"])
addDirectoryItem({"mode": "folder", "url": item["url"]}, liStyle)
xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def show_category_folder(url):
xbmc.log("Category URL: " + url)
popcorntv = PopcornTV()
items = popcorntv.getSubCategories(url)
for item in items:
liStyle=xbmcgui.ListItem(item["title"])
addDirectoryItem({"mode": "list", "url": item["url"]}, liStyle)
xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_LABEL)
xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def show_video_files(url):
xbmc.log("Subcategory URL: " + url)
popcorntv = PopcornTV()
page = popcorntv.getVideoBySubCategories(url)
for video in page["videoList"]:
liStyle=xbmcgui.ListItem(video["title"])
liStyle.setArt({"thumb": video["thumb"]})
liStyle.setInfo('video', {"Plot": video["plot"]})
addLinkItem({"mode": "video", "url": video["url"]}, liStyle)
if page["prevPageUrl"] is not None:
liStyle=xbmcgui.ListItem("< Precedente")
liStyle.setArt({"icon": "DefaultFolder.png"})
addDirectoryItem({"mode": "list", "url": page["prevPageUrl"]}, liStyle)
if page["nextPageUrl"] is not None:
liStyle=xbmcgui.ListItem("> Successivo")
liStyle.setArt({"icon": "DefaultFolder.png"})
addDirectoryItem({"mode": "list", "url": page["nextPageUrl"]}, liStyle)
xbmcplugin.endOfDirectory(handle=handle, succeeded=True)
def play_video(url):
xbmc.log("Video URL: " + url)
popcorntv = PopcornTV()
metadata = popcorntv.getVideoMetadata(url)
liStyle=xbmcgui.ListItem(path=metadata["videoUrl"])
xbmcplugin.setResolvedUrl(handle=handle, succeeded=True, listitem=liStyle)
# parameter values
params = parameters_string_to_dict(sys.argv[2])
mode = str(params.get("mode", ""))
url = str(params.get("url", ""))
if mode == "":
show_root_folder()
elif mode == "folder":
show_category_folder(url)
elif mode == "list":
show_video_files(url)
elif mode == "video":
play_video(url)