From f66a37abbd049dcd5881b49add7d8a53ff0dfb9a Mon Sep 17 00:00:00 2001 From: Hypsometric <25771958+hypsometric@users.noreply.github.com> Date: Fri, 30 Nov 2018 17:03:05 +0100 Subject: [PATCH] Redacted: use a FL token when available - Use a FL token when available - Added a configuration (default off) to enable the feature - Skip prefetching the data with Deluge as with Transmission in `preprocess()` - Note: because QBittorrent & uTorrent need the data to compute the torrenthash but still require the url to download the file, it will result in 2 FL tokens used instead of one because the .torrent will be downloaded twice from the server. Fixes #3163 --- data/interfaces/default/config.html | 4 ++++ headphones/config.py | 1 + headphones/searcher.py | 8 +++++--- headphones/webserve.py | 3 ++- lib/pygazelle/api.py | 11 ++++++----- lib/pygazelle/torrent.py | 1 + 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 5f7f1aa2..974aba6b 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -686,6 +686,10 @@ +
+ + +
diff --git a/headphones/config.py b/headphones/config.py index 15259fbd..0afc34a0 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -309,6 +309,7 @@ _CONFIG_DEFINITIONS = { 'REDACTED_USERNAME': (str, 'Redacted', ''), 'REDACTED_PASSWORD': (str, 'Redacted', ''), 'REDACTED_RATIO': (str, 'Redacted', ''), + 'REDACTED_USE_FLTOKEN': (int, 'Redacted', 0), 'XBMC_ENABLED': (int, 'XBMC', 0), 'XBMC_HOST': (str, 'XBMC', ''), 'XBMC_NOTIFY': (int, 'XBMC', 0), diff --git a/headphones/searcher.py b/headphones/searcher.py index 1991ecd3..10e5e604 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -1691,9 +1691,10 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, for torrent in match_torrents: if not torrent.file_path: torrent.group.update_group_data() # will load the file_path for the individual torrents + use_token = headphones.CONFIG.REDACTED_USE_FLTOKEN and torrent.can_use_token resultlist.append((torrent.file_path, torrent.size, - redobj.generate_torrent_link(torrent.id), + redobj.generate_torrent_link(torrent.id, use_token), provider, 'torrent', True)) @@ -1914,8 +1915,9 @@ def preprocess(resultlist): if result[3] == 'rutracker.org': return ruobj.get_torrent_data(result[2]), result - # Get out of here if we're using Transmission - if headphones.CONFIG.TORRENT_DOWNLOADER == 1: # if not a magnet link still need the .torrent to generate hash... uTorrent support labeling + # Get out of here if we're using Transmission or Deluge + # if not a magnet link still need the .torrent to generate hash... uTorrent support labeling + if headphones.CONFIG.TORRENT_DOWNLOADER in [1, 3]: return True, result # Get out of here if it's a magnet link if result[2].lower().startswith("magnet:"): diff --git a/headphones/webserve.py b/headphones/webserve.py index 028fbf04..e7f607a9 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1255,6 +1255,7 @@ class WebInterface(object): "redacted_username": headphones.CONFIG.REDACTED_USERNAME, "redacted_password": headphones.CONFIG.REDACTED_PASSWORD, "redacted_ratio": headphones.CONFIG.REDACTED_RATIO, + "redacted_use_fltoken": checked(headphones.CONFIG.REDACTED_USE_FLTOKEN), "pref_qual_0": radio(headphones.CONFIG.PREFERRED_QUALITY, 0), "pref_qual_1": radio(headphones.CONFIG.PREFERRED_QUALITY, 1), "pref_qual_2": radio(headphones.CONFIG.PREFERRED_QUALITY, 2), @@ -1463,7 +1464,7 @@ class WebInterface(object): "use_newznab", "newznab_enabled", "use_torznab", "torznab_enabled", "use_nzbsorg", "use_omgwtfnzbs", "use_piratebay", "use_oldpiratebay", "use_mininova", "use_waffles", "use_rutracker", - "use_orpheus", "use_redacted", "preferred_bitrate_allow_lossless", + "use_orpheus", "use_redacted", "redacted_use_fltoken", "preferred_bitrate_allow_lossless", "detect_bitrate", "ignore_clean_releases", "freeze_db", "cue_split", "move_files", "rename_files", "correct_metadata", "cleanup_files", "keep_nfo", "add_album_art", "embed_album_art", "embed_lyrics", diff --git a/lib/pygazelle/api.py b/lib/pygazelle/api.py index 29f5aa8d..a8c55a72 100644 --- a/lib/pygazelle/api.py +++ b/lib/pygazelle/api.py @@ -401,14 +401,15 @@ class GazelleAPI(object): return {'curr_page': curr_page, 'pages': pages, 'results': matching_torrents} - def generate_torrent_link(self, id): - url = "%storrents.php?action=download&id=%s&authkey=%s&torrent_pass=%s" %\ - (self.site, id, self.logged_in_user.authkey, self.logged_in_user.passkey) + def generate_torrent_link(self, id, use_token=False): + url = "%storrents.php?action=download&id=%s&authkey=%s&torrent_pass=%s&usetoken=%d" %\ + (self.site, id, self.logged_in_user.authkey, self.logged_in_user.passkey, use_token) return url - def save_torrent_file(self, id, dest): + def save_torrent_file(self, id, dest, use_token=False): file_data = self.unparsed_request("torrents.php", 'download', - id=id, authkey=self.logged_in_user.authkey, torrent_pass=self.logged_in_user.passkey) + id=id, authkey=self.logged_in_user.authkey, torrent_pass=self.logged_in_user.passkey, + usetoken=int(use_token)) with open(dest, 'w+') as dest_file: dest_file.write(file_data) diff --git a/lib/pygazelle/torrent.py b/lib/pygazelle/torrent.py index 730cb841..38400dd1 100644 --- a/lib/pygazelle/torrent.py +++ b/lib/pygazelle/torrent.py @@ -152,6 +152,7 @@ class Torrent(object): self.snatched = search_torrent_json_response['snatches'] self.free_torrent = search_torrent_json_response['isFreeleech'] or search_torrent_json_response['isPersonalFreeleech'] self.time = search_torrent_json_response['time'] + self.can_use_token = search_torrent_json_response.get('canUseToken', False) def set_torrent_top_10_data(self, top_10_json_response): if self.id != top_10_json_response['torrentId']: