def __init__(self): self.scrape_provider = 'downloads' self.threads = [] self.sources = [] self.scrape_results = [] self.extensions = supported_video_extensions() self.extensions.remove('.strm')
def resolve_magnet(self, magnet_url, info_hash, store_to_cloud): from modules.utils import supported_video_extensions try: torrent_id = None torrent_keys = [] extensions = supported_video_extensions() torrent_files = self.check_hash(info_hash) if not info_hash in torrent_files: return None torrent_files = torrent_files[info_hash]['rd'][0] try: files_tuple = sorted([(k, v['filename'].lower()) for k,v in torrent_files.items() if v['filename'].lower().endswith(tuple(extensions))]) except: return None files_tuple = sorted(files_tuple) for i in files_tuple: torrent_keys.append(i[0]) if not torrent_keys: return None torrent_keys = ','.join(torrent_keys) torrent = self.add_magnet(magnet_url) torrent_id = torrent['id'] self.add_torrent_select(torrent_id, torrent_keys) torrent_files = self.user_cloud_info(torrent_id) status = torrent_files.get('status') if not status == 'downloaded': return None media_id = torrent_files.get('links')[0] file_url = torrent_files['links'][0] if not store_to_cloud: self.delete_torrent(torrent_id) return self.unrestrict_link(file_url) except: if torrent_id: self.delete_torrent(torrent_id) return None
def __init__(self, scrape_provider, scraper_name): self.scrape_provider = scrape_provider self.scraper_name = scraper_name self.threads = [] self.sources = [] self.scrape_results = [] self.extensions = supported_video_extensions()
def rd_downloads(): from modules.utils import jsondate_to_datetime try: my_downloads = RealDebrid.downloads() 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)) ] for count, item in enumerate(my_downloads, 1): try: cm = [] datetime_object = jsondate_to_datetime(item['generated'], "%Y-%m-%dT%H:%M:%S.%fZ", remove_time=True) filename = item['filename'] name = clean_file_name(filename).upper() size = float(int(item['filesize'])) / 1073741824 display = '%02d | %.2f GB | %s | [I]%s [/I]' % ( count, size, datetime_object, name) url_link = item['download'] url_params = { 'mode': 'media_play', 'url': url_link, 'rootname': 'video' } down_file_params = { 'mode': 'download_file', 'name': name, 'url': url_link, 'db_type': 'realdebrid_direct_file', 'image': default_rd_icon } cm.append(("[B]Download File[/B]", 'XBMC.RunPlugin(%s)' % build_url(down_file_params))) url = build_url(url_params) listitem = xbmcgui.ListItem(display) listitem.addContextMenuItems(cm) listitem.setArt({ 'icon': default_rd_icon, 'poster': default_rd_icon, 'thumb': default_rd_icon, 'fanart': fanart, 'banner': default_rd_icon }) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass xbmcplugin.setContent(__handle__, 'files') xbmcplugin.endOfDirectory(__handle__) setView('view.premium')
def rd_external_browser(magnet, filtering_list): import re try: from HTMLParser import HTMLParser except ImportError: from html.parser import HTMLParser try: episode_match = False torrent_id = None torrent_keys = [] extensions = supported_video_extensions() magnet_url = HTMLParser().unescape(magnet) r = re.search('''magnet:.+?urn:([a-zA-Z0-9]+):([a-zA-Z0-9]+)''', str(magnet), re.I) infoHash = r.group(2).lower() torrent_files = RealDebrid.check_hash(infoHash) torrent_files = torrent_files[infoHash]['rd'][0] try: files_tuple = sorted([ (k, v['filename'].lower()) for k, v in torrent_files.items() if v['filename'].lower().endswith(tuple(extensions)) ]) except: return None files_tuple = sorted(files_tuple) for i in files_tuple: if any(x in i[1] for x in filtering_list): episode_match = True torrent_keys.append(i[0]) if not episode_match: return None if not torrent_keys: return None torrent_keys = ','.join(torrent_keys) torrent = RealDebrid.add_magnet(magnet_url) torrent_id = torrent['id'] RealDebrid.add_torrent_select(torrent_id, torrent_keys) torrent_files = RealDebrid.user_cloud_info(torrent_id) file_info = [ i for i in torrent_files['files'] if i['path'].lower().endswith(tuple(extensions)) ] file_urls = torrent_files['links'] pack_info = [ dict(i.items() + [('url_link', file_urls[c])]) for c, i in enumerate(file_info) ] pack_info = sorted(pack_info, key=lambda k: k['path']) for item in pack_info: filename = clean_title(item['path']) if any(x in filename for x in filtering_list): correct_result = item break url_link = correct_result['url_link'] RealDebrid.delete_torrent(torrent_id) return resolve_rd(url_link, play=False) except: if torrent_id: RealDebrid.delete_torrent(torrent_id) return None
def add_uncached_torrent(self, magnet_url): import xbmc from modules.nav_utils import show_busy_dialog, hide_busy_dialog from modules.utils import supported_video_extensions def _transfer_info(transfer_id): info = self.transfer_info() 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='Unknown Error.'): try: progressDialog.close() except Exception: pass self.delete_transfer(transfer_id) hide_busy_dialog() xbmc.sleep(500) xbmcgui.Dialog().ok('FEN Cloud Transfer', message) return False show_busy_dialog() extensions = supported_video_extensions() transfer_id = self.create_transfer(magnet_url) if not transfer_id['status'] == 'success': return _return_failed('ERROR Transferring Torrent.') transfer_id = transfer_id['id'] transfer_info = _transfer_info(transfer_id) if not transfer_info: return _return_failed('ERROR Transferring Torrent.') interval = 5 line1 = 'Saving Torrent to the Premiumize Cloud...' line2 = transfer_info['name'] line3 = transfer_info['message'] progressDialog.create('FEN Cloud Transfer', line1, line2, line3) while not transfer_info['status'] == 'seeding': xbmc.sleep(1000 * interval) transfer_info = _transfer_info(transfer_id) line3 = transfer_info['message'] progressDialog.update(int(float(transfer_info['progress']) * 100), line3=line3) if xbmc.abortRequested == True: return sys.exit() try: if progressDialog.iscanceled(): return _return_failed('Transfer Cancelled.') except Exception: pass if transfer_info.get('status') == 'stalled': return _return_failed('ERROR Transferring Torrent.') xbmc.sleep(1000 * interval) try: progressDialog.close() except Exception: pass hide_busy_dialog() return True
def resolve_magnet(self, magnet_url, info_hash, store_to_cloud): from modules.utils import supported_video_extensions extensions = supported_video_extensions() transfer_id = self.create_transfer(magnet_url) transfer_info = self.list_transfer(transfer_id) for link, file in transfer_info.get('links').items(): if any(file.lower().endswith(x) for x in extensions): media_id = link.replace("\/", "/") break if not store_to_cloud: self.delete_transfer(transfer_id) file_url = self.unrestrict_link(media_id) return file_url
def results(self, info): try: self.info = info self.db_type = self.info.get("db_type") self.title = self.info.get("title") self.year = self.info.get("year") if self.year: self.rootname = '%s (%s)' % (self.title, self.year) else: self.rootname = self.title self.season = self.info.get("season") self.episode = self.info.get("episode") self.query = clean_title(self.title) self.file_query = self._episode_query_list( ) if self.db_type == 'episode' else self._year_query_list() self.extensions = supported_video_extensions() self._scrape_cloud() if not self.scrape_results: return self.sources self.label_settings = label_settings(self.info['scraper_settings'], self.scrape_provider) for item in self.scrape_results: try: file_name = normalize(item['name']) path = item['path'] file_dl = item['id'] size = float(item['size']) / 1073741824 video_quality = get_release_quality(file_name, path) details = get_file_info(file_name) if not details: details = get_file_info(path) label, multiline_label = build_internal_scrapers_label( self.label_settings, file_name, details, size, video_quality) self.sources.append({ 'name': file_name, 'label': label, 'multiline_label': multiline_label, 'title': file_name, 'quality': video_quality, 'size': size, 'url_dl': file_dl, 'id': file_dl, 'downloads': False, 'direct': True, 'source': self.scrape_provider, 'scrape_provider': self.scrape_provider }) except: pass window.setProperty('pm-cloud_source_results', json.dumps(self.sources)) except Exception as e: from modules.utils import logger logger('FEN premiumize scraper Exception', e) return self.sources
def resolve_magnet(self, magnet, store_to_cloud): from modules.utils import supported_video_extensions try: data = {'src': magnet} url = 'transfer/directdl' result = self._post(url, data) if not 'status' in result or result['status'] != 'success': return None end_results = [] extensions = supported_video_extensions() for item in result.get('content'): if any(item.get('path').lower().endswith(x) for x in extensions) and not item.get('link', '') == '': end_results.append(item) file_url = max(end_results, key=lambda x: x.get('size')).get('link', None) if store_to_cloud: self.create_transfer(magnet) return self.add_headers_to_url(file_url) except: return None
def _scrape_folders(self, folder_info): try: final_files = [] extensions = supported_video_extensions() assigned_folder = folder_info[2] torrent_folder = folder_info[1] links = torrent_folder['links'] total_size = torrent_folder['size'] try: links_count = len([ v for k, v in links.items() if v.lower().endswith(tuple(self.extensions)) ]) for k, v in links.items(): if v.lower().endswith(tuple(self.extensions)): size = total_size / links_count final_files.append({ 'name': v, 'url_link': k, 'size': size }) except: links_count = len([ v for k, v in links.iteritems() if v.lower().endswith(tuple(self.extensions)) ]) for k, v in links.iteritems(): if v.lower().endswith(tuple(self.extensions)): size = total_size / links_count final_files.append({ 'name': v, 'url_link': k, 'size': size }) for item in final_files: filename = clean_title(normalize(item['name'])) if any(x in filename for x in self.query_list): if assigned_folder: self.scrape_results.append(item) elif self.folder_query in filename: self.scrape_results.append(item) except: return
def pm_transfers(): extensions = supported_video_extensions() transfer_files = Premiumize.transfers_list()['transfers'] for count, item in enumerate(transfer_files, 1): try: cm = [] file_type = 'folder' if item['file_id'] is None else 'file' name = clean_file_name(item['name']).upper() status = item['status'] progress = item['progress'] if status == 'finished': progress = 100 else: try: progress = re.findall('\.(\d+)', str(progress))[0] progress = progress[:2] except: progress = '' if file_type == 'folder': display = '%02d | %s%% | [B]%s[/B] | [I]%s [/I]' % (count, str(progress), file_type.upper(), name) url_params = {'mode': 'premiumize.pm_torrent_cloud', 'id': item['folder_id'], 'folder_name': normalize(item['name'])} else: details = Premiumize.get_item_details(item['file_id']) url_link = details['link'] if url_link.startswith('/'): url_link = 'https' + url_link size = details['size'] display_size = float(int(size))/1073741824 display = '%02d | %s%% | [B]%s[/B] | %.2f GB | [I]%s [/I]' % (count, str(progress), file_type.upper(), display_size, name) url_params = {'mode': 'media_play', 'url': url_link, 'rootname': 'video'} down_file_params = {'mode': 'download_file', 'name': item['name'], 'url': url_link, 'db_type': 'premiumize_file', 'image': default_pm_icon} cm.append(("[B]Download File[/B]",'XBMC.RunPlugin(%s)' % build_url(down_file_params))) url = build_url(url_params) listitem = xbmcgui.ListItem(display) listitem.addContextMenuItems(cm) listitem.setArt({'icon': default_pm_icon, 'poster': default_pm_icon, 'thumb': default_pm_icon, 'fanart': fanart, 'banner': default_pm_icon}) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass xbmcplugin.setContent(__handle__, 'files') xbmcplugin.endOfDirectory(__handle__) setView('view.premium')
def pm_torrent_cloud(folder_id=None, folder_name=None): try: extensions = supported_video_extensions() cloud_files = Premiumize.user_cloud(folder_id)['content'] 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: return for count, item in enumerate(cloud_files, 1): try: cm = [] file_type = item['type'] name = clean_file_name(item['name']).upper() rename_params = {'mode': 'premiumize.rename', 'file_type': file_type, 'id': item['id'], 'name': item['name']} if file_type == 'folder': size = 0 display = '%02d | [B]%s[/B] | [I]%s [/I]' % (count, file_type.upper(), name) url_params = {'mode': 'premiumize.pm_torrent_cloud', 'id': item['id'], 'folder_name': normalize(item['name'])} else: url_link = item['link'] if url_link.startswith('/'): url_link = 'https' + url_link size = item['size'] display_size = float(int(size))/1073741824 display = '%02d | [B]%s[/B] | %.2f GB | [I]%s [/I]' % (count, file_type.upper(), display_size, name) url_params = {'mode': 'media_play', 'url': url_link, 'rootname': 'video'} down_file_params = {'mode': 'download_file', 'name': item['name'], 'url': url_link, 'db_type': 'premiumize_file', 'image': default_pm_icon} cm.append(("[B]Download File[/B]",'XBMC.RunPlugin(%s)' % build_url(down_file_params))) cm.append(("[B]Rename %s[/B]" % file_type.capitalize(),'XBMC.RunPlugin(%s)' % build_url(rename_params))) url = build_url(url_params) listitem = xbmcgui.ListItem(display) listitem.addContextMenuItems(cm) listitem.setArt({'icon': default_pm_icon, 'poster': default_pm_icon, 'thumb': default_pm_icon, 'fanart': fanart, 'banner': default_pm_icon}) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass xbmcplugin.setContent(__handle__, 'files') xbmcplugin.endOfDirectory(__handle__) setView('view.premium')
def browse_ad_cloud(folder): final_files = [] extensions = supported_video_extensions() torrent_folder = json.loads(folder) links = torrent_folder['links'] total_size = torrent_folder['size'] try: links_count = len([ v for k, v in links.items() if v.lower().endswith(tuple(extensions)) ]) for k, v in links.items(): if v.lower().endswith(tuple(extensions)): size = total_size / links_count final_files.append({'name': v, 'down_url': k, 'size': size}) except: links_count = len([ v for k, v in links.iteritems() if v.lower().endswith(tuple(extensions)) ]) for k, v in links.iteritems(): if v.lower().endswith(tuple(extensions)): size = total_size / links_count final_files.append({'name': v, 'down_url': k, 'size': size}) for count, item in enumerate(final_files, 1): try: cm = [] url_link = item['down_url'] name = clean_file_name(item['name']).upper() size = item['size'] display_size = float(int(size)) / 1073741824 display = '%02d | %.2f GB | [I]%s [/I]' % (count, display_size, name) url_params = {'mode': 'alldebrid.resolve_ad', 'url': url_link} url = build_url(url_params) down_file_params = { 'mode': 'download_file', 'name': name, 'url': url_link, 'db_type': 'alldebrid_file', 'image': default_ad_icon } cm.append(("[B]Download File[/B]", 'XBMC.RunPlugin(%s)' % build_url(down_file_params))) listitem = xbmcgui.ListItem(display) listitem.addContextMenuItems(cm) listitem.setArt({ 'icon': default_ad_icon, 'poster': default_ad_icon, 'thumb': default_ad_icon, 'fanart': fanart, 'banner': default_ad_icon }) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass xbmcplugin.setContent(__handle__, 'files') xbmcplugin.endOfDirectory(__handle__) setView('view.premium')
def add_uncached_torrent(self, magnet_url): import xbmc from modules.nav_utils import show_busy_dialog, hide_busy_dialog from modules.utils import supported_video_extensions def _return_failed(message='Unknown Error.'): try: progressDialog.close() except Exception: pass self.delete_torrent(torrent_id) hide_busy_dialog() xbmc.sleep(500) xbmcgui.Dialog().ok('FEN Cloud Transfer', message) return False show_busy_dialog() extensions = supported_video_extensions() torrent = self.add_magnet(magnet_url) torrent_id = torrent['id'] if not torrent_id: return _return_failed('ERROR Transferring Torrent.') interval = 5 stalled = ['magnet_error', 'error', 'virus', 'dead'] torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'magnet_conversion': line1 = 'Converting MAGNET...' line2 = torrent_info['filename'] line3 = '%s seeders' % torrent_info['seeders'] timeout = 100 progressDialog.create('FEN Cloud Transfer', line1, line2, line3) while status == 'magnet_conversion' and timeout > 0: progressDialog.update(timeout, line3=line3) if xbmc.abortRequested == True: return sys.exit() try: if progressDialog.iscanceled(): return _return_failed('Transfer Cancelled.') except Exception: pass if any(x in status for x in stalled): return _return_failed('ERROR Transferring Torrent.') timeout -= interval xbmc.sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] line3 = '%s seeders' % torrent_info['seeders'] try: progressDialog.close() except Exception: pass if status == 'magnet_conversion': return _return_failed('ERROR Converting Magnet.') 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) try: video = max(video_files, key=lambda x: x['bytes']) file_id = video['id'] except ValueError: return _return_failed('No Video File Found.') self.add_torrent_select(torrent_id, str(file_id)) 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 = 'Saving Torrent to the Real-Debrid Cloud...' line2 = torrent_info['filename'] line3 = status progressDialog.create('FEN Cloud Transfer', line1, line2, line3) while not status == 'downloaded': xbmc.sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloading': line3 = 'Downloading %s GB @ %s mbps from %s peers, %s %% completed' % (file_size, round(float(torrent_info['speed']) / (1000**2), 2), torrent_info['seeders'], torrent_info['progress']) else: line3 = status progressDialog.update(int(float(torrent_info['progress'])), line3=line3) if xbmc.abortRequested == True: return sys.exit() # try: if progressDialog.iscanceled(): return _return_failed('Transfer Cancelled.') # except Exception: # pass if any(x in status for x in stalled): return _return_failed('ERROR Transferring Torrent.') try: progressDialog.close() except Exception: pass hide_busy_dialog() return True hide_busy_dialog() return False
def browse_rd_cloud(folder_id): try: torrent_files = RealDebrid.user_cloud_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: return xbmcgui.Dialog().ok('Fen - Real Debrid', 'Cannot display Malformed Pack.') for count, item in enumerate(pack_info, 1): try: cm = [] name = item['path'] if name.startswith('/'): name = name.split('/')[-1] name = clean_file_name(name).upper() url_link = item['url_link'] if url_link.startswith('/'): url_link = 'http' + url_link size = float(int(item['bytes'])) / 1073741824 display = '%02d | [B]FILE[/B] | %.2f GB | [I]%s [/I]' % ( count, size, name) url_params = {'mode': 'real_debrid.resolve_rd', 'url': url_link} url = build_url(url_params) down_file_params = { 'mode': 'download_file', 'name': name, 'url': url_link, 'db_type': 'realdebrid_file', 'image': default_rd_icon } cm.append(("[B]Download File[/B]", 'XBMC.RunPlugin(%s)' % build_url(down_file_params))) listitem = xbmcgui.ListItem(display) listitem.addContextMenuItems(cm) listitem.setArt({ 'icon': default_rd_icon, 'poster': default_rd_icon, 'thumb': default_rd_icon, 'fanart': fanart, 'banner': default_rd_icon }) xbmcplugin.addDirectoryItem(__handle__, url, listitem, isFolder=True) except: pass xbmcplugin.setContent(__handle__, 'files') xbmcplugin.endOfDirectory(__handle__) setView('view.premium')