From b1637df3f79b670a3d7cd0a1ab4735a0b47bbaac Mon Sep 17 00:00:00 2001 From: newt-sc <47229722+newt-sc@users.noreply.github.com> Date: Sun, 28 Nov 2021 15:25:02 +0200 Subject: [PATCH] release: v1.33.0 --- CHANGELOG.md | 3 + a4kStreaming/explorer.py | 10 +- a4kStreaming/lib/debrid.py | 5 +- a4kStreaming/lib/utils.py | 2 + a4kStreaming/provider.py | 91 +++++++++++++------ addon.xml | 5 +- packages/addons.xml | 5 +- packages/addons.xml.crc | 2 +- .../resource.language.en_gb/strings.po | 10 +- resources/settings.xml | 7 +- tests/test_suite.py | 15 ++- 11 files changed, 113 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 723553b..b0bff3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* [v1.33.0](https://github.com/newt-sc/a4kStreaming/releases/tag/plugin.video.a4kstreaming%2Fplugin.video.a4kstreaming-1.33.0): + * Add recommended providers usage for general speedup + * [v1.32.0](https://github.com/newt-sc/a4kStreaming/releases/tag/plugin.video.a4kstreaming%2Fplugin.video.a4kstreaming-1.32.0): * Back navigation from source files browsing diff --git a/a4kStreaming/explorer.py b/a4kStreaming/explorer.py index dc50b9d..ccfde20 100644 --- a/a4kStreaming/explorer.py +++ b/a4kStreaming/explorer.py @@ -2271,7 +2271,7 @@ def play(core, params): season_results = None pack_results = None - if len(last_results) > 50: + while len(last_results) > 10: oldest_key = list(last_results.keys())[0] for key in last_results: if last_results[key]['time'] < last_results[oldest_key]['time']: @@ -2500,7 +2500,10 @@ def delete_magnet(): core.threading.Thread(target=delete_magnet).start() return files - link = None + link = result.get('url', None) + if link: + goto .play # type: ignore # noqa: F821 + files = [] if result.get('debrid', 'PM') == 'PM': try: files = resolve_pm() @@ -2594,7 +2597,10 @@ def delete_magnet(): except: core.logger.notice(core.traceback.format_exc()) + label .play # type: ignore # noqa: F821 item = core.kodi.xbmcgui.ListItem(path=link, offscreen=True) + item.setProperty('IsPlayable', 'true') + item.setContentLookup(False) video_meta = provider_params.title.copy() video_meta.pop('tvshowseasonid', None) diff --git a/a4kStreaming/lib/debrid.py b/a4kStreaming/lib/debrid.py index 628c5f4..f6001d2 100644 --- a/a4kStreaming/lib/debrid.py +++ b/a4kStreaming/lib/debrid.py @@ -10,9 +10,12 @@ def premiumize_transfers(apikey): } def premiumize_files(apikey, id): + if id != '': + id = 'id=%s&' % id + return { 'method': 'GET', - 'url': 'https://www.premiumize.me/api/folder/list?id=%s&includebreadcrumbs=false&apikey=%s' % (id, apikey), + 'url': 'https://www.premiumize.me/api/folder/list?%sincludebreadcrumbs=false&apikey=%s' % (id, apikey), 'headers': { 'content-type': 'application/json', }, diff --git a/a4kStreaming/lib/utils.py b/a4kStreaming/lib/utils.py index 47025bb..feaec99 100644 --- a/a4kStreaming/lib/utils.py +++ b/a4kStreaming/lib/utils.py @@ -9,6 +9,7 @@ import zipfile import shutil import time +import base64 from datetime import datetime from io import BytesIO from itertools import islice @@ -34,6 +35,7 @@ default_encoding = 'utf-8' zip_utf8_flag = 0x800 py3_zip_missing_utf8_flag_fallback_encoding = 'cp437' +recommended = base64.b64decode('VE9SUkVOVElP') temp_dir = os.path.join(kodi.addon_profile, 'temp') provider_temp_dir = os.path.join(kodi.addon_profile, 'provider-temp') diff --git a/a4kStreaming/provider.py b/a4kStreaming/provider.py index bacaec5..d754eb6 100644 --- a/a4kStreaming/provider.py +++ b/a4kStreaming/provider.py @@ -162,31 +162,54 @@ def __search(core, params): return {} sources = {} - for key in provider: - if not provider[key]: - continue - try: - source = core.importlib.import_module(__sources_module_name(core) + ('.%s' % key.lower())) - sources[key] = source.sources() - except: pass + use_recommended = core.kodi.get_bool_setting('provider.use_recommended') + recommended = core.utils.recommended + try: + source = core.importlib.import_module(__sources_module_name(core) + ('.%s' % recommended.lower())) + sources[recommended] = source.sources() + except: pass + + if len(sources) == 0 or not use_recommended: + use_recommended = False + for key in provider: + if not provider[key] or key == recommended: + continue + + try: + source = core.importlib.import_module(__sources_module_name(core) + ('.%s' % key.lower())) + sources[key] = source.sources() + except: pass threads = [] search = lambda: None search.results = {} search.cached = {} + premiumize_apikey = core.utils.get_premiumize_apikey(core) + realdebrid_apikey = core.utils.get_realdebrid_apikey(core) + alldebrid_apikey = core.utils.get_alldebrid_apikey(core) + use_direct_urls = False + for key in sources.keys(): def get_sources(key): source = sources[key] results = [] try: + apikeys = {} + if use_direct_urls: + apikeys = { + 'pm': premiumize_apikey, + 'rd': realdebrid_apikey, + 'ad': alldebrid_apikey + } + if params.title.mediatype == 'movie': try: - results += source.movie(params.title.title, params.title.year, params.title.imdbnumber) + results += source.movie(params.title.title, params.title.year, params.title.imdbnumber, apikeys=apikeys) except Exception as e: if 'movie() takes' in str(e): - results += source.movie(params.title.title, params.title.year) + results += source.movie(params.title.title, params.title.year, apikeys=apikeys) else: core.logger.notice(core.traceback.format_exc()) else: @@ -202,7 +225,7 @@ def get_sources(key): 'is_airing': params.title.is_airing } all_info = { 'info': { 'tvshow.imdb_id': params.title.tvshowid } } - results += source.episode(simple_info, all_info) + results += source.episode(simple_info, all_info, apikeys=apikeys) if len(results) <= 0: return @@ -302,24 +325,33 @@ def rd(apikey): def ad(apikey): sanitize_results(check_ad(apikey), 'AD') - threads = [] - - premiumize_apikey = core.utils.get_premiumize_apikey(core) - if premiumize_apikey: - threads.append(core.threading.Thread(target=pm, args=(premiumize_apikey,))) - - realdebrid_apikey = core.utils.get_realdebrid_apikey(core) - if realdebrid_apikey: - threads.append(core.threading.Thread(target=rd, args=(realdebrid_apikey,))) - - alldebrid_apikey = core.utils.get_alldebrid_apikey(core) - if alldebrid_apikey: - threads.append(core.threading.Thread(target=ad, args=(alldebrid_apikey,))) + def sanitize_direct_url_results(): + for result in results: + result = result.copy() + result['ref'] = params.title + size = float(result['size']) / 1024 + result['size'] = round(size, 1) + core.utils.cleanup_result(result) + if search.results.get(result['url'], None) is None: + search.results[result['url']] = result + result['title_with_debrid'] = '%s | %s' % (result['debrid'], result['title']) + search.cached['%s%s' % (result['debrid'], result['url'])] = result - for thread in threads: - thread.start() - for thread in threads: - thread.join() + if use_direct_urls: + sanitize_direct_url_results() + else: + threads = [] + if premiumize_apikey: + threads.append(core.threading.Thread(target=pm, args=(premiumize_apikey,))) + if realdebrid_apikey: + threads.append(core.threading.Thread(target=rd, args=(realdebrid_apikey,))) + if alldebrid_apikey: + threads.append(core.threading.Thread(target=ad, args=(alldebrid_apikey,))) + + for thread in threads: + thread.start() + for thread in threads: + thread.join() except Exception as e: core.logger.notice(e) @@ -373,8 +405,9 @@ def execute(): time_after_start = core.utils.time_ms() - params.start_time if time_after_start < 1000: core.kodi.xbmc.sleep(int(round(1000 - time_after_start))) - progress.create(core.kodi.addon_name, *progress_msg()) - search.dialog = True + if not use_recommended: + progress.create(core.kodi.addon_name, *progress_msg()) + search.dialog = True chunk_size = len(sources) for chunk in core.utils.chunk(threads, chunk_size): diff --git a/addon.xml b/addon.xml index e88316d..18ff3d6 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ @@ -32,6 +32,9 @@ Designed for low-end devices and Estuary skin. screenshot-06.jpg +[v1.33.0]: + * Add recommended providers usage for general speedup + [v1.32.0]: * Back navigation from source files browsing diff --git a/packages/addons.xml b/packages/addons.xml index d3222a8..01b7f2c 100644 --- a/packages/addons.xml +++ b/packages/addons.xml @@ -4,7 +4,7 @@ @@ -35,6 +35,9 @@ Designed for low-end devices and Estuary skin. screenshot-06.jpg +[v1.33.0]: + * Add recommended providers usage for general speedup + [v1.32.0]: * Back navigation from source files browsing diff --git a/packages/addons.xml.crc b/packages/addons.xml.crc index 3bf4786..f60b7ac 100644 --- a/packages/addons.xml.crc +++ b/packages/addons.xml.crc @@ -1 +1 @@ -3551276326d6a3558e0748757b1a431d81bd9268 \ No newline at end of file +37360db3c14234cbc4d347aa5b2f24a06582bb7b \ No newline at end of file diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index efc409f..2c9beeb 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -171,10 +171,14 @@ msgid "Install" msgstr "" msgctxt "#33302" -msgid "Manage" +msgid "Use recommended" msgstr "" msgctxt "#33303" +msgid "Manage" +msgstr "" + +msgctxt "#33304" msgid "Check for an update" msgstr "" @@ -218,11 +222,11 @@ msgid "Migrate Trakt.tv's watched status to IMDb (via rating)" msgstr "" msgctxt "#33602" -msgid "Trakt API key (Client ID): " +msgid "Trakt API key/Client ID (!used only for migration!): " msgstr "" msgctxt "#33603" -msgid "Trakt username (User slug): " +msgid "Trakt username/slug (!used only for migration!): " msgstr "" msgctxt "#33604" diff --git a/resources/settings.xml b/resources/settings.xml index a12b8df..296f8c6 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -21,9 +21,10 @@ - - - + + + + diff --git a/tests/test_suite.py b/tests/test_suite.py index 27a3555..2508590 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -41,7 +41,7 @@ def select(*args, **kwargs): return 1 provider = a4kstreaming_api.core.cache.get_provider() selected = {} for key in provider.keys(): - if len(key) == 8: + if len(key) == 8 or settings.get('provider.use_recommended', 'false') == 'true': selected[key] = True a4kstreaming_api.core.cache.save_provider(selected) @@ -68,6 +68,7 @@ def __invoke(a4kstreaming_api, action, params={}, settings={}, prerun=None, remo 'views.episodes': '0', 'views.season': '0', 'views.episode': '0', + 'provider.use_recommended': 'false', 'premiumize.apikey': premiumize_apikey, 'realdebrid.apikey': realdebrid_apikey, 'alldebrid.apikey': alldebrid_apikey, @@ -139,6 +140,18 @@ def prerun(): assert play.results is not None +def test_play_movie_pm_using_recommended(): + a4kstreaming_api = api.A4kStreamingApi({'kodi': True}) + + settings = { 'realdebrid.apikey': '', 'alldebrid.apikey': '', 'provider.use_recommended': 'true' } + def prerun(): + __setup_provider(a4kstreaming_api, settings) + + title = b'eyJtZWRpYXR5cGUiOiAibW92aWUiLCAiaW1kYm51bWJlciI6ICJ0dDAxMDgxNjAiLCAidGl0bGUiOiAiU2xlZXBsZXNzIGluIFNlYXR0bGUiLCAib3JpZ2luYWx0aXRsZSI6ICJTbGVlcGxlc3MgaW4gU2VhdHRsZSIsICJ0dnNob3dpZCI6IG51bGwsICJzZWFzb25zIjogbnVsbCwgInR2c2hvd3RpdGxlIjogIiIsICJ5ZWFyIjogMTk5MywgInByZW1pZXJlZCI6ICIxOTkzLTYtMjUiLCAiZHVyYXRpb24iOiA2MzAwLCAibXBhYSI6ICJQRyIsICJnZW5yZSI6IFsiQ29tZWR5IiwgIkRyYW1hIiwgIlJvbWFuY2UiXSwgImNvdW50cnkiOiBbIlVuaXRlZCBTdGF0ZXMiXSwgInRyYWlsZXIiOiAiP2FjdGlvbj10cmFpbGVyJmlkPXZpNzI3MzY3NDQ5IiwgInBsb3QiOiAiQSByZWNlbnRseSB3aWRvd2VkIG1hbidzIHNvbiBjYWxscyBhIHJhZGlvIHRhbGstc2hvdyBpbiBhbiBhdHRlbXB0IHRvIGZpbmQgaGlzIGZhdGhlciBhIHBhcnRuZXIuIiwgInRhZ2xpbmUiOiAiV2hhdCBpZiBzb21lb25lIHlvdSBuZXZlciBtZXQsIHNvbWVvbmUgeW91IG5ldmVyIHNhdywgc29tZW9uZSB5b3UgbmV2ZXIga25ldyB3YXMgdGhlIG9ubHkgc29tZW9uZSBmb3IgeW91PyIsICJvdmVybGF5IjogMCwgInN0dWRpbyI6IFsiVHJpU3RhciBQaWN0dXJlcyIsICJUcmlTdGFyIFBpY3R1cmVzIiwgIkNvbHVtYmlhIFRyaVN0YXIgRmlsbSJdLCAiZGlyZWN0b3IiOiBbIk5vcmEgRXBocm9uIl0sICJ3cml0ZXIiOiBbIkplZmYgQXJjaCIsICJOb3JhIEVwaHJvbiIsICJEYXZpZCBTLiBXYXJkIl19' + play = __invoke(a4kstreaming_api, 'play', { 'type': title }, settings=settings, prerun=prerun) + + assert play.results is not None + def test_trailer(): a4kstreaming_api = api.A4kStreamingApi({'kodi': True})