-
Notifications
You must be signed in to change notification settings - Fork 0
/
addon.py
84 lines (67 loc) · 2.88 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
from builtins import str
import sys
import urllib.request, urllib.parse, urllib.error
import urllib.parse
import xbmcgui
import xbmcplugin
import xbmcaddon
import requests
import resources.lib.const_localize as clo
from bs4 import BeautifulSoup
import re
def loadlist():
lp_url='https://longnow.org/membership/signin/'
headers = {'Referer': lp_url}
lp = requests.get(lp_url+'?next=/seminars/list', headers=headers)
if lp.status_code!=200:
xbmcgui.Dialog().ok(my_addon.getLocalizedString(clo.ERR_NO_LOGIN),
my_addon.getLocalizedString(clo.INF_HTTP_STATE) % lp.status_code)
return
loginSoup=BeautifulSoup(lp.text, "html.parser")
token=loginSoup.find("input", {"name":"csrfmiddlewaretoken"})
username=my_addon.getSetting('username')
password=my_addon.getSetting('password')
if (username is None) or (username==""):
xbmcgui.Dialog().ok(my_addon.getLocalizedString(clo.ERR_INV_USER),
my_addon.getLocalizedString(clo.HELP_INV_USER))
if (password is None) or (password==""):
xbmcgui.Dialog().ok(my_addon.getLocalizedString(clo.ERR_INV_PWD),
my_addon.getLocalizedString(clo.HELP_INV_PWD))
data= {
'username': username,
'password': password,
'next': '/seminars/list',
'csrfmiddlewaretoken': token['value']
}
r = requests.post(lp_url, data=data, headers=headers,cookies=lp.cookies)
listpage=r
if listpage.status_code!=200:
xbmcgui.Dialog().ok(my_addon.getLocalizedString(clo.ERR_NO_ACCESS),
my_addon.getLocalizedString(clo.INF_HTTP_STATE) % listpage.status_code,
my_addon.getLocalizedString(clo.HELP_NO_LOGIN))
return
listSoup=BeautifulSoup(listpage.text, "html.parser")
errorblock=listSoup.find("div",{'class':'error_block'})
if errorblock is not None:
xbmcgui.Dialog().ok(my_addon.getLocalizedString(clo.ERR_NO_ACCESS),
my_addon.getLocalizedString(clo.ERR_USERNAME_CORRECT))
return
hdstring=re.compile('Full HD Video');
for dl in listSoup.findAll("ul", 'download_list'):
hdlink=dl.find('a',title=hdstring);
if hdlink is not None:
name=dl.parent.parent.find('td',{'class':'title'}).a.string
url=hdlink['href'];
li = xbmcgui.ListItem(name)
li.setArt({'iconImage':'DefaultVideo.png'})
xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urllib.parse.parse_qs(sys.argv[2][1:])
my_addon = xbmcaddon.Addon()
xbmcplugin.setContent(addon_handle, 'movies')
try:
loadlist()
except requests.exceptions.RequestException as e:
xbmcgui.Dialog().ok(my_addon.getLocalizedString(clo.ERR_NO_CONNECT), str(e))
xbmcplugin.endOfDirectory(addon_handle)