Skip to content

Commit

Permalink
release: v0.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed Jan 25, 2021
1 parent 0b7e7aa commit 055dc7a
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 96 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
env:
A4KSTREAMING_IMDB_TOKEN: ${{ secrets.A4KSTREAMING_IMDB_TOKEN }}
A4KSTREAMING_PREMIUMIZE_APIKEY: ${{ secrets.A4KSTREAMING_PREMIUMIZE_APIKEY }}
A4KSTREAMING_REALDEBRID_APIKEY: ${{ secrets.A4KSTREAMING_REALDEBRID_APIKEY }}
A4KSTREAMING_PROVIDER_URL: ${{ secrets.A4KSTREAMING_PROVIDER_URL }}
run: |
coverage run -m pytest -v
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cron-tests-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
env:
A4KSTREAMING_IMDB_TOKEN: ${{ secrets.A4KSTREAMING_IMDB_TOKEN }}
A4KSTREAMING_PREMIUMIZE_APIKEY: ${{ secrets.A4KSTREAMING_PREMIUMIZE_APIKEY }}
A4KSTREAMING_REALDEBRID_APIKEY: ${{ secrets.A4KSTREAMING_REALDEBRID_APIKEY }}
A4KSTREAMING_PROVIDER_URL: ${{ secrets.A4KSTREAMING_PROVIDER_URL }}
run: |
pytest -v ./tests/test_suite.py
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* [v0.23.0](https://github.com/newt-sc/a4kStreaming/releases/tag/plugin.video.a4kstreaming%2Fplugin.video.a4kstreaming-0.23.0):
* RealDebrid support

* [v0.22.0](https://github.com/newt-sc/a4kStreaming/releases/tag/plugin.video.a4kstreaming%2Fplugin.video.a4kstreaming-0.22.0):
* New context menu:
* Trailer
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Designed for low-end devices and Estuary skin.
* Caching of results
* Debrid support
* Premiumize
* RealDebrid
* Misc
* Migrate watched titles from Trakt.tv to IMDb (via rating)
* Migrate movies and shows collection from Trakt.tv to IMDb custom lists
Expand Down
2 changes: 1 addition & 1 deletion a4kStreaming/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __mock_settings(self, settings):

def get_setting(id):
setting = settings.get(id, None)
if not setting:
if setting is None:
setting = default(id)
return setting

Expand Down
117 changes: 98 additions & 19 deletions a4kStreaming/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def debrid(core, params):
])

elif params.type == 'premiumize_files':
apikey = core.utils.get_debrid_apikey(core)
apikey = core.utils.get_premiumize_apikey(core)
if not apikey or apikey == '':
core.kodi.notification('Missing debrid service API key')
return
Expand Down Expand Up @@ -810,7 +810,7 @@ def debrid(core, params):
})

elif params.type == 'premiumize_transfers':
apikey = core.utils.get_debrid_apikey(core)
apikey = core.utils.get_premiumize_apikey(core)
if not apikey or apikey == '':
core.kodi.notification('Missing debrid service API key')
return
Expand Down Expand Up @@ -1606,7 +1606,7 @@ def trailer(core, params):
return [trailerUrl]

def cache_sources(core, params, results=None):
apikey = core.utils.get_debrid_apikey(core)
apikey = core.utils.get_premiumize_apikey(core)
if not apikey or apikey == '':
core.kodi.notification('Missing debrid service API key')
return
Expand Down Expand Up @@ -1698,8 +1698,9 @@ def play(core, params):
core.utils.end_action(core, True)
return

apikey = core.utils.get_debrid_apikey(core)
if not apikey or apikey == '':
pm_apikey = core.utils.get_premiumize_apikey(core)
rd_apikey = core.utils.get_realdebrid_apikey(core)
if (not pm_apikey or pm_apikey == '') and (not rd_apikey or rd_apikey == ''):
core.kodi.notification('Missing debrid service API key')
core.utils.end_action(core, True)
return
Expand Down Expand Up @@ -1766,7 +1767,7 @@ def play(core, params):
if len(provider.cached) == 0:
core.kodi.notification('No sources found')

if len(provider.results) > 0:
if len(provider.results) > 0 and pm_apikey:
confirmed = core.kodi.xbmcgui.Dialog().yesno(
'Uncached sources found',
'Found %s uncached sources. Do you want to some of them to debrid?' % len(provider.results),
Expand Down Expand Up @@ -1873,23 +1874,89 @@ def sorter():
selection -= 1

result = results[results_keys[selection]]
video_ext = list(map(lambda v: '.%s' % v.upper(), core.utils.video_containers()))
size = 1048576 * 200

request = {
'method': 'POST',
'url': 'https://www.premiumize.me/api/transfer/directdl?apikey=%s' % apikey,
'data': {
'src': result['magnet']
},
}
def resolve_pm():
request = {
'method': 'POST',
'url': 'https://www.premiumize.me/api/transfer/directdl?apikey=%s' % pm_apikey,
'data': {
'src': result['magnet']
},
}

response = core.request.execute(core, request)
link = None
if response.status_code == 200:
response = core.request.execute(core, request)
parsed_response = core.json.loads(response.content)
video_ext = list(map(lambda v: '.%s' % v.upper(), core.utils.video_containers()))
size = 1048576 * 200
return parsed_response.get('content', [])

files = parsed_response.get('content', [])
def resolve_rd():
auth = core.utils.rd_auth_query_params(core, rd_apikey)
request = {
'method': 'POST',
'url': 'https://api.real-debrid.com/rest/1.0/torrents/addMagnet%s' % auth,
'data': {
'magnet': result['magnet']
},
}
response = core.request.execute(core, request)
parsed_response = core.json.loads(response.content)
id = parsed_response['id']
uri = parsed_response['uri']
files = []
try:
file_ids = []
for file_id in result['debrid_files'].keys():
file = result['debrid_files'][file_id]
if core.os.path.splitext(file['filename'])[1].upper() in video_ext and int(file['filesize']) > size:
file_ids.append(file_id)

request = {
'method': 'POST',
'url': 'https://api.real-debrid.com/rest/1.0/torrents/selectFiles/%s%s' % (id, auth),
'data': {
'files': ','.join(file_ids)
},
}
response = core.request.execute(core, request)

request = {
'method': 'GET',
'url': '%s%s' % (uri, auth)
}
response = core.request.execute(core, request)
parsed_response = core.json.loads(response.content)
selected_files = []
for file in parsed_response['files']:
if file.get('selected', None):
selected_files.append(file)

for i, file in enumerate(selected_files):
files.append({
'path': file['path'],
'size': file['bytes'],
'link': parsed_response['links'][i]
})

except:
request = {
'method': 'DELETE',
'url': 'https://api.real-debrid.com/rest/1.0/torrents/delete/%s%s' % (id, auth),
}
response = core.request.execute(core, request)
core.logger.notice(files)
return files

link = None
files = []
if result.get('debrid', 'PM') == 'PM':
try: files = resolve_pm()
except: pass
elif result['debrid'] == 'RD':
try: files = resolve_rd()
except: pass

if len(files) > 0:
for file in files:
if file.get('path', None):
file['path'] = core.os.path.basename(file['path']).upper()
Expand Down Expand Up @@ -1954,6 +2021,18 @@ def sorter():
file = files[0]
link = file.get('link', file.get('stream_link', None))

if result.get('debrid', 'PM') == 'RD':
request = {
'method': 'POST',
'url': 'https://api.real-debrid.com/rest/1.0/unrestrict/link%s' % core.utils.rd_auth_query_params(core, rd_apikey),
'data': {
'link': link
},
}
response = core.request.execute(core, request)
parsed_response = core.json.loads(response.content)
link = parsed_response['download']

if not link:
general.last_action_time = core.utils.time_ms()
core.cache.save_general(general)
Expand Down
2 changes: 1 addition & 1 deletion a4kStreaming/lib/kodi_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __get_addon_info(name):
elif name == 'path':
return os.path.join(os.path.dirname(__file__), '../..')
__addon.getAddonInfo = __get_addon_info
__addon.getSetting = lambda _: '29'
__addon.getSetting = lambda _: None
xbmcaddon.Addon = lambda _: __addon

# xbmcplugin
Expand Down
9 changes: 8 additions & 1 deletion a4kStreaming/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def imdb_auth_request_props():
}
}

def rd_auth_query_params(core, rd_api_key=None):
rd_apikey = rd_api_key if rd_api_key else get_realdebrid_apikey(core)
return '?client_id=X245A4XAIBGVM&auth_token=%s' % rd_apikey

def time_ms():
return int(round(time.time() * 1000))

Expand Down Expand Up @@ -171,9 +175,12 @@ def extract_zip(src, dest):
def random_digit_str(length):
return ''.join(random.choice(string.digits) for _ in range(length))

def get_debrid_apikey(core):
def get_premiumize_apikey(core):
return core.kodi.get_setting('premiumize.apikey')

def get_realdebrid_apikey(core):
return core.kodi.get_setting('realdebrid.apikey')

def get_color_string(string, color):
return '[B][COLOR %s]%s[/COLOR][/B]' % (color, string)

Expand Down
122 changes: 99 additions & 23 deletions a4kStreaming/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def __sources_module_name(core):

def __update_config(core):
provider = core.cache.get_provider()
sources = core.importlib.import_module(__sources_module_name(core)).__all__
try: sources = core.importlib.import_module(__sources_module_name(core)).__all__
except: sources = []
sources = [source.upper() for source in sources]

provider_sources = list(provider.keys())
Expand Down Expand Up @@ -163,8 +164,10 @@ def __search(core, params):
if not provider[key]:
continue

source = core.importlib.import_module(__sources_module_name(core) + ('.%s' % key.lower()))
sources[key] = source.sources()
try:
source = core.importlib.import_module(__sources_module_name(core) + ('.%s' % key.lower()))
sources[key] = source.sources()
except: pass

threads = []
search = lambda: None
Expand Down Expand Up @@ -199,32 +202,105 @@ def get_sources(key):
all_info = { 'info': { 'tvshow.imdb_id': params.title.tvshowid } }
results += source.episode(simple_info, all_info)

if len(results) > 0:
request = {
'method': 'POST',
'url': 'https://www.premiumize.me/api/cache/check?apikey=%s' % core.utils.get_debrid_apikey(core),
'data': {
'items[]': [item['hash'] for item in results]
},
}
if len(results) <= 0:
return

response = core.request.execute(core, request)
if response.status_code == 200:
def check_pm():
check_result = { 'status': [], 'filesize': [], 'files': None }
try:
apikey = core.utils.get_premiumize_apikey(core)
if not apikey:
return check_result

request = {
'method': 'POST',
'url': 'https://www.premiumize.me/api/cache/check?apikey=%s' % apikey,
'data': {
'items[]': [item['hash'] for item in results]
},
}

response = core.request.execute(core, request)
parsed_response = core.json.loads(response.content)
for i, status in enumerate(parsed_response['response']):
result = results[i]
result['ref'] = params.title
return { 'status': parsed_response['response'], 'filesize': parsed_response['filesize'], 'files': None }
except:
return check_result

size = float(parsed_response['filesize'][i]) / 1024 / 1024 / 1024
if size <= 0:
size = float(result['size']) / 1024
result['size'] = round(size, 1)
def check_rd():
check_result = { 'status': [], 'filesize': [], 'files': [] }
try:
apikey = core.utils.get_realdebrid_apikey(core)
if not apikey:
return check_result

keys = [item['hash'] for item in results]
hashes = '/'.join(keys)
request = {
'method': 'GET',
'url': 'https://api.real-debrid.com/rest/1.0/torrents/instantAvailability/%s?client_id=X245A4XAIBGVM&auth_token=%s' % (hashes, apikey)
}

response = core.request.execute(core, request)
parsed_response = core.json.loads(response.content)

core.utils.cleanup_result(result)
for key in keys:
parsed_result = parsed_response.get(key, {})
if isinstance(parsed_result, list):
parsed_result = {}
status = len(parsed_result.get('rd', [])) > 0
filesize = 0
files = None
if status:
try:
files = {}
for file_result in parsed_result['rd']:
for file_id in file_result.keys():
files[file_id] = file_result[file_id]
filesize = sum(f.get('filesize', 0) for f in files.values())
except:
status = False
check_result['status'].append(status)
check_result['filesize'].append(filesize)
check_result['files'].append(files)

return check_result
except:
return check_result

def sanitize_results(check, debrid):
for i, status in enumerate(check['status']):
result = results[i].copy()
result['ref'] = params.title

size = float(check['filesize'][i]) / 1024 / 1024 / 1024
if size <= 0:
size = float(result['size']) / 1024
result['size'] = round(size, 1)

core.utils.cleanup_result(result)
if search.results.get(result['hash'], None) is None:
search.results[result['hash']] = result

if status:
search.cached[result['hash']] = result
if status:
result_copy = result
result_copy['title'] = '%s | %s' % (debrid, result['title'])
result_copy['debrid'] = debrid
if check['files'] and len(check['files']) > i:
result_copy['debrid_files'] = check['files'][i]
search.cached['%s%s' % (debrid, result['hash'])] = result_copy

def pm():
sanitize_results(check_pm(), 'PM')
def rd():
sanitize_results(check_rd(), 'RD')

threads = []
threads.append(core.threading.Thread(target=pm))
threads.append(core.threading.Thread(target=rd))
for thread in threads:
thread.start()
for thread in threads:
thread.join()

except Exception as e:
core.logger.notice(e)
Expand Down
Loading

0 comments on commit 055dc7a

Please sign in to comment.