diff --git a/plugin.video.stalkervod/README.md b/plugin.video.stalkervod/README.md index 853bfd86a..ed65d9fb9 100644 --- a/plugin.video.stalkervod/README.md +++ b/plugin.video.stalkervod/README.md @@ -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 \ No newline at end of file diff --git a/plugin.video.stalkervod/addon.xml b/plugin.video.stalkervod/addon.xml index 9d0a9d976..58b0d9dd2 100644 --- a/plugin.video.stalkervod/addon.xml +++ b/plugin.video.stalkervod/addon.xml @@ -1,5 +1,5 @@ - + @@ -22,7 +22,9 @@ resources/media/screenshot_2.png resources/media/screenshot_3.png - v0.0.1 (2023-10-22) + 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 diff --git a/plugin.video.stalkervod/lib/addon.py b/plugin.video.stalkervod/lib/addon.py index 0be35cd38..145a5c54d 100644 --- a/plugin.video.stalkervod/lib/addon.py +++ b/plugin.video.stalkervod/lib/addon.py @@ -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) @@ -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) @@ -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: @@ -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) diff --git a/plugin.video.stalkervod/lib/api.py b/plugin.video.stalkervod/lib/api.py index cc19839a2..3a422c270 100644 --- a/plugin.video.stalkervod/lib/api.py +++ b/plugin.video.stalkervod/lib/api.py @@ -16,7 +16,7 @@ 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, @@ -24,9 +24,10 @@ def __call_stalker_portal(params): 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() @@ -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) diff --git a/plugin.video.stalkervod/lib/auth.py b/plugin.video.stalkervod/lib/auth.py index 5e93c0f00..469a26224 100644 --- a/plugin.video.stalkervod/lib/auth.py +++ b/plugin.video.stalkervod/lib/auth.py @@ -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""" @@ -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 diff --git a/plugin.video.stalkervod/lib/globals.py b/plugin.video.stalkervod/lib/globals.py index 72e54d966..0099fff4b 100644 --- a/plugin.video.stalkervod/lib/globals.py +++ b/plugin.video.stalkervod/lib/globals.py @@ -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