def resolve_magnet(self, magnet_url, info_hash, store_to_cloud, title, season, episode): from modules.source_utils import supported_video_extensions, seas_ep_filter, extras_filter try: file_url = None correct_files = [] append = correct_files.append extensions = supported_video_extensions() extras_filtering_list = extras_filter() result = self.instant_transfer(magnet_url) if not 'status' in result or result['status'] != 'success': return None valid_results = [ i for i in result.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-]+', '.', title.replace('\'', '').replace('&', 'and').replace( '%', '.percent')).lower() for item in valid_results: if seas_ep_filter(season, episode, item['path'].split('/')[-1]): 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 not any(file_url.lower().endswith(x) for x in extensions): file_url = None if file_url: if store_to_cloud: self.create_transfer(magnet_url) return self.add_headers_to_url(file_url) except: return None
def _scrape_downloads(self): try: my_downloads = RealDebrid.downloads() my_downloads = [ i for i in my_downloads if i['download'].lower().endswith(tuple(self.extensions)) ] append = self.scrape_results.append for item in my_downloads: match = False normalized = normalize(item['filename']) filename = clean_title(normalized) if self.db_type == 'movie': if any(x in filename for x in self._year_query_list()): match = True else: if seas_ep_filter(self.season, self.episode, normalized): match = True if match and self.folder_query in filename: item = self.make_downloads_item(item) if item['path'] not in [ d['path'] for d in self.scrape_results ]: append(item) except: pass
def resolve_magnet(self, magnet_url, info_hash, store_to_cloud, title, season, episode): from modules.source_utils import supported_video_extensions, seas_ep_filter, extras_filter try: file_url = None correct_files = [] append = correct_files.append extensions = supported_video_extensions() extras_filtering_list = 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: episode_title = re.sub( r'[^A-Za-z0-9-]+', '.', title.replace('\'', '').replace('&', 'and').replace( '%', '.percent')).lower() for item in valid_results: if seas_ep_filter(season, episode, item['filename']): append(item) if len(correct_files) == 0: continue 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) if not any(file_url.lower().endswith(x) for x in extensions): file_url = None return file_url except Exception: if transfer_id: self.delete_transfer(transfer_id) return None
def _scrape_folders(self, folder_info): try: assigned_folder = folder_info[2] folder_files = RealDebrid.user_cloud_info(folder_info[1]) contents = [ i for i in folder_files['files'] if i['path'].lower().endswith(tuple(self.extensions)) ] file_urls = folder_files['links'] append = self.scrape_results.append for c, i in enumerate(contents): try: i.update({ 'folder_name': folder_info[0], 'url_link': file_urls[c] }) except: pass contents.sort(key=lambda k: k['path']) for item in contents: match = False normalized = normalize(item['path']) filename = clean_title(normalized) if assigned_folder and self.db_type == 'movie': match = True else: if self.db_type == 'movie': if any(x in filename for x in self._year_query_list() ) and self.folder_query in filename: match = True else: if assigned_folder: if any(x in normalized.lower() for x in self.seas_ep_query_list): match = True elif seas_ep_filter(self.season, self.episode, normalized): match = True if match: if assigned_folder: item['assigned_folder'] = True append(item) except: pass
def _scrape_cloud(self): try: cloud_files = Premiumize.user_cloud_all()['files'] cloud_files = [ i for i in cloud_files if i['path'].lower().endswith(tuple(self.extensions)) ] cloud_files.sort(key=lambda k: k['name']) except: return self.sources append = self.scrape_results.append for item in cloud_files: normalized = normalize(item['name']) item_name = clean_title(normalized) if self.query in item_name: if self.db_type == 'movie': if any(x in item['name'] for x in self._year_query_list()): append(item) elif seas_ep_filter(self.season, self.episode, normalized): append(item)
def _process(item): file_type = item[1] normalized = normalize(item[0]) item_name = clean_title(normalized) if file_type == 'file': ext = os.path.splitext(urlparse(item[0]).path)[-1].lower() if ext in self.extensions: if self.db_type == 'movie': if self.assigned_content or self.title_query in item_name: url_path = self.url_path(folder_name, item[0]) size = self._get_size(url_path) scrape_results_append((item[0], url_path, size)) else: if seas_ep_filter(self.season, self.episode, normalized): if self.assigned_content or not folder_name in self.folder_path: url_path = self.url_path(folder_name, item[0]) size = self._get_size(url_path) scrape_results_append((item[0], url_path, size)) elif self.title_query in item_name: url_path = self.url_path(folder_name, item[0]) size = self._get_size(url_path) scrape_results_append((item[0], url_path, size)) elif file_type == 'folder': if not assigned_folder: self.assigned_content = self._assigned_content(normalize(item[0])) if self.assigned_content: if self.assigned_content == self.rootname: new_folder = os.path.join(folder_name, item[0]) foler_results_append((new_folder, True)) elif self.title_query in item_name or any(x in item_name for x in self.folder_query): new_folder = os.path.join(folder_name, item[0]) foler_results_append((new_folder, self.assigned_content)) elif assigned_folder: if any(x in item_name for x in self.folder_query): new_folder = os.path.join(folder_name, item[0]) foler_results_append((new_folder, True)) elif self.title_query in item_name or any(x in item_name for x in self.folder_query): new_folder = os.path.join(folder_name, item[0]) foler_results_append((new_folder, self.assigned_content))
def _scrape_folders(self, folder_info): try: assigned_folder = folder_info[2] torrent_folder = folder_info[1] links = torrent_folder['links'] append = self.scrape_results.append links = [i for i in links if i['filename'].lower().endswith(tuple(self.extensions))] for item in links: match = False normalized = normalize(item['filename']) filename = clean_title(normalized) if assigned_folder and self.db_type == 'movie': match = True else: if self.db_type == 'movie': if any(x in filename for x in self._year_query_list()) and self.folder_query in filename: match = True else: if assigned_folder: if any(x in normalized.lower() for x in self.seas_ep_query_list): match = True elif seas_ep_filter(self.season, self.episode, normalized): match = True if match: if assigned_folder: item['assigned_folder'] = True append(item) except: return
def resolve_magnet(self, magnet_url, info_hash, store_to_cloud, title, season, episode): from modules.source_utils import supported_video_extensions, seas_ep_filter, extras_filter try: torrent_id, rd_url, match = None, None, False extensions = supported_video_extensions() extras_filtering_list = extras_filter() torrent_files = self.check_hash(info_hash) if not info_hash in torrent_files: return None torrent = self.add_magnet(magnet_url) torrent_id = torrent['id'] torrent_files = torrent_files[info_hash]['rd'] torrent_files = [ item for item in torrent_files if self._video_only(item, extensions) ] if season: episode_title = re.sub( r'[^A-Za-z0-9-]+', '.', title.replace('\'', '').replace('&', 'and').replace( '%', '.percent')).lower() else: m2ts_check = self._m2ts_check(torrent_files) if m2ts_check: m2ts_key, torrent_files = self._m2ts_key_value( torrent_files) else: torrent_files = self.sort_cache_list([ (item, max([i['filesize'] for i in item.values()])) for item in torrent_files ]) for item in torrent_files: try: if season: 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 elif not m2ts_check: item_values = self.sort_cache_list([ (i['filename'], i['filesize']) for i in item.values() ]) for value in item_values: filename = re.sub( r'[^A-Za-z0-9-]+', '.', value.replace('\'', '').replace('&', 'and').replace( '%', '.percent')).lower() if any(x in filename for x in extras_filtering_list): continue break 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.user_cloud_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']) if correct_file_check: correct_files.append(value[1]) break 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 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] break 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() if any(x in filename for x in extras_filtering_list): continue match, index = True, value[0] break if match: break except: pass 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 self.delete_torrent(torrent_id) except Exception: if torrent_id: self.delete_torrent(torrent_id) return None