-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddon.py
99 lines (77 loc) · 3.96 KB
/
addon.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
import sys
import xbmc
import xbmcgui
import xbmcplugin
import requests
import re
import urllib
from lxml import html
from urlparse import parse_qsl
from datetime import date, timedelta
# https://forum.kodi.tv/showthread.php?tid=324570
_pid = sys.argv[0]
_handle = int(sys.argv[1])
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Mobile Safari/537.36',
}
def list_categories():
xbmcplugin.setPluginCategory(_handle, 'LA7')
xbmcplugin.setContent(_handle, 'videos')
listitem = xbmcgui.ListItem(label='Refresh List')
listitem.setInfo('video', {'title': 'Refresh List', 'mediatype': 'video'})
xbmcplugin.addDirectoryItem(handle=_handle, url=_pid, listitem=listitem, isFolder=True)
listitem = xbmcgui.ListItem(label="Live")
listitem.setInfo('video', {'title': 'Live', 'mediatype': 'video'})
listitem.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem(handle=_handle, url='{0}?action=get_play&video={1}&rex={2}'.format(_pid, urllib.quote('https://www.la7.it/dirette-tv'), urllib.quote("vS = '(.*?)'")), listitem=listitem, isFolder=False)
for daysago in range(7):
ddd = (date.today() - timedelta(daysago)).strftime('%A %d %B %Y')
listitem = xbmcgui.ListItem(label=ddd)
listitem.setInfo('video', {'title': ddd, 'mediatype': 'video'})
xbmcplugin.addDirectoryItem(handle=_handle, url='{0}?action=listing&daysago={1}'.format(_pid, daysago), listitem=listitem, isFolder=True)
xbmcplugin.endOfDirectory(_handle)
def list_videos(daysago):
ddd = (date.today() - timedelta(daysago)).strftime('%A %d %B %Y')
xbmcplugin.setPluginCategory(_handle, ddd)
xbmcplugin.setContent(_handle, 'videos')
listitem = xbmcgui.ListItem(label='Refresh List')
listitem.setInfo('video', {'title': 'Refresh List', 'mediatype': 'video'})
xbmcplugin.addDirectoryItem(handle=_handle, url='{0}?action=listing&daysago={1}'.format(_pid, daysago), listitem=listitem, isFolder=True)
page = requests.get('https://www.la7.it/rivedila7/{0}/LA7'.format(daysago), headers=headers).content
tree = html.fromstring(page)
for item in tree.xpath('//div[@class="palinsesto_row disponibile clearfix"]'):
href = item.xpath('.//div[@class="titolo clearfix"]/a')[0].get('href');
if not href.startswith('http'):
href = 'https://www.la7.it{0}'.format(href)
image = item.xpath('.//a[@class="thumbVideo"]//img')[0]
time = item.xpath('.//div[@class="orario"]')[0].text.encode('utf-8').strip()
title = '[{0}] {1}'.format(time, image.get('title').encode('utf-8').strip())
desc = item.xpath('.//div[@class="descrizione"]/p')[0].text.encode('utf-8').strip()
listitem = xbmcgui.ListItem(label=title)
listitem.setInfo('video', {'title': title, 'plot': desc, 'mediatype': 'video'})
listitem.setArt({'thumb': image.get('src').encode('utf-8').strip()})
listitem.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem(handle=_handle, url='{0}?action=get_play&video={1}&rex={2}'.format(_pid, urllib.quote(href), urllib.quote('"(http.*?\.m3u8)"')), listitem=listitem, isFolder=False)
xbmcplugin.endOfDirectory(_handle)
def get_and_play_video(path, rex):
page = requests.get(path, headers=headers).content
if re.findall(rex, page):
url = re.findall(rex, page)[0].encode('utf-8').strip()
if url.startswith('//'):
url = 'https:{0}'.format(url)
xbmc.log("play {0}".format(url), xbmc.LOGNOTICE)
xbmcplugin.setResolvedUrl(_handle, True, listitem=xbmcgui.ListItem(path=url))
else:
xbmcgui.Dialog().ok(_pid, "Impossibile trovare uno stream nel programma richiesto")
xbmc.log(" ".join(sys.argv), xbmc.LOGNOTICE)
def router(paramstring):
params = dict(parse_qsl(paramstring))
if params:
if params['action'] == 'listing':
list_videos(int(params['daysago']))
elif params['action'] == 'get_play':
get_and_play_video(params['video'], params['rex'])
else:
list_categories()
if __name__ == '__main__':
router(sys.argv[2][1:])