def user_transfers_to_listItem(self): try: sysaddon, syshandle = argv[0], int(argv[1]) extensions = supported_video_extensions() transfer_files = self.user_transfers() if not transfer_files: if self.server_notifications: control.notification(message='Request Failure-Empty Content', icon=pm_icon) log_utils.log('Premiumize.me: Request Failure-Empty Content', __name__, log_utils.LOGDEBUG) return except: log_utils.error() return folder_str, file_str, downloadMenu, renameMenu, deleteMenu, clearFinishedMenu = control.lang(40046).upper(), control.lang(40047).upper(), control.lang(40048), control.lang(40049), control.lang(40050), control.lang(40051) for count, item in enumerate(transfer_files, 1): try: cm = [] type = 'folder' if item['file_id'] is None else 'file' name = control.strip_non_ascii_and_unprintable(item['name']) status = item['status'] progress = item['progress'] if status == 'finished': progress = 100 else: try: progress = re.findall(r'(?:\d{0,1}\.{0,1})(\d+)', str(progress))[0][:2] except: progress = 'UNKNOWN' if type == 'folder': isFolder = True if status == 'finished' else False status_str = '[COLOR %s]%s[/COLOR]' % (control.getHighlightColor(), status.capitalize()) label = '%02d | [B]%s[/B] - %s | [B]%s[/B] | [I]%s [/I]' % (count, status_str, str(progress) + '%', folder_str, name) url = '%s?action=pm_MyFiles&id=%s&name=%s' % (sysaddon, item['folder_id'], quote_plus(name)) # Till PM addresses issue with item also being removed from public acess if item not accessed for 60 days this option is disabled. # cm.append((clearFinishedMenu, 'RunPlugin(%s?action=pm_ClearFinishedTransfers)' % sysaddon)) else: isFolder = False details = self.item_details(item['file_id']) if not details: if self.server_notifications: control.notification(message='Request Failure-Empty Content', icon=pm_icon) log_utils.log('Premiumize.me: Request Failure-Empty Content', __name__, log_utils.LOGDEBUG) return url_link = details['link'] if url_link.startswith('/'): url_link = 'https' + url_link size = details['size'] display_size = float(int(size)) / 1073741824 label = '%02d | %s%% | [B]%s[/B] | %.2f GB | [I]%s [/I]' % (count, str(progress), file_str, display_size, name) url = '%s?action=play_URL&url=%s' % (sysaddon, url_link) cm.append((downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&url=%s&caller=premiumize)' % (sysaddon, quote_plus(name), quote_plus(pm_icon), url_link))) cm.append((deleteMenu % 'Transfer', 'RunPlugin(%s?action=pm_DeleteTransfer&id=%s&name=%s)' % (sysaddon, item['id'], quote_plus(name)))) item = control.item(label=label) item.addContextMenuItems(cm) item.setArt({'icon': pm_icon, 'poster': pm_icon, 'thumb': pm_icon, 'fanart': addonFanart, 'banner': pm_icon}) item.setInfo(type='video', infoLabels='') control.addItem(handle=syshandle, url=url, listitem=item, isFolder=isFolder) except: log_utils.error() control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
def display_magnet_pack(self, magnet_url, info_hash): try: torrent_id = None video_only_items = [] append = video_only_items.append list_file_items = [] info_hash = info_hash.lower() extensions = supported_video_extensions() torrent_files = self._get(check_cache_url + '/' + info_hash) if not info_hash in torrent_files: return None torrent_id = self.add_magnet(magnet_url) if not torrent_id: return None torrent_files = torrent_files[info_hash]['rd'] for item in torrent_files: video_only = self.video_only(item, extensions) if not video_only: continue torrent_keys = item.keys() if len(torrent_keys) == 0: continue append(torrent_keys) video_only_items = max(video_only_items, key=len) torrent_keys = ','.join(video_only_items) self.add_torrent_select(torrent_id, torrent_keys) torrent_info = self.torrent_info(torrent_id) list_file_items = [dict(i, **{'link':torrent_info['links'][idx]}) for idx, i in enumerate([i for i in torrent_info['files'] if i['selected'] == 1])] list_file_items = [{'link': i['link'], 'filename': i['path'].replace('/', ''), 'size': float(i['bytes']) / 1073741824} for i in list_file_items] self.delete_torrent(torrent_id) return list_file_items except: log_utils.error('Real-Debrid Error: DISPLAY MAGNET PACK %s : ' % magnet_url) if torrent_id: self.delete_torrent(torrent_id)
def resolve_magnet(self, magnet_url, info_hash, season, episode, ep_title): from resources.lib.modules.source_utils import seas_ep_filter, extras_filter try: file_url = None correct_files = [] extensions = supported_video_extensions() extras_filtering_list = extras_filter() data = {'src': magnet_url} response = self._post(transfer_directdl_url, data) if not 'status' in response or response['status'] != 'success': return None valid_results = [i for i in response.get('content') if any(i.get('path').lower().endswith(x) for x in extensions) and not i.get('link', '') == ''] if len(valid_results) == 0: return if season: episode_title = re.sub(r'[^A-Za-z0-9-]+', '.', ep_title.replace('\'', '')).lower() for item in valid_results: if seas_ep_filter(season, episode, item['path'].split('/')[-1]): correct_files.append(item) if len(correct_files) == 0: continue for i in correct_files: compare_link = seas_ep_filter(season, episode, i['path'], split=True) compare_link = re.sub(episode_title, '', compare_link) if not any(x in compare_link for x in extras_filtering_list): file_url = i['link'] break else: file_url = max(valid_results, key=lambda x: int(x.get('size'))).get('link', None) if file_url: if self.store_to_cloud: self.create_transfer(magnet_url) return self.add_headers_to_url(file_url) else: log_utils.log('Premiumize.me: FAILED TO RESOLVE MAGNET %s : ' % magnet_url, __name__, log_utils.LOGWARNING) except: log_utils.error('Premiumize.me Error RESOLVE MAGNET %s : ' % magnet_url) return None
def display_magnet_pack(self, magnet_url, info_hash): try: end_results = [] extensions = supported_video_extensions() data = {'src': magnet_url} result = self._post(transfer_directdl_url, data=data) if not 'status' in result or result['status'] != 'success': return None for item in result.get('content'): if any( item.get('path').lower().endswith(x) for x in extensions) and not item.get('link', '') == '': try: path = item['path'].split('/')[-1] except: path = item['path'] end_results.append({ 'link': item['link'], 'filename': path, 'size': float(item['size']) / 1073741824 }) return end_results except Exception as e: log_utils.log('Error display_magnet_pack: %s' % str(e), __name__, log_utils.LOGDEBUG) return None
def resolve_magnet(self, magnet_url, info_hash, season, episode, ep_title): from resources.lib.modules.source_utils import seas_ep_filter, episode_extras_filter try: file_url = None correct_files = [] extensions = supported_video_extensions() extras_filtering_list = episode_extras_filter() transfer_id = self.create_transfer(magnet_url) transfer_info = self.list_transfer(transfer_id) valid_results = [i for i in transfer_info.get('links') if any(i.get('filename').lower().endswith(x) for x in extensions) and not i.get('link', '') == ''] if len(valid_results) == 0: return if season: for item in valid_results: if seas_ep_filter(season, episode, item['filename']): correct_files.append(item) if len(correct_files) == 0: continue episode_title = re.sub(r'[^A-Za-z0-9-]+', '.', ep_title.replace('\'', '')).lower() for i in correct_files: compare_link = seas_ep_filter(season, episode, i['filename'], split=True) compare_link = re.sub(episode_title, '', compare_link) if not any(x in compare_link for x in extras_filtering_list): media_id = i['link'] break else: media_id = max(valid_results, key=lambda x: x.get('size')).get('link', None) if not store_to_cloud: self.delete_transfer(transfer_id) file_url = self.unrestrict_link(media_id) return file_url except: log_utils.error() if transfer_id: self.delete_transfer(transfer_id) return None
def browse_user_cloud(self, folder): sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) extensions = supported_video_extensions() torrent_folder = jsloads(folder) links = torrent_folder['links'] links = [i for i in links if i['filename'].lower().endswith(tuple(extensions))] status_code = torrent_folder['statusCode'] file_str, downloadMenu, deleteMenu = control.lang(40047).upper(), control.lang(40048), control.lang(40050) for count, item in enumerate(links, 1): try: cm = [] url_link = item['link'] name = control.strip_non_ascii_and_unprintable(item['filename']) size = item['size'] display_size = float(int(size))/1073741824 label = '%02d | [B]%s[/B] | %.2f GB | [I]%s [/I]' % (count, file_str, display_size, name) if status_code == 4: url = '%s?action=playURL&url=%s&caller=alldebrid&type=unrestrict' % (sysaddon, url_link) else: url = '' cm.append((downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&url=%s&caller=alldebrid)' % (sysaddon, quote_plus(name), quote_plus(ad_icon), url_link))) item = control.item(label=label) item.addContextMenuItems(cm) item.setArt({'icon': ad_icon, 'poster': ad_icon, 'thumb': ad_icon, 'fanart': addonFanart, 'banner': ad_icon}) item.setInfo(type='video', infoLabels='') video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) except: log_utils.error() control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
def add_uncached_torrent(self, magnet_url, pack=False): def _transfer_info(transfer_id): info = self.list_transfer() if 'status' in info and info['status'] == 'success': for item in info['transfers']: if item['id'] == transfer_id: return item return {} def _return_failed(message=control.lang(33586)): try: control.progressDialog.close() except: pass self.delete_transfer(transfer_id) control.hide() control.sleep(500) control.okDialog(title=control.lang(40018), message=message) return False control.busy() extensions = supported_video_extensions() transfer_id = self.create_transfer(magnet_url) if not transfer_id: return control.hide() if not transfer_id['status'] == 'success': return _return_failed() transfer_id = transfer_id['id'] transfer_info = _transfer_info(transfer_id) if not transfer_info: return _return_failed() # if pack: # control.hide() # control.okDialog(title='default', message=control.lang(40017) % control.lang(40057)) # return True interval = 5 line = '%s\n%s\n%s' line1 = '%s...' % (control.lang(40017) % control.lang(40057)) line2 = transfer_info['name'] line3 = transfer_info['message'] control.progressDialog.create(control.lang(40018), line % (line1, line2, line3)) while not transfer_info['status'] == 'seeding': control.sleep(1000 * interval) transfer_info = _transfer_info(transfer_id) line3 = transfer_info['message'] control.progressDialog.update(int(float(transfer_info['progress']) * 100), line % (line1, line2, line3)) if control.monitor.abortRequested(): return sysexit() try: if control.progressDialog.iscanceled(): if control.yesnoDialog('Delete PM download also?', 'No will continue the download', 'but close dialog'): return _return_failed(control.lang(40014)) else: control.progressDialog.close() control.hide() return False except: pass if transfer_info.get('status') == 'stalled': return _return_failed() control.sleep(1000 * interval) try: control.progressDialog.close() except: log_utils.error() control.hide() return True
def display_magnet_pack(self, magnet_url, info_hash): try: torrent_id = None rd_url = None match = False video_only_items = [] list_file_items = [] info_hash = info_hash.lower() extensions = supported_video_extensions() torrent_files = self.get_url(check_cache_url + '/' + info_hash) if not info_hash in torrent_files: return None torrent_id = self.create_transfer(magnet_url) if not torrent_id: return None torrent_files = torrent_files[info_hash]['rd'] for item in torrent_files: video_only = self.video_only(item, extensions) if not video_only: continue torrent_keys = item.keys() if len(torrent_keys) == 0: continue video_only_items.append(torrent_keys) video_only_items = max(video_only_items, key=len) torrent_keys = ','.join(video_only_items) self.select_file(torrent_id, torrent_keys) torrent_info = self.torrent_info(torrent_id) list_file_items = [ dict(i, **{'link': torrent_info['links'][idx]}) for idx, i in enumerate( [i for i in torrent_info['files'] if i['selected'] == 1]) ] list_file_items = [{ 'link': i['link'], 'filename': i['path'].replace('/', ''), 'size': float(i['bytes']) / 1073741824 } for i in list_file_items] self.delete_torrent(torrent_id) return list_file_items except Exception as e: if torrent_id: self.delete_torrent(torrent_id) log_utils.log( 'Real-Debrid Error: DISPLAY MAGNET PACK | %s' % str(e), __name__, log_utils.LOGDEBUG) raise
def resolve_magnet_pack(self, media_id, season, episode, ep_title): from resources.lib.modules.source_utils import seas_ep_filter, episode_extras_filter try: file_url = None correct_files = [] extensions = supported_video_extensions() extras_filtering_list = episode_extras_filter() data = {'src': media_id} response = self._post(transfer_directdl, data) if not 'status' in response or response['status'] != 'success': return None valid_results = [ i for i in response.get('content') if any(i.get('path').lower().endswith(x) for x in extensions) and not i.get('link', '') == '' ] if len(valid_results) == 0: return for item in valid_results: if seas_ep_filter( season, episode, re.sub('[^A-Za-z0-9]+', '.', unquote(item['path'].split('/')[-1])).lower()): correct_files.append(item) if len(correct_files) == 0: continue episode_title = re.sub('[^A-Za-z0-9-]+', '.', ep_title.replace('\'', '')).lower() for i in correct_files: compare_link = re.sub('[^A-Za-z0-9-]+', '.', unquote(i['path'].replace( "\'", ''))).lower() compare_link = seas_ep_filter(season, episode, compare_link, split=True) compare_link = re.sub(episode_title, '', compare_link) if not any(x in compare_link for x in extras_filtering_list): file_url = i['link'] break if file_url: return self.add_headers_to_url(file_url) except Exception as e: log_utils.log('Error resolve_magnet_pack: %s' % str(e), __name__, log_utils.LOGDEBUG) return None
def my_files_to_listItem(self, folder_id=None, folder_name=None): try: sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) extensions = supported_video_extensions() cloud_files = self.my_files(folder_id) if not cloud_files: control.notification(message='Request Failure-Empty Content') return cloud_files = [i for i in cloud_files if ('link' in i and i['link'].lower().endswith(tuple(extensions))) or i['type'] == 'folder'] cloud_files = sorted(cloud_files, key=lambda k: k['name']) cloud_files = sorted(cloud_files, key=lambda k: k['type'], reverse=True) except: log_utils.error() return folder_str, file_str, downloadMenu, renameMenu, deleteMenu = control.lang(40046).upper(), control.lang(40047).upper(), control.lang(40048), control.lang(40049), control.lang(40050) for count, item in enumerate(cloud_files, 1): try: cm = [] type = item['type'] name = control.strip_non_ascii_and_unprintable(item['name']) if type == 'folder': isFolder = True size = 0 label = '%02d | [B]%s[/B] | [I]%s [/I]' % (count, folder_str, name) url = '%s?action=pm_MyFiles&id=%s&name=%s' % (sysaddon, item['id'], quote_plus(name)) else: isFolder = False url_link = item['link'] if url_link.startswith('/'): url_link = 'https' + url_link size = item['size'] display_size = float(int(size))/1073741824 label = '%02d | [B]%s[/B] | %.2f GB | [I]%s [/I]' % (count, file_str, display_size, name) url = '%s?action=playURL&url=%s' % (sysaddon, url_link) cm.append((downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&url=%s&caller=premiumize)' % (sysaddon, quote_plus(name), quote_plus(pm_icon), url_link))) cm.append((renameMenu % type.capitalize(), 'RunPlugin(%s?action=pm_Rename&type=%s&id=%s&name=%s)' % (sysaddon, type, item['id'], quote_plus(name)))) cm.append((deleteMenu % type.capitalize(), 'RunPlugin(%s?action=pm_Delete&type=%s&id=%s&name=%s)' % (sysaddon, type, item['id'], quote_plus(name)))) item = control.item(label=label) item.addContextMenuItems(cm) item.setArt({'icon': pm_icon, 'poster': pm_icon, 'thumb': pm_icon, 'fanart': addonFanart, 'banner': pm_icon}) item.setInfo(type='video', infoLabels='') video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=isFolder) except: log_utils.error() pass control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
def my_downloads_to_listItem(self, page): try: from datetime import datetime import time sysaddon, syshandle = argv[0], int(argv[1]) my_downloads, pages = self.downloads(page) except: my_downloads = None if not my_downloads: return extensions = supported_video_extensions() my_downloads = [i for i in my_downloads if i['download'].lower().endswith(tuple(extensions))] downloadMenu, deleteMenu = getLS(40048), getLS(40050) for count, item in enumerate(my_downloads, 1): if page > 1: count += (page-1) * 50 try: cm = [] try: datetime_object = datetime.strptime(item['generated'], FormatDateTime).date() except TypeError: datetime_object = datetime(*(time.strptime(item['generated'], FormatDateTime)[0:6])).date() name = string_tools.strip_non_ascii_and_unprintable(item['filename']) size = float(int(item['filesize'])) / 1073741824 label = '%02d | %.2f GB | %s | [I]%s [/I]' % (count, size, datetime_object, name) url_link = item['download'] url = '%s?action=play_URL&url=%s' % (sysaddon, url_link) cm.append((downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&url=%s&caller=realdebrid)' % (sysaddon, quote_plus(name), quote_plus(rd_icon), url_link))) cm.append((deleteMenu % 'File', 'RunPlugin(%s?action=rd_DeleteDownload&id=%s&name=%s)' % (sysaddon, item['id'], name))) item = control.item(label=label, offscreen=True) item.addContextMenuItems(cm) item.setArt({'icon': rd_icon, 'poster': rd_icon, 'thumb': rd_icon, 'fanart': addonFanart, 'banner': rd_icon}) item.setInfo(type='video', infoLabels='') control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) except: log_utils.error() if page < pages: page += 1 next = True else: next = False if next: try: nextMenu = getLS(32053) url = '%s?action=rd_MyDownloads&query=%s' % (sysaddon, page) page = ' [I](%s)[/I]' % page nextMenu = '[COLOR skyblue]' + nextMenu + page + '[/COLOR]' item = control.item(label=nextMenu, offscreen=True) icon = control.addonNext() item.setArt({'icon': rd_icon, 'poster': rd_icon, 'thumb': rd_icon, 'fanart': addonFanart, 'banner': rd_icon}) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: log_utils.error() control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
def create_transfer(self, magnet_url): try: extensions = supported_video_extensions() torrent_id = self.add_magnet(magnet_url) info = self.torrent_info(torrent_id) files = info['files'] torrent_keys = [str(item['id']) for item in files if item['path'].lower().endswith(tuple(extensions))] torrent_keys = ','.join(torrent_keys) self.add_torrent_select(torrent_id, torrent_keys) return 'success' except: log_utils.error() self.delete_torrent(torrent_id) return 'failed'
def display_magnet_pack(self, magnet_url, info_hash): try: extensions = supported_video_extensions() transfer_id = self.create_transfer(magnet_url) transfer_info = self.list_transfer(transfer_id) end_results = [] for item in transfer_info.get('links'): if any(item.get('filename').lower().endswith(x) for x in extensions) and not item.get('link', '') == '': end_results.append({'link': item['link'], 'filename': item['filename'], 'size': item['size']}) self.delete_transfer(transfer_id) return end_results except: log_utils.error() if transfer_id: self.delete_transfer(transfer_id) return None
def browse_user_torrents(self, folder_id): try: sysaddon, syshandle = argv[0], int(argv[1]) torrent_files = self.torrent_info(folder_id) except: return extensions = supported_video_extensions() try: file_info = [i for i in torrent_files['files'] if i['path'].lower().endswith(tuple(extensions))] file_urls = torrent_files['links'] for c, i in enumerate(file_info): try: i.update({'url_link': file_urls[c]}) except: pass pack_info = sorted(file_info, key=lambda k: k['path']) except: if self.server_notifications: control.notification(message='Real-Debrid Error: browse_user_torrents failed', icon=rd_icon) log_utils.log('Real-Debrid Error: browse_user_torrents failed', __name__, log_utils.LOGWARNING) return file_str, downloadMenu, renameMenu, deleteMenu, clearFinishedMenu = \ getLS(40047).upper(), getLS(40048), getLS(40049), getLS(40050), getLS(40051) for count, item in enumerate(pack_info, 1): try: cm = [] try: url_link = item['url_link'] except: continue if url_link.startswith('/'): url_link = 'http' + url_link name = item['path'] if name.startswith('/'): name = name.split('/')[-1] size = float(int(item['bytes'])) / 1073741824 label = '%02d | [B]%s[/B] | %.2f GB | [I]%s [/I]' % (count, file_str, size, name) url = '%s?action=play_URL&url=%s&caller=realdebrid&type=unrestrict' % (sysaddon, url_link) cm.append((downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&url=%s&caller=realdebrid&type=unrestrict)' % (sysaddon, quote_plus(name), quote_plus(rd_icon), url_link))) cm.append((deleteMenu % 'Torrent', 'RunPlugin(%s?action=rd_DeleteUserTorrent&id=%s&name=%s)' % (sysaddon, item['id'], quote_plus(name)))) item = control.item(label=label, offscreen=True) item.addContextMenuItems(cm) item.setArt({'icon': rd_icon, 'poster': rd_icon, 'thumb': rd_icon, 'fanart': addonFanart, 'banner': rd_icon}) item.setInfo(type='video', infoLabels='') control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) except: log_utils.error() control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
def resolve_magnet_pack(self, media_id, info_hash, season, episode, ep_title): from resources.lib.modules.source_utils import seas_ep_filter, episode_extras_filter try: info_hash = info_hash.lower() torrent_id = None rd_url = None match = False extensions = supported_video_extensions() extras_filtering_list = episode_extras_filter() info_hash = info_hash.lower() torrent_files = self._get(check_cache_url + '/' + info_hash) if not info_hash in torrent_files: return None torrent_id = self.create_transfer(media_id) torrent_files = torrent_files[info_hash]['rd'] for item in torrent_files: video_only = self.video_only(item, extensions) if not video_only: continue correct_file_check = False item_values = [i['filename'] for i in item.values()] for value in item_values: correct_file_check = seas_ep_filter( season, episode, re.sub('[^A-Za-z0-9]+', '.', unquote(value)).lower()) if correct_file_check: break if not correct_file_check: continue torrent_keys = item.keys() if len(torrent_keys) == 0: continue torrent_keys = ','.join(torrent_keys) self.select_file(torrent_id, torrent_keys) torrent_info = self.torrent_info(torrent_id) selected_files = [(idx, i) for idx, i in enumerate( [i for i in torrent_info['files'] if i['selected'] == 1])] correct_files = [] correct_file_check = False for value in selected_files: checker = re.sub('[^A-Za-z0-9]+', '.', unquote(value[1]['path'])).lower() correct_file_check = seas_ep_filter( season, episode, checker) if correct_file_check: correct_files.append(value[1]) break if len(correct_files) == 0: continue episode_title = re.sub('[^A-Za-z0-9-]+', '.', ep_title.replace("\'", '')).lower() for i in correct_files: compare_link = re.sub('[^A-Za-z0-9-]+', '.', unquote(i['path'].replace( "\'", ''))).lower() compare_link = seas_ep_filter(season, episode, compare_link, split=True) compare_link = re.sub(episode_title, '', compare_link) if any(x in compare_link for x in extras_filtering_list): continue else: match = True break if match: index = [ i[0] for i in selected_files if i[1]['path'] == correct_files[0]['path'] ][0] rd_link = torrent_info['links'][index] rd_url = self.unrestrict_link(rd_link) # should we be deleting torrents? isn't this our cloud account? self.delete_torrent(torrent_id) return rd_url self.delete_torrent(torrent_id) except Exception as e: if torrent_id: self.delete_torrent(torrent_id) log_utils.log('Real-Debrid Error: RESOLVE MAGNET PACK | %s' % e, __name__, log_utils.LOGDEBUG) raise
def add_uncached_torrent(self, magnet_url, pack=False): def _return_failed(message=control.lang(33586)): try: control.progressDialog.close() except: pass self.delete_torrent(torrent_id) control.hide() control.sleep(500) control.okDialog(title=control.lang(40018), message=message) return False control.busy() try: active_count = self.torrents_activeCount() if active_count['nb'] >= active_count['limit']: return _return_failed() except: pass interval = 5 stalled = ['magnet_error', 'error', 'virus', 'dead'] extensions = supported_video_extensions() torrent = self.add_magnet(magnet_url) # if not transfer_id: # check if this is needed # control.hide() # return torrent_id = torrent['id'] if not torrent_id: return _return_failed() torrent_info = self.torrent_info(torrent_id) if 'error_code' in torrent_info: # log_utils.log('torrent_info = %s' % torrent_info, __name__, log_utils.LOGDEBUG) return _return_failed() status = torrent_info['status'] if status == 'magnet_conversion': line1 = control.lang(40013) line2 = torrent_info['filename'] line3 = control.lang(40012) % str(torrent_info['seeders']) timeout = 100 control.progressDialog.create(control.lang(40018), line1, line2, line3) while status == 'magnet_conversion' and timeout > 0: control.progressDialog.update(timeout, line3=line3) if control.monitor.abortRequested(): return sys.exit() try: if control.progressDialog.iscanceled(): return _return_failed(control.lang(40014)) except: pass if any(x in status for x in stalled): return _return_failed() timeout -= interval control.sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] line3 = control.lang(40012) % str(torrent_info['seeders']) try: control.progressDialog.close() except: pass if status == 'magnet_conversion': return _return_failed() if status == 'waiting_files_selection': video_files = [] all_files = torrent_info['files'] for item in all_files: if any(item['path'].lower().endswith(x) for x in extensions): video_files.append(item) if pack: try: if len(video_files) == 0: return _return_failed() video_files = sorted(video_files, key=lambda x: x['path']) torrent_keys = [str(i['id']) for i in video_files] if not torrent_keys: return _return_failed(control.lang(40014)) torrent_keys = ','.join(torrent_keys) self.select_file(torrent_id, torrent_keys) control.okDialog(title='default', message=control.lang(40017) % control.lang(40058)) # self.clear_cache() control.hide() return True except: return _return_failed() else: try: video = max(video_files, key=lambda x: x['bytes']) file_id = video['id'] except ValueError: return _return_failed() self.select_file(torrent_id, str(file_id)) control.sleep(2000) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloaded': return True file_size = round(float(video['bytes']) / (1000**3), 2) line1 = '%s...' % (control.lang(40017) % control.lang(40058)) line2 = torrent_info['filename'] line3 = status control.progressDialog.create(ls(40018), line1, line2, line3) while not status == 'downloaded': control.sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloading': line3 = control.lang(40011) % ( file_size, round(float(torrent_info['speed']) / (1000**2), 2), torrent_info['seeders'], torrent_info['progress']) else: line3 = status control.progressDialog.update(int( float(torrent_info['progress'])), line3=line3) if control.monitor.abortRequested(): return sys.exit() try: if control.progressDialog.iscanceled(): return _return_failed(control.lang(40011)) except: pass if any(x in status for x in stalled): return _return_failed() try: control.progressDialog.close() except Exception: pass control.hide() return True control.hide() return False
def sources(self, data, hostDict): sources = [] if not data: return sources try: title = data['tvshowtitle'] if 'tvshowtitle' in data else data[ 'title'] title = title.replace('&', 'and').replace('Special Victims Unit', 'SVU') aliases = data['aliases'] episode_title = data['title'] if 'tvshowtitle' in data else None self.year = data['year'] hdlr = 'S%02dE%02d' % (int(data['season']), int( data['episode'])) if 'tvshowtitle' in data else self.year self.season = str( data['season']) if 'tvshowtitle' in data else None self.episode = str( data['episode']) if 'tvshowtitle' in data else None query_list = self.episode_query_list( ) if 'tvshowtitle' in data else self.year_query_list() # log_utils.log('query_list = %s' % query_list) cloud_files = premiumize.Premiumize().my_files_all() if not cloud_files: return sources cloud_files = [ i for i in cloud_files if i['path'].lower().endswith( tuple(supported_video_extensions())) ] # this only lets folder names thru with known video extensions..? if not cloud_files: return sources ignoreM2ts = getSetting('pm_cloud.ignore.m2ts') == 'true' extras_filter = cloud_utils.extras_filter() except: from resources.lib.modules import log_utils log_utils.error('PM_CLOUD: ') return sources for item in cloud_files: is_m2ts = False try: name = item.get('name', '') invalids = ('.img', '.bin', '.dat', '.mpls', '.mpl', '.bdmv', '.bdm', '.disc') if name.lower().endswith(invalids): continue path = item.get('path', '').lower() if not cloud_utils.cloud_check_title(title, aliases, path): continue rt = cloud_utils.release_title_format(name) if any(value in rt for value in extras_filter): continue if name.endswith('m2ts'): if ignoreM2ts: continue name = item.get('path', '').split('/')[0] if name in str(sources): continue if all(not bool(re.search(i, rt)) for i in query_list): continue # check if this newly added causes any movie titles that do not have the year to get dropped is_m2ts = True m2ts_files = [ i for i in cloud_files if name in i.get('path') ] largest = sorted(m2ts_files, key=lambda k: k['size'], reverse=True)[0] url_id = largest.get('id', '') size = largest.get('size', '') else: if all(not bool(re.search(i, rt)) for i in query_list): if 'tvshowtitle' in data: season_folder_list = self.season_folder_list() if all(not bool(re.search(i, path)) for i in season_folder_list): continue episode_list = self.episode_list() if all(not bool(re.search(i, rt)) for i in episode_list): continue else: if all(not bool(re.search(i, path)) for i in query_list): continue name = item.get('path', '').split('/')[0] if item.get('size') < 52428800: continue url_id = item.get('id', '') size = item.get('size', '') name_info = fs_utils.info_from_name(name, title, self.year, hdlr, episode_title) quality, info = fs_utils.get_release_quality(name_info, name) try: dsize, isize = fs_utils.convert_size(size, to='GB') info.insert(0, isize) except: dsize = 0 if is_m2ts: info.append('M2TS') info = ' | '.join(info) sources.append({ 'provider': 'pm_cloud', 'source': 'cloud', 'debrid': 'Premiumize.me', 'seeders': '', 'hash': '', 'name': name, 'name_info': name_info, 'quality': quality, 'language': 'en', 'url': url_id, 'info': info, 'direct': True, 'debridonly': True, 'size': dsize }) except: from resources.lib.modules import log_utils log_utils.error('PM_CLOUD: ') return sources return sources
def sources(self, data, hostDict): sources = [] if not data: return sources try: title = data['tvshowtitle'] if 'tvshowtitle' in data else data['title'] title = title.replace('&', 'and').replace('Special Victims Unit', 'SVU') aliases = data['aliases'] episode_title = data['title'] if 'tvshowtitle' in data else None self.year = data['year'] hdlr = 'S%02dE%02d' % (int(data['season']), int(data['episode'])) if 'tvshowtitle' in data else self.year self.season = str(data['season']) if 'tvshowtitle' in data else None self.episode = str(data['episode']) if 'tvshowtitle' in data else None query_list = self.episode_query_list() if 'tvshowtitle' in data else self.year_query_list() # log_utils.log('query_list = %s' % query_list) cloud_folders = realdebrid.RealDebrid().user_torrents() if not cloud_folders: return sources cloud_folders = [i for i in cloud_folders if i['status'] == 'downloaded'] if not cloud_folders: return sources ignoreM2ts = getSetting('rd_cloud.ignore.m2ts') == 'true' extras_filter = cloud_utils.extras_filter() except: from resources.lib.modules import log_utils log_utils.error('RD_CLOUD: ') return sources for folder in cloud_folders: is_m2ts = False try: folder_name = folder.get('filename', '') if not cloud_utils.cloud_check_title(title, aliases, folder_name): continue id = folder.get('id', '') torrent_info = realdebrid.RealDebrid().torrent_info(id) folder_files = torrent_info['files'] folder_files = [i for i in folder_files if i['selected'] == 1] except: from resources.lib.modules import log_utils log_utils.error('RD_CLOUD: ') return sources for file in folder_files: try: name = file.get('path').lstrip('/') rt = cloud_utils.release_title_format(name) if not name.lower().endswith(tuple(supported_video_extensions())): continue if any(value in rt for value in extras_filter): continue if name.endswith('m2ts'): if ignoreM2ts: continue name = folder_name rt = cloud_utils.release_title_format(name) if name in str(sources): continue if all(not bool(re.search(i, rt)) for i in query_list): continue # check if this newly added causes any movie titles that do not have the year to get dropped is_m2ts = True largest = sorted(folder_files, key=lambda k: k['bytes'], reverse=True)[0] index_pos = folder_files.index(largest) size = largest['bytes'] try: link = torrent_info['links'][index_pos] except: link = torrent_info['links'][0] else: if all(not bool(re.search(i, rt)) for i in query_list): if 'tvshowtitle' in data: season_folder_list = self.season_folder_list() nl = name.lower() if all(not bool(re.search(i, nl)) for i in season_folder_list): continue episode_list = self.episode_list() if all(not bool(re.search(i, rt)) for i in episode_list): continue else: if all(not bool(re.search(i, folder_name)) for i in query_list): continue name = folder_name if file.get('bytes') < 52428800: continue name = name.split('/') name = name[len(name)-1] index_pos = folder_files.index(file) link = torrent_info['links'][index_pos] size = file.get('bytes', '') name_info = fs_utils.info_from_name(name, title, self.year, hdlr, episode_title) hash = folder.get('hash', '') quality, info = fs_utils.get_release_quality(name_info, name) try: dsize, isize = fs_utils.convert_size(size, to='GB') info.insert(0, isize) except: dsize = 0 if is_m2ts: info.append('M2TS') info = ' / '.join(info) sources.append({'provider': 'rd_cloud', 'source': 'cloud', 'debrid': 'Real-Debrid', 'seeders': '', 'hash': hash, 'name': name, 'name_info': name_info, 'quality': quality, 'language': 'en', 'url': link, 'info': info, 'direct': True, 'debridonly': True, 'size': dsize}) except: from resources.lib.modules import log_utils log_utils.error('RD_CLOUD: ') return sources return sources
def resolve_magnet(self, magnet_url, info_hash, season, episode, ep_title): from resources.lib.modules.source_utils import seas_ep_filter, extras_filter try: file_url = None media_id = None failed_reason = 'Unknown' correct_files = [] extensions = supported_video_extensions() extras_filtering_list = extras_filter() transfer_id = self.create_transfer(magnet_url) transfer_info = self.list_transfer(transfer_id) # log_utils.log('transfer_info=%s' % transfer_info) # valid_results = [i for i in transfer_info.get('links') if any(i.get('filename').lower().endswith(x) for x in extensions) and not i.get('link', '') == ''] #.m2ts file extension is not in "filename" so this fails invalids = [ '.rar', '.zip', '.iso', '.part', '.png', '.jpg', '.bmp', '.gif', '.txt' ] valid_results = [ i for i in transfer_info.get('links') if not any( i.get('filename').lower().endswith(x) for x in invalids) and not i.get('link', '') == '' ] if len(valid_results) == 0: failed_reason = 'No valid video extension found' raise Exception() if season: for item in valid_results: if '.m2ts' in str(item.get('files')): log_utils.log( 'AllDebrid: Can not resolve .m2ts season disk episode', level=log_utils.LOGDEBUG) failed_reason = '.m2ts season disk incapable of determining episode' continue if seas_ep_filter(season, episode, item['filename']): correct_files.append(item) if len(correct_files) == 0: failed_reason = 'no matching episode found' continue episode_title = re.sub(r'[^A-Za-z0-9-]+', '.', ep_title.replace('\'', '')).lower() for i in correct_files: compare_link = seas_ep_filter(season, episode, i['filename'], split=True) compare_link = re.sub(episode_title, '', compare_link) if not any(x in compare_link for x in extras_filtering_list): media_id = i['link'] break else: media_id = max(valid_results, key=lambda x: x.get('size')).get('link', None) # log_utils.log('media_id=%s' % media_id) if not self.store_to_cloud: self.delete_transfer(transfer_id) if not media_id: log_utils.log( 'AllDebrid: FAILED TO RESOLVE MAGNET %s : (%s)' % (magnet_url, failed_reason), __name__, log_utils.LOGWARNING) return None file_url = self.unrestrict_link(media_id) if not file_url: log_utils.log( 'AllDebrid: FAILED TO UNRESTRICT MAGNET %s : ' % magnet_url, __name__, log_utils.LOGWARNING) return file_url except: if failed_reason != 'Unknown': log_utils.log('AllDebrid: Error RESOLVE MAGNET %s : (%s)' % (magnet_url, failed_reason)) else: log_utils.error('AllDebrid: Error RESOLVE MAGNET %s : ' % magnet_url) if transfer_id: self.delete_transfer(transfer_id) return None
def browse_user_cloud(self, folder): sysaddon, syshandle = argv[0], int(argv[1]) extensions = supported_video_extensions() torrent_folder = jsloads(folder) links = torrent_folder['links'] # links = [i for i in links if i['filename'].lower().endswith(tuple(extensions))] status_code = torrent_folder['statusCode'] file_str, downloadMenu, deleteMenu = getLS(40047).upper(), getLS( 40048), getLS(40050) for count, item in enumerate(links, 1): try: cm = [] url_link = item['link'] name = string_tools.strip_non_ascii_and_unprintable( item['filename']) if name.lower().endswith(invalid_extensions): continue if not name.lower().endswith(tuple(extensions)): files = item['files'] entry = files[0].get('e') name = entry[0].get('n') if isinstance( entry, list) else entry.get('n') def entry_loop(entry): entry = entry.get('e') name = entry[0].get('n') if isinstance( entry, list) else entry.get('n') if not name.lower().endswith(tuple(extensions)): return entry_loop(entry) else: return string_tools.strip_non_ascii_and_unprintable( name) if not name.lower().endswith(tuple(extensions)): name = entry_loop(entry) size = item['size'] display_size = float(int(size)) / 1073741824 label = '%02d | [B]%s[/B] | %.2f GB | [I]%s [/I]' % ( count, file_str, display_size, name) if status_code == 4: url = '%s?action=play_URL&url=%s&caller=alldebrid&type=unrestrict' % ( sysaddon, url_link) else: url = '' cm.append(( downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&url=%s&caller=alldebrid)' % (sysaddon, quote_plus(name), quote_plus(ad_icon), url_link))) item = control.item(label=label, offscreen=True) item.addContextMenuItems(cm) item.setArt({ 'icon': ad_icon, 'poster': ad_icon, 'thumb': ad_icon, 'fanart': addonFanart, 'banner': ad_icon }) item.setInfo(type='video', infoLabels='') control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) except: log_utils.error() control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
''' import sys import json import requests try: from urllib import quote_plus except: from urllib.parse import quote_plus from resources.lib.modules import control from resources.lib.modules import log_utils from resources.lib.modules.source_utils import supported_video_extensions accepted_extensions = tuple(supported_video_extensions()) class Furk: def __init__(self): self.base_link = "https://www.furk.net" self.account_info_link = "/api/account/info?api_key=%s" # self.search_link = "/api/plugins/metasearch?api_key=%s&q=%s" self.search_link = "/api/plugins/metasearch?api_key=%s&q=%s&cached=all" \ "&sort=cached&type=video&offset=0&limit=200" # self.search_link = "/api/plugins/metasearch?api_key=%s&q=%s&cached=all" \ # "&match=%s&moderated=%s%s&sort=relevance&type=video&offset=0&limit=200" # self.get_user_files_link = "/api/file/get?api_key=%s" self.get_user_files_link = "/api/file/get?api_key=%s&type=video" self.file_info_link = "/api/file/info?api_key%s"
def resolve_magnet(self, magnet_url, info_hash, season, episode, ep_title): from resources.lib.modules.source_utils import seas_ep_filter, episode_extras_filter try: torrent_id = None rd_url = None match = False extensions = supported_video_extensions() extras_filtering_list = episode_extras_filter() info_hash = info_hash.lower() torrent_files = self._get(check_cache_url + '/' + info_hash) if not info_hash in torrent_files: return None torrent_id = self.add_magnet(magnet_url) torrent_info = self.torrent_info(torrent_id) torrent_files = torrent_files[info_hash]['rd'] for item in torrent_files: try: video_only = self.video_only(item, extensions) if not video_only: continue if season: correct_file_check = False item_values = [i['filename'] for i in item.values()] for value in item_values: correct_file_check = seas_ep_filter( season, episode, value) if correct_file_check: break if not correct_file_check: continue torrent_keys = item.keys() if len(torrent_keys) == 0: continue torrent_keys = ','.join(torrent_keys) self.add_torrent_select(torrent_id, torrent_keys) torrent_info = self.torrent_info(torrent_id) status = torrent_info.get('status') if 'error' in torrent_info: continue selected_files = [(idx, i) for idx, i in enumerate([ i for i in torrent_info['files'] if i['selected'] == 1 ])] if season: correct_files = [] correct_file_check = False for value in selected_files: correct_file_check = seas_ep_filter( season, episode, value[1]['path']) if correct_file_check: correct_files.append(value[1]) break if len(correct_files) == 0: continue episode_title = re.sub(r'[^A-Za-z0-9-]+', '.', ep_title.replace("\'", '')).lower() for i in correct_files: compare_link = seas_ep_filter(season, episode, i['path'], split=True) compare_link = re.sub(episode_title, '', compare_link) if any(x in compare_link for x in extras_filtering_list): continue else: match = True break if match: index = [ i[0] for i in selected_files if i[1]['path'] == correct_files[0]['path'] ][0] break else: match, index = True, 0 except: log_utils.error() if match: rd_link = torrent_info['links'][index] rd_url = self.unrestrict_link(rd_link) if rd_url.endswith('rar'): rd_url = None if not store_to_cloud: self.delete_torrent(torrent_id) return rd_url self.delete_torrent(torrent_id) except Exception as e: if torrent_id: self.delete_torrent(torrent_id) log_utils.log( 'Real-Debrid Error: RESOLVE MAGNET %s | %s' % (magnet_url, e), __name__, log_utils.LOGDEBUG) return None
def add_uncached_torrent(self, magnet_url, pack=False): def _return_failed(message=getLS(33586)): try: control.progressDialog.close() except: pass self.delete_torrent(torrent_id) control.hide() control.sleep(500) control.okDialog(title=getLS(40018), message=message) return False control.busy() try: active_count = self.torrents_activeCount() if active_count['nb'] >= active_count['limit']: return _return_failed() except: pass interval = 5 stalled = ['magnet_error', 'error', 'virus', 'dead'] extensions = supported_video_extensions() torrent_id = self.add_magnet(magnet_url) if not torrent_id: return _return_failed() torrent_info = self.torrent_info(torrent_id) if 'error_code' in torrent_info: return _return_failed() status = torrent_info['status'] line = '%s\n%s\n%s' if status == 'magnet_conversion': line1 = getLS(40013) line2 = torrent_info['filename'] line3 = getLS(40012) % str(torrent_info['seeders']) timeout = 100 control.progressDialog.create(getLS(40018), line % (line1, line2, line3)) while status == 'magnet_conversion' and timeout > 0: control.progressDialog.update(timeout, line % (line1, line2, line3)) if control.monitor.abortRequested(): return sysexit() try: if control.progressDialog.iscanceled(): return _return_failed(getLS(40014)) except: pass timeout -= interval control.sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if any(x in status for x in stalled): return _return_failed() line3 = getLS(40012) % str(torrent_info['seeders']) try: control.progressDialog.close() except: pass if status == 'downloaded': control.busy() return True if status == 'magnet_conversion': return _return_failed() if any(x in status for x in stalled): return _return_failed(status) if status == 'waiting_files_selection': video_files = [] append = video_files.append all_files = torrent_info['files'] for item in all_files: if any(item['path'].lower().endswith(x) for x in extensions): append(item) if pack: try: if len(video_files) == 0: return _return_failed() video_files.sort(key=lambda x: x['path']) torrent_keys = [str(i['id']) for i in video_files] if not torrent_keys: return _return_failed(getLS(40014)) torrent_keys = ','.join(torrent_keys) self.add_torrent_select(torrent_id, torrent_keys) control.okDialog(title='default', message=getLS(40017) % getLS(40058)) control.hide() return True # returning true here causes "success" to be returned and resolve runs on non valid link except: return _return_failed() else: try: video = max(video_files, key=lambda x: x['bytes']) file_id = video['id'] except ValueError: return _return_failed() self.add_torrent_select(torrent_id, str(file_id)) control.sleep(2000) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloaded': control.hide() control.notification(message=getLS(32057), icon=rd_icon) return True file_size = round(float(video['bytes']) / (1000 ** 3), 2) line1 = '%s...' % (getLS(40017) % getLS(40058)) line2 = torrent_info['filename'] line3 = status control.progressDialog.create(getLS(40018), line % (line1, line2, line3)) while not status == 'downloaded': control.sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloading': line3 = getLS(40011) % (file_size, round(float(torrent_info['speed']) / (1000**2), 2), torrent_info['seeders'], torrent_info['progress']) else: line3 = status control.progressDialog.update(int(float(torrent_info['progress'])), line % (line1, line2, line3)) if control.monitor.abortRequested(): return sysexit() try: if control.progressDialog.iscanceled(): if control.yesnoDialog('Delete RD download also?', 'No will continue the download', 'but close dialog'): return _return_failed(getLS(40014)) else: control.progressDialog.close() control.hide() return False except: pass if any(x in status for x in stalled): return _return_failed() try: control.progressDialog.close() except: pass control.hide() return True control.hide() return False
def resolve_magnet(self, magnet_url, info_hash, season, episode, title): from resources.lib.modules.source_utils import seas_ep_filter, extras_filter try: torrent_id = None rd_url = None match = False extensions = supported_video_extensions() extras_filtering_list = extras_filter() info_hash = info_hash.lower() torrent_files = self._get(check_cache_url + '/' + info_hash) if not info_hash in torrent_files: return None torrent_id = self.add_magnet(magnet_url) # add_magent() returns id torrent_files = torrent_files[info_hash]['rd'] torrent_files = [ item for item in torrent_files if self.video_only(item, extensions) ] # log_utils.log('torrent_files=%s' % torrent_files) if not season: m2ts_check = self.m2ts_check(torrent_files) if m2ts_check: m2ts_key, torrent_files = self.m2ts_key_value( torrent_files) for item in torrent_files: try: correct_file_check = False item_values = [i['filename'] for i in item.values()] if season: for value in item_values: correct_file_check = seas_ep_filter( season, episode, value) # log_utils.log('correct_file_check=%s' % correct_file_check) if correct_file_check: break if not correct_file_check: continue elif not m2ts_check: compare_title = re.sub(r'[^A-Za-z0-9]+', '.', title.replace('\'', '')).lower() for value in item_values: filename = re.sub(r'[^A-Za-z0-9]+', '.', value.replace('\'', '')).lower() if any(x in filename for x in extras_filtering_list): continue correct_file_check = re.search( compare_title, filename) if correct_file_check: break if not correct_file_check: continue torrent_keys = item.keys() if len(torrent_keys) == 0: continue torrent_keys = ','.join(torrent_keys) self.add_torrent_select(torrent_id, torrent_keys) torrent_info = self.torrent_info(torrent_id) if 'error' in torrent_info: continue selected_files = [(idx, i) for idx, i in enumerate([ i for i in torrent_info['files'] if i['selected'] == 1 ])] if season: correct_files = [] correct_file_check = False for value in selected_files: correct_file_check = seas_ep_filter( season, episode, value[1]['path']) # log_utils.log('correct_file_check=%s' % correct_file_check) if correct_file_check: correct_files.append(value[1]) break if len(correct_files) == 0: continue # episode_title = re.sub(r'[^A-Za-z0-9-]+', '.', title.replace("\'", '')).lower() episode_title = re.sub(r'[^A-Za-z0-9]+', '.', title.replace("\'", '')).lower() for i in correct_files: compare_link = seas_ep_filter(season, episode, i['path'], split=True) # log_utils.log('compare_link=%s' % compare_link) compare_link = re.sub(episode_title, '', compare_link) if any(x in compare_link for x in extras_filtering_list): continue else: match = True break if match: index = [ i[0] for i in selected_files if i[1]['path'] == correct_files[0]['path'] ][0] break elif m2ts_check: match, index = True, [ i[0] for i in selected_files if i[1]['id'] == m2ts_key ][0] else: match = False compare_title = re.sub(r'[^A-Za-z0-9]+', '.', title.replace('\'', '')).lower() for value in selected_files: filename = re.sub( r'[^A-Za-z0-9]+', '.', value[1]['path'].replace('\'', '')).lower() if any(x in filename for x in extras_filtering_list): continue match = re.search(compare_title, filename) if match: index = value[0] break if match: break except: log_utils.error() if match: rd_link = torrent_info['links'][index] file_url = self.unrestrict_link(rd_link) if file_url.endswith('rar'): file_url = None if not any(file_url.lower().endswith(x) for x in extensions): file_url = None if not store_to_cloud: self.delete_torrent(torrent_id) return file_url else: log_utils.log( 'Real-Debrid FAILED TO RESOLVE MAGNET : %s' % magnet_url, __name__, log_utils.LOGWARNING) self.delete_torrent(torrent_id) except: log_utils.error('Real-Debrid Error RESOLVE MAGNET %s : ' % magnet_url) if torrent_id: self.delete_torrent(torrent_id) return None
def resolve_magnet(self, magnet_url, info_hash, season, episode, title): from resources.lib.modules.source_utils import seas_ep_filter, extras_filter from resources.lib.cloud_scrapers.cloud_utils import cloud_check_title try: torrent_id = None rd_url = None match = False reason = '' extensions = supported_video_extensions() extras_filtering_list = extras_filter() info_hash = info_hash.lower() if not season: compare_title = re.sub(r'[^A-Za-z0-9]+', '.', title.replace('\'', '').replace('&', 'and').replace('%', '.percent')).lower() torrent_files = self._get(check_cache_url + '/' + info_hash) if not info_hash in torrent_files: return None torrent_id = self.add_magnet(magnet_url) # add_magent() returns id torrent_files = torrent_files[info_hash]['rd'] torrent_files = [item for item in torrent_files if self.video_only(item, extensions)] if not season: m2ts_check = self.m2ts_check(torrent_files) if m2ts_check: m2ts_key, torrent_files = self.m2ts_key_value(torrent_files) for item in torrent_files: try: correct_file_check = False item_values = [i['filename'] for i in item.values()] if season: for value in item_values: if '.m2ts' in value: log_utils.log('Real-Debrid: Can not resolve .m2ts season disk episode', level=log_utils.LOGDEBUG) continue correct_file_check = seas_ep_filter(season, episode, value) if correct_file_check: break if not correct_file_check: reason = value + ' :no matching video filename' continue elif not m2ts_check: for value in item_values: filename = re.sub(r'[^A-Za-z0-9]+', '.', value.replace('\'', '').replace('&', 'and').replace('%', '.percent')).lower() filename_info = filename.replace(compare_title, '') if any(x in filename_info for x in extras_filtering_list): continue aliases = self.get_aliases(title) correct_file_check = cloud_check_title(title, aliases, filename) if correct_file_check: break if not correct_file_check: reason = filename + ' :no matching video filename' continue torrent_keys = item.keys() if len(torrent_keys) == 0: continue torrent_keys = ','.join(torrent_keys) self.add_torrent_select(torrent_id, torrent_keys) torrent_info = self.torrent_info(torrent_id) if 'error' in torrent_info: continue selected_files = [(idx, i) for idx, i in enumerate([i for i in torrent_info['files'] if i['selected'] == 1])] if season: correct_files = [] append = correct_files.append correct_file_check = False for value in selected_files: correct_file_check = seas_ep_filter(season, episode, value[1]['path']) if correct_file_check: append(value[1]) break if len(correct_files) == 0: continue episode_title = re.sub(r'[^A-Za-z0-9]+', '.', title.replace("\'", '').replace('&', 'and').replace('%', '.percent')).lower() for i in correct_files: compare_link = seas_ep_filter(season, episode, i['path'], split=True) compare_link = re.sub(episode_title, '', compare_link) if any(x in compare_link for x in extras_filtering_list): continue else: match = True break if match: index = [i[0] for i in selected_files if i[1]['path'] == correct_files[0]['path']][0] break elif m2ts_check: match, index = True, [i[0] for i in selected_files if i[1]['id'] == m2ts_key][0] else: match = False for value in selected_files: filename = re.sub(r'[^A-Za-z0-9]+', '.', value[1]['path'].rsplit('/', 1)[1].replace('\'', '').replace('&', 'and').replace('%', '.percent')).lower() filename_info = filename.replace(compare_title, '') if any(x in filename_info for x in extras_filtering_list): continue aliases = self.get_aliases(title) match = cloud_check_title(title, aliases, filename) if match: index = value[0] break if match: break except: log_utils.error() if match: rd_link = torrent_info['links'][index] file_url = self.unrestrict_link(rd_link) if file_url.endswith('rar'): file_url = None if not any(file_url.lower().endswith(x) for x in extensions): file_url = None if not self.store_to_cloud: self.delete_torrent(torrent_id) return file_url else: log_utils.log('Real-Debrid: FAILED TO RESOLVE MAGNET : "%s": %s' % (magnet_url, reason), __name__, log_utils.LOGWARNING) self.delete_torrent(torrent_id) except: log_utils.error('Real-Debrid: Error RESOLVE MAGNET %s : ' % magnet_url) if torrent_id: self.delete_torrent(torrent_id) return None