From 99680e9a0f4f61710fb7fc75e5f094d35b5c62c9 Mon Sep 17 00:00:00 2001 From: likeitneverwentaway Date: Sat, 8 Oct 2016 00:46:12 +0200 Subject: [PATCH 1/6] Update searcher.py to add t411 support --- headphones/searcher.py | 86 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/headphones/searcher.py b/headphones/searcher.py index c8f16184..ff7e4736 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -14,6 +14,7 @@ # along with Headphones. If not, see . # NZBGet support added by CurlyMo as a part of XBian - XBMC on the Raspberry Pi +# t411 support added by a1ex, @likeitneverwentaway on github for maintenance from base64 import b16encode, b32decode from hashlib import sha1 @@ -812,6 +813,19 @@ def send_to_downloader(data, bestqual, album): # Get torrent name from .torrent, this is usually used by the torrent client as the folder name torrent_name = helpers.replace_illegal_chars(folder_name) + '.torrent' download_path = os.path.join(headphones.CONFIG.TORRENTBLACKHOLE_DIR, torrent_name) + + # Blackhole for t411 + if bestqual[2].lower().startswith("http://api.t411"): + if headphones.CONFIG.MAGNET_LINKS == 2: + try: + url = bestqual[2].split('TOKEN')[0] + token = bestqual[2].split('TOKEN')[1] + data = request.request_content(url, headers = {'Authorization':token}) + torrent_to_file(download_path, data) + logger.info('Successfully converted magnet to torrent file') + except Exception as e: + logger.error("Error converting magnet link: %s" % str(e)) + return if bestqual[2].lower().startswith("magnet:"): if headphones.CONFIG.MAGNET_LINKS == 1: @@ -1763,6 +1777,78 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, resultlist.append((title, size, url, provider, 'torrent', match)) except Exception as e: logger.exception("Unhandled exception in Mininova Parser") + # t411 + if headphones.CONFIG.TQUATTRECENTONZE: + username = headphones.CONFIG.TQUATTRECENTONZE_USER + password = headphones.CONFIG.TQUATTRECENTONZE_PASSWORD + API_URL = "http://api.t411.ch" + AUTH_URL= API_URL + '/auth' + DL_URL = API_URL + '/torrents/download/' + provider = "t411" + t411_term = term.replace(" ","%20") + SEARCH_URL = API_URL + '/torrents/search/' + t411_term + "?limit=15&cid=395&subcat=623" + headers_login = {'username': username, 'password' : password} + + # Requesting content + logger.info('Parsing results from t411 using search term: %s' % term) + req = request.request_content(AUTH_URL, method='post',data = headers_login) + + if len(req.split('"')) == 9: + token =req.split('"')[7] + headers_auth = {'Authorization':token} + logger.info('t411 - User %s logged in' % username) + else: + logger.info('t411 - Login error : %s' % req.split('"')[3]) + + # Quality + if headphones.CONFIG.PREFERRED_QUALITY == 3 or losslessOnly: + providerurl = "&term[16][]=529&term[16][]=1184" + elif headphones.CONFIG.PREFERRED_QUALITY == 1 or allow_lossless: + providerurl = fix_url(SEARCH_URL + "&term[16][]=685&term[16][]=527&term[16][]=1070&term[16][]=528&term[16][]=1167&term[16][]=1166&term[16][]=530&term[16][]=529&term[16][]=1184&term[16][]=532&term[16][]=533&term[16][]=1085&term[16][]=534&term[16][]=535&term[16][]=1069&term[16][]=537&term[16][]=538") + elif headphones.CONFIG.PREFERRED_QUALITY == 0: + providerurl = fix_url(SEARCH_URL + "&term[16][]=685&term[16][]=527&term[16][]=1070&term[16][]=528&term[16][]=1167&term[16][]=1166&term[16][]=530&term[16][]=532&term[16][]=533&term[16][]=1085&term[16][]=534&term[16][]=535&term[16][]=1069&term[16][]=537&term[16][]=538") + else: + providerurl = fix_url(SEARCH_URL) + + # Tracker search + req = request.request_content(providerurl, headers = headers_auth) + req = json.loads(req) + total = req['total'] + + # Process feed + if total == '0': + logger.info("No results found from t411 for %s" % term) + else: + logger.info('Found %s results from t411' % total) + torrents = req['torrents'] + for torrent in torrents: + try: + title = torrent['name'] + if torrent['seeders'] < minimumseeders: + logger.info('Skipping torrent %s : seeders below minimum set' % title) + continue + id = torrent['id'] + size = int(torrent['size']) + data = request.request_content(DL_URL + id, headers = headers_auth) + + #Blackhole + if headphones.CONFIG.TORRENT_DOWNLOADER == 0 and headphones.CONFIG.MAGNET_LINKS == 2: + url = DL_URL + id + 'TOKEN' + token + resultlist.append((title, size, url, provider, 'torrent', True)) + + # Build magnet + else: + metadata = bdecode(data) + hashcontents = bencode(metadata['info']) + digest = sha1(hashcontents).hexdigest() + trackers = [metadata["announce"]][0] + url = 'magnet:?xt=urn:btih:%s&tr=%s' % (digest, trackers) + resultlist.append((title, size, url, provider, 'torrent', True)) + + except Exception as e: + logger.error("Error converting magnet link: %s" % str(e)) + return + # attempt to verify that this isn't a substring result # when looking for "Foo - Foo" we don't want "Foobar" From bd8eb74662d370ac4394876afe962c0d70684ab2 Mon Sep 17 00:00:00 2001 From: likeitneverwentaway Date: Sat, 8 Oct 2016 00:50:48 +0200 Subject: [PATCH 2/6] Update config.html to add t411 support --- data/interfaces/default/config.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index a22a0ea7..baf39586 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -743,6 +743,22 @@ + +
+
+ +
+
+
+ + +
+
+ + +
+
+
@@ -2400,6 +2416,7 @@ initConfigCheckbox("#api_enabled"); initConfigCheckbox("#enable_https"); initConfigCheckbox("#customauth"); + initConfigCheckbox("#use_tquattrecentonze"); $('#twitterStep1').click(function () { From d3d48d27df71ab2f67554347c91a6254bfb04d72 Mon Sep 17 00:00:00 2001 From: likeitneverwentaway Date: Sat, 8 Oct 2016 01:00:49 +0200 Subject: [PATCH 3/6] Update webserve.py to add t411 support --- headphones/webserve.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/headphones/webserve.py b/headphones/webserve.py index 249bf9f9..1337894c 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1229,6 +1229,9 @@ class WebInterface(object): "whatcd_ratio": headphones.CONFIG.WHATCD_RATIO, "use_strike": checked(headphones.CONFIG.STRIKE), "strike_ratio": headphones.CONFIG.STRIKE_RATIO, + "use_tquattrecentonze": checked(headphones.CONFIG.TQUATTRECENTONZE), + "tquattrecentonze_user": headphones.CONFIG.TQUATTRECENTONZE_USER, + "tquattrecentonze_password": headphones.CONFIG.TQUATTRECENTONZE_PASSWORD, "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), @@ -1425,7 +1428,7 @@ class WebInterface(object): "use_newznab", "newznab_enabled", "use_torznab", "torznab_enabled", "use_nzbsorg", "use_omgwtfnzbs", "use_kat", "use_piratebay", "use_oldpiratebay", "use_mininova", "use_waffles", "use_rutracker", - "use_whatcd", "use_strike", "preferred_bitrate_allow_lossless", "detect_bitrate", + "use_whatcd", "use_strike", "use_tquattrecentonze", "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", From aa503f0fe88a1ff4fd6dee49211500bc62be7a22 Mon Sep 17 00:00:00 2001 From: likeitneverwentaway Date: Sat, 8 Oct 2016 01:01:39 +0200 Subject: [PATCH 4/6] Update config.py to add t411 support --- headphones/config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/headphones/config.py b/headphones/config.py index 5b819007..e825cc68 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -274,6 +274,9 @@ _CONFIG_DEFINITIONS = { 'TWITTER_PASSWORD': (str, 'Twitter', ''), 'TWITTER_PREFIX': (str, 'Twitter', 'Headphones'), 'TWITTER_USERNAME': (str, 'Twitter', ''), + 'TQUATTRECENTONZE': (int, 'tquattrecentonze', 0), + 'TQUATTRECENTONZE_PASSWORD': (str, 'tquattrecentonze', ''), + 'TQUATTRECENTONZE_USER': (str, 'tquattrecentonze', ''), 'UPDATE_DB_INTERVAL': (int, 'General', 24), 'USENET_RETENTION': (int, 'General', '1500'), 'UTORRENT_HOST': (str, 'uTorrent', ''), From 31a99a908afa91b8ada2e2d6a5c4c5f9722cba8f Mon Sep 17 00:00:00 2001 From: likeitneverwentaway Date: Sat, 8 Oct 2016 01:08:54 +0200 Subject: [PATCH 5/6] Added credit --- headphones/webserve.py | 1 + 1 file changed, 1 insertion(+) diff --git a/headphones/webserve.py b/headphones/webserve.py index 1337894c..9b09feba 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -14,6 +14,7 @@ # along with Headphones. If not, see . # NZBGet support added by CurlyMo as a part of XBian - XBMC on the Raspberry Pi +# t411 support added by a1ex, @likeitneverwentaway on github for maintenance from operator import itemgetter import threading From 42294d261d1cce82ec3e8be593671d00d257daba Mon Sep 17 00:00:00 2001 From: likeitneverwentaway Date: Sat, 8 Oct 2016 01:55:55 +0200 Subject: [PATCH 6/6] Fix typo, import loads from json --- headphones/searcher.py | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index ff7e4736..6c7fe8cf 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -25,6 +25,7 @@ import datetime import subprocess import unicodedata import urlparse +from json import loads import os import re @@ -813,14 +814,14 @@ def send_to_downloader(data, bestqual, album): # Get torrent name from .torrent, this is usually used by the torrent client as the folder name torrent_name = helpers.replace_illegal_chars(folder_name) + '.torrent' download_path = os.path.join(headphones.CONFIG.TORRENTBLACKHOLE_DIR, torrent_name) - + # Blackhole for t411 if bestqual[2].lower().startswith("http://api.t411"): if headphones.CONFIG.MAGNET_LINKS == 2: try: url = bestqual[2].split('TOKEN')[0] token = bestqual[2].split('TOKEN')[1] - data = request.request_content(url, headers = {'Authorization':token}) + data = request.request_content(url, headers={'Authorization': token}) torrent_to_file(download_path, data) logger.info('Successfully converted magnet to torrent file') except Exception as e: @@ -1782,24 +1783,24 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, username = headphones.CONFIG.TQUATTRECENTONZE_USER password = headphones.CONFIG.TQUATTRECENTONZE_PASSWORD API_URL = "http://api.t411.ch" - AUTH_URL= API_URL + '/auth' + AUTH_URL = API_URL + '/auth' DL_URL = API_URL + '/torrents/download/' provider = "t411" - t411_term = term.replace(" ","%20") + t411_term = term.replace(" ", "%20") SEARCH_URL = API_URL + '/torrents/search/' + t411_term + "?limit=15&cid=395&subcat=623" - headers_login = {'username': username, 'password' : password} - + headers_login = {'username': username, 'password': password} + # Requesting content logger.info('Parsing results from t411 using search term: %s' % term) - req = request.request_content(AUTH_URL, method='post',data = headers_login) - + req = request.request_content(AUTH_URL, method='post', data=headers_login) + if len(req.split('"')) == 9: - token =req.split('"')[7] - headers_auth = {'Authorization':token} + token = req.split('"')[7] + headers_auth = {'Authorization': token} logger.info('t411 - User %s logged in' % username) else: logger.info('t411 - Login error : %s' % req.split('"')[3]) - + # Quality if headphones.CONFIG.PREFERRED_QUALITY == 3 or losslessOnly: providerurl = "&term[16][]=529&term[16][]=1184" @@ -1809,12 +1810,12 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, providerurl = fix_url(SEARCH_URL + "&term[16][]=685&term[16][]=527&term[16][]=1070&term[16][]=528&term[16][]=1167&term[16][]=1166&term[16][]=530&term[16][]=532&term[16][]=533&term[16][]=1085&term[16][]=534&term[16][]=535&term[16][]=1069&term[16][]=537&term[16][]=538") else: providerurl = fix_url(SEARCH_URL) - + # Tracker search - req = request.request_content(providerurl, headers = headers_auth) - req = json.loads(req) + req = request.request_content(providerurl, headers=headers_auth) + req = loads(req) total = req['total'] - + # Process feed if total == '0': logger.info("No results found from t411 for %s" % term) @@ -1829,26 +1830,25 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, continue id = torrent['id'] size = int(torrent['size']) - data = request.request_content(DL_URL + id, headers = headers_auth) - - #Blackhole + data = request.request_content(DL_URL + id, headers=headers_auth) + + # Blackhole if headphones.CONFIG.TORRENT_DOWNLOADER == 0 and headphones.CONFIG.MAGNET_LINKS == 2: url = DL_URL + id + 'TOKEN' + token resultlist.append((title, size, url, provider, 'torrent', True)) - + # Build magnet else: metadata = bdecode(data) hashcontents = bencode(metadata['info']) digest = sha1(hashcontents).hexdigest() trackers = [metadata["announce"]][0] - url = 'magnet:?xt=urn:btih:%s&tr=%s' % (digest, trackers) + url = 'magnet:?xt=urn:btih:%s&tr=%s' % (digest, trackers) resultlist.append((title, size, url, provider, 'torrent', True)) - + except Exception as e: logger.error("Error converting magnet link: %s" % str(e)) return - # attempt to verify that this isn't a substring result # when looking for "Foo - Foo" we don't want "Foobar"