Skip to content

Commit f3c79fd

Browse files
authored
Merge pull request #96 from DesSolo/hdrezka_auth
feat: Add auth
2 parents 0501615 + e73196e commit f3c79fd

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

addons/plugin.video.hdrezka.tv/addon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="plugin.video.hdrezka.tv" name="Hdrezka.tv" version="3.2.1" provider-name="MrStealth, dandy, DesSolo">
2+
<addon id="plugin.video.hdrezka.tv" name="Hdrezka.tv" version="3.2.2" provider-name="MrStealth, dandy, DesSolo">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.xbmc.helpers" version="3.0.0"/>

addons/plugin.video.hdrezka.tv/default.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# -*- coding: utf-8 -*-
33
#
44
# Writer (c) 2012-2021, MrStealth, dandy
5-
65
import os
76
import re
87
import sys
@@ -59,6 +58,13 @@ def _load_session(self):
5958
'Referer': self.domain,
6059
'User-Agent': USER_AGENT,
6160
}
61+
62+
saved_cookies = self.addon.getSetting('cookies')
63+
if saved_cookies:
64+
session.cookies = helpers.load_cookies(
65+
self.addon.getSetting('cookies')
66+
)
67+
6268
return session
6369

6470
def _load_proxy_settings(self):
@@ -577,6 +583,28 @@ def _normalize_url(self, item):
577583
item = self.url + item
578584
return item
579585

586+
def authorize(plugin):
587+
log('*** authorize')
588+
589+
login_response = plugin.make_response('POST', '/ajax/login/', data={
590+
'login_name': plugin.addon.getSetting('username'),
591+
'login_password': plugin.addon.getSetting('password'),
592+
'login_not_save': '0'
593+
})
594+
595+
data = login_response.json()
596+
if not data.get('success'):
597+
raise Exception('Authorization failed status: %s text: %s' % (login_response.status_code, login_response.text))
598+
599+
plugin.addon.setSetting('cookies', helpers.dump_cookies(login_response.cookies))
600+
601+
def main():
602+
plugin = HdrezkaTV()
603+
604+
if sys.argv[2] == 'authorize':
605+
authorize(plugin)
606+
else:
607+
plugin.main()
580608

581-
plugin = HdrezkaTV()
582-
plugin.main()
609+
if __name__ == '__main__':
610+
main()

addons/plugin.video.hdrezka.tv/helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import json
2+
3+
from requests.cookies import cookiejar_from_dict
14
import xbmc
25

36

@@ -28,6 +31,11 @@ def built_title(name, country_years, **kwargs):
2831
colored_info = f'[COLOR=55FFFFFF]{kwargs["age_limit"]} ({country_years})[/COLOR]'
2932
return f'{name} {colored_rating} {colored_info}'
3033

34+
def dump_cookies(cookies):
35+
return json.dumps(dict(cookies))
36+
37+
def load_cookies(src):
38+
return cookiejar_from_dict(json.loads(src))
3139

3240
def log(msg, level=xbmc.LOGINFO):
3341
xbmc.log(f'hdrezka: {msg}', level)

addons/plugin.video.hdrezka.tv/resources/settings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
<setting type="bool" id="united_search" visible="false" default="true" />
1111
<setting type="text" id="us_command" visible="false" default="mode=search&keyword=" />
1212
</category>
13+
<category label="Authorization">
14+
<setting id="username" type="text" label="Username" />
15+
<setting id="password" type="text" label="Password" />
16+
<setting id="cookies" type="text" visible="false" label="Authorization cookies" />
17+
<setting type="action" label="Authorize" action="RunScript(plugin.video.hdrezka.tv, 0, authorize)" />
18+
</category>
1319
<category label="Proxy settings">
1420
<setting id="use_proxy" type="bool" label="Use proxy settings" default="false" />
1521
<setting id="protocol" type="labelenum" label="Protocol" values="http|https|socks5" default="http"/>

0 commit comments

Comments
 (0)