Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin.video.stalkervod] 0.0.2 #4440

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugin.video.stalkervod/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Stalker VOD Kodi add-on
**plugin.video.stalkervod** is a [Kodi](https://kodi.tv/) add-on for Stalker platform IPTV Client. You can watch Video On-Demand as well as TV Channels.

0.0.2 Add favorites context menu option and re-use existing token if possible

0.0.1 Initial Release
6 changes: 4 additions & 2 deletions plugin.video.stalkervod/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.stalkervod" name="Stalker VOD Client" version="0.0.1" provider-name="rickey">
<addon id="plugin.video.stalkervod" name="Stalker VOD Client" version="0.0.2" provider-name="rickey">
<requires>
<import addon="xbmc.python" version="3.0.1"/>
<import addon="script.module.requests" version="2.27.1"/>
Expand All @@ -22,7 +22,9 @@
<screenshot>resources/media/screenshot_2.png</screenshot>
<screenshot>resources/media/screenshot_3.png</screenshot>
</assets>
<news>v0.0.1 (2023-10-22)
<news>v0.0.2 (2023-12-27)
- Add favorites context menu option and re-use existing token if possible
v0.0.1 (2023-10-22)
- Initial Release
</news>
</extension>
Expand Down
15 changes: 9 additions & 6 deletions plugin.video.stalkervod/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ def list_categories():
categories = get_categories()
for category in categories:
list_item = xbmcgui.ListItem(label=category['title'])
url = G.get_plugin_url({'action': 'search', 'category': category['title'], 'category_id': category['id']})
list_item.addContextMenuItems([('Search', f'RunPlugin({url}, False)')])
fav_url = G.get_plugin_url({'action': 'listing', 'category': category['title'], 'category_id': category['id'],
'page': 1, 'update_listing': False, 'search_term': '', 'fav': 1})
search_url = G.get_plugin_url({'action': 'search', 'category': category['title'],
'category_id': category['id'], 'fav': 0})
list_item.addContextMenuItems([('Favorites', f'Container.Update({fav_url})'), ('Search', f'RunPlugin({search_url}, False)')])
# list_item.setInfo('video', {'title': category['title'], 'mediatype': 'video'})
url = G.get_plugin_url({'action': 'listing', 'category': category['title'], 'category_id': category['id'],
'page': 1, 'update_listing': False, 'search_term': ''})
'page': 1, 'update_listing': False, 'search_term': '', 'fav': 0})
xbmcplugin.addDirectoryItem(G.get_handle(), url, list_item, True)
xbmcplugin.endOfDirectory(G.get_handle(), succeeded=True, updateListing=False, cacheToDisc=False)

Expand Down Expand Up @@ -101,7 +104,7 @@ def list_videos(params):
search_term = params.get('search_term', '')
xbmcplugin.setPluginCategory(G.get_handle(), params['category'])
xbmcplugin.setContent(G.get_handle(), 'videos')
videos = get_videos(params['category_id'], params['page'], search_term)
videos = get_videos(params['category_id'], params['page'], search_term, params.get('fav', 0))
create_video_listing(videos, params)


Expand Down Expand Up @@ -157,7 +160,7 @@ def create_video_listing(videos, params):
video_info.setDateAdded(video['added'])
if video['year'].isdigit():
video_info.setYear(int(video['year']))
list_item.setArt({'poster': poster_url})
list_item.setArt({'poster': poster_url, 'fanart': poster_url})
directory_items.append((url, list_item, is_folder))
# Add navigation items
if int(videos['total_items']) > item_count:
Expand Down Expand Up @@ -220,7 +223,7 @@ def list_episodes(params):
else:
video_info.setMediaType('movie')
list_item.setProperties({'IsPlayable': 'true'})
list_item.setArt({'poster': params['poster_url']})
list_item.setArt({'poster': params['poster_url'], 'fanart': params['poster_url']})
url = G.get_plugin_url({'action': 'play', 'video_id': params['video_id'], 'series': episode_no})
xbmcplugin.addDirectoryItem(G.get_handle(), url, list_item, False)
xbmcplugin.endOfDirectory(G.get_handle(), succeeded=True, updateListing=False, cacheToDisc=False)
Expand Down
11 changes: 6 additions & 5 deletions plugin.video.stalkervod/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ def __call_stalker_portal(params):
_portal_url = G.portal_config.portal_url
_auth = Auth()
while True:
token = _auth.get_token()
token = _auth.get_token(retries > 0)
response = requests.get(url=_url,
headers={'Cookie': _mac_cookie,
'Authorization': 'Bearer ' + token,
'X-User-Agent': 'Model: MAG250; Link: WiFi', 'Referrer': _portal_url},
params=params,
timeout=30
)
if response.content.decode('utf-8') != 'Authorization failed.' or retries == G.addon_config.max_retries:
if response.content.decode('utf-8').find('Authorization failed') == -1 or retries == G.addon_config.max_retries:
break
_auth.clear_cache()
if retries > 1:
_auth.clear_cache()
retries += 1
return response.json()

Expand Down Expand Up @@ -67,9 +68,9 @@ def get_tv_channels(category_id, page):
return get_listing(params, page)


def get_videos(category_id, page, search_term):
def get_videos(category_id, page, search_term, fav):
"""Get videos for a category"""
params = {'type': 'vod', 'action': 'get_ordered_list', 'category': category_id, 'sortby': 'added'}
params = {'type': 'vod', 'action': 'get_ordered_list', 'category': category_id, 'sortby': 'added', 'fav': fav}
if bool(search_term.strip()):
params.update({'search': search_term})
return get_listing(params, page)
Expand Down
44 changes: 43 additions & 1 deletion plugin.video.stalkervod/lib/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,46 @@ class Token:
value: str = None


def _refresh_token(token):
"""Refresh token"""
_url = G.portal_config.portal_base_url + G.portal_config.context_path
_mac_cookie = G.portal_config.mac_cookie
_portal_url = G.portal_config.portal_url
requests.get(url=_url,
headers={'Cookie': _mac_cookie, 'Authorization': 'Bearer ' + token,
'X-User-Agent': 'Model: MAG250; Link: WiFi', 'Referrer': _portal_url},
params={
'type': 'stb',
'action': 'get_profile',
'hd': '1',
'auth_second_step': '0',
'num_banks': '1',
'stb_type': 'MAG250',
'image_version': '216',
'hw_version': '1.7-BD-00',
'not_valid_token': '0',
'device_id': G.portal_config.device_id,
'device_id2': G.portal_config.device_id_2,
'signature': G.portal_config.signature,
'sn': G.portal_config.serial_number,
'ver': 'ImageDescription:%200.2.18-r23-pub-254;%20ImageDate:%20Wed%20Aug%2029%2010:49:26'
'%20EEST%202018;%20PORTAL%20version:%205.1.1;%20API%20Version:%20JS%20API'
'%20version:%20328;%20STB%20API%20version:%20134;%20Player%20Engine%20version'
':%200x566'
},
timeout=30
)
requests.get(url=_url,
headers={'Cookie': _mac_cookie, 'Authorization': 'Bearer ' + token,
'X-User-Agent': 'Model: MAG250; Link: WiFi', 'Referrer': _portal_url},
params={
'type': 'watchdog', 'action': 'get_events',
'init': '0', 'cur_play_type': '1', 'event_active_id': '0'
},
timeout=30
)


class Auth:
"""Auth API"""

Expand All @@ -24,10 +64,12 @@ def __init__(self):
self._token = Token()
self._load_cache()

def get_token(self):
def get_token(self, refresh_token):
"""Get Token"""
Logger.debug('Token path {}'.format(self._token_path))
if self._token.value:
if refresh_token:
_refresh_token(self._token.value)
return self._token.value

_url = G.portal_config.portal_base_url + G.portal_config.context_path
Expand Down
2 changes: 1 addition & 1 deletion plugin.video.stalkervod/lib/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AddOnConfig:
handle: str = None
addon_data_path: str = None
max_page_limit: int = 2
max_retries: int = 2
max_retries: int = 3
token_path: str = None


Expand Down
Loading