-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayvideo.py
More file actions
69 lines (54 loc) · 1.9 KB
/
playvideo.py
File metadata and controls
69 lines (54 loc) · 1.9 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
import urlparse
import sys,urllib
import xbmc, xbmcgui, xbmcaddon, xbmcplugin
import resolveurl as urlresolver
from bs4 import BeautifulSoup
import re
import resources.lib.meczreplay
#import web_pdb; web_pdb.set_trace()
base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])
_addon = xbmcaddon.Addon()
_icon = _addon.getAddonInfo('icon')
def build_url(query):
return base_url + '?' + urllib.urlencode(query)
def resolve_url(url):
duration=7500 #in milliseconds
message = "Cannot Play URL"
stream_url = urlresolver.HostedMediaFile(url=url).resolve()
# If urlresolver returns false then the video url was not resolved.
if not stream_url:
dialog = xbmcgui.Dialog()
dialog.notification("URL Resolver Error", message, xbmcgui.NOTIFICATION_INFO, duration)
return False
else:
return stream_url
def play_video(path):
"""
Play a video by the provided path.
:param path: str
"""
# Create a playable item with a path to play.
play_item = xbmcgui.ListItem(path=path)
vid_url = play_item.getfilename()
stream_url = resolve_url(vid_url)
if stream_url:
play_item.setPath(stream_url)
# Pass the item to the Kodi player.
xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)
# addon kicks in
mode = args.get('mode', None)
if mode is None:
parser = resources.lib.meczreplay.webParser()
data = parser.getData()
for i in data:
video_play_url = i.videoLink
url = build_url({'mode' :'play', 'playlink' : video_play_url})
li = xbmcgui.ListItem(i.name, iconImage=i.imgLink)
li.setProperty('IsPlayable' , 'true')
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
xbmcplugin.endOfDirectory(addon_handle)
elif mode[0] == 'play':
final_link = args['playlink'][0]
play_video(final_link)