Rename PTH to Redacted and fix invalid User-Agent (Again)

This is a duplicate of albshin's PR as I got impatient waiting for him
to submit it to the develop branch with the addition of removing the
previous user agents and replacing them with Headphones as the agent.
Redacted considers falsifying the agent as a bannable offence.

From albshin's PR;
"Changes all instances of PassTheHeadphones to Redacted. Removed the URL
option for Redacted as it's unnecessary(?).

Fixed a bug in the pyGazelle library in which the User-Agent was invalid
due to a missing space. Should work now for Redacted."
This commit is contained in:
DJ-666
2017-03-31 23:36:34 +10:30
parent f8b82337a2
commit 1da1f5124a
5 changed files with 39 additions and 46 deletions
+5 -9
View File
@@ -678,24 +678,20 @@
<fieldset> <fieldset>
<div class="row checkbox left"> <div class="row checkbox left">
<input id="use_pth" type="checkbox" class="bigcheck" name="use_pth" value="1" ${config['use_pth']} /><label for="use_pth"><span class="option">PassTheHeadphones.me</span></label> <input id="use_redacted" type="checkbox" class="bigcheck" name="use_redacted" value="1" ${config['use_redacted']} /><label for="use_redacted"><span class="option">Redacted</span></label>
</div> </div>
<div class="config"> <div class="config">
<div class="row"> <div class="row">
<label>Username</label> <label>Username</label>
<input type="text" name="pth_username" value="${config['pth_username']}" size="36"> <input type="text" name="redacted_username" value="${config['redacted_username']}" size="36">
</div> </div>
<div class="row"> <div class="row">
<label>Password</label> <label>Password</label>
<input type="password" name="pth_password" value="${config['pth_password'] | h}" size="36"> <input type="password" name="redacted_password" value="${config['redacted_password'] | h}" size="36">
</div>
<div class="row">
<label>URL</label>
<input type="text" name="pth_url" value="${config['pth_url']}" size="36">
</div> </div>
<div class="row"> <div class="row">
<label>Seed Ratio</label> <label>Seed Ratio</label>
<input type="text" class="override-float" name="pth_ratio" value="${config['pth_ratio']}" size="10" title="Stop seeding when ratio met, 0 = unlimited. Scheduled job will remove torrent when post processed and finished seeding"> <input type="text" class="override-float" name="redacted_ratio" value="${config['redacted_ratio']}" size="10" title="Stop seeding when ratio met, 0 = unlimited. Scheduled job will remove torrent when post processed and finished seeding">
</div> </div>
</div> </div>
</fieldset> </fieldset>
@@ -2558,7 +2554,7 @@
initConfigCheckbox("#use_waffles"); initConfigCheckbox("#use_waffles");
initConfigCheckbox("#use_rutracker"); initConfigCheckbox("#use_rutracker");
initConfigCheckbox("#use_apollo"); initConfigCheckbox("#use_apollo");
initConfigCheckbox("#use_pth"); initConfigCheckbox("#use_redacted");
initConfigCheckbox("#use_strike"); initConfigCheckbox("#use_strike");
initConfigCheckbox("#api_enabled"); initConfigCheckbox("#api_enabled");
initConfigCheckbox("#enable_https"); initConfigCheckbox("#enable_https");
+4 -5
View File
@@ -306,11 +306,10 @@ _CONFIG_DEFINITIONS = {
'WAFFLES_PASSKEY': (str, 'Waffles', ''), 'WAFFLES_PASSKEY': (str, 'Waffles', ''),
'WAFFLES_RATIO': (str, 'Waffles', ''), 'WAFFLES_RATIO': (str, 'Waffles', ''),
'WAFFLES_UID': (str, 'Waffles', ''), 'WAFFLES_UID': (str, 'Waffles', ''),
'PTH': (int, 'PassTheHeadphones.me', 0), 'REDACTED': (int, 'Redacted', 0),
'PTH_PASSWORD': (str, 'PassTheHeadphones.me', ''), 'REDACTED_USERNAME': (str, 'Redacted', ''),
'PTH_RATIO': (str, 'PassTheHeadphones.me', ''), 'REDACTED_PASSWORD': (str, 'Redacted', ''),
'PTH_USERNAME': (str, 'PassTheHeadphones.me', ''), 'REDACTED_RATIO': (str, 'Redacted', ''),
'PTH_URL': (str, 'PassTheHeadphones.me', 'https://passtheheadphones.me'),
'XBMC_ENABLED': (int, 'XBMC', 0), 'XBMC_ENABLED': (int, 'XBMC', 0),
'XBMC_HOST': (str, 'XBMC', ''), 'XBMC_HOST': (str, 'XBMC', ''),
'XBMC_NOTIFY': (int, 'XBMC', 0), 'XBMC_NOTIFY': (int, 'XBMC', 0),
+24 -24
View File
@@ -47,9 +47,9 @@ TORRENT_TO_MAGNET_SERVICES = [
# Persistent Apollo.rip API object # Persistent Apollo.rip API object
apolloobj = None apolloobj = None
# Persistent PTH API object
ruobj = None ruobj = None
pthobj = None # Persistent RED API object
redobj = None
def fix_url(s, charset="utf-8"): def fix_url(s, charset="utf-8"):
@@ -164,8 +164,8 @@ def get_seed_ratio(provider):
seed_ratio = headphones.CONFIG.KAT_RATIO seed_ratio = headphones.CONFIG.KAT_RATIO
elif provider == 'Apollo.rip': elif provider == 'Apollo.rip':
seed_ratio = headphones.CONFIG.APOLLO_RATIO seed_ratio = headphones.CONFIG.APOLLO_RATIO
elif provider == 'PassTheHeadphones.Me': elif provider == 'Redacted':
seed_ratio = headphones.CONFIG.PTH_RATIO seed_ratio = headphones.CONFIG.REDACTED_RATIO
elif provider == 'The Pirate Bay': elif provider == 'The Pirate Bay':
seed_ratio = headphones.CONFIG.PIRATEBAY_RATIO seed_ratio = headphones.CONFIG.PIRATEBAY_RATIO
elif provider == 'Old Pirate Bay': elif provider == 'Old Pirate Bay':
@@ -277,7 +277,7 @@ def do_sorted_search(album, new, losslessOnly, choose_specific_download=False):
headphones.CONFIG.WAFFLES or headphones.CONFIG.WAFFLES or
headphones.CONFIG.RUTRACKER or headphones.CONFIG.RUTRACKER or
headphones.CONFIG.APOLLO or headphones.CONFIG.APOLLO or
headphones.CONFIG.PTH or headphones.CONFIG.REDACTED or
headphones.CONFIG.STRIKE or headphones.CONFIG.STRIKE or
headphones.CONFIG.TQUATTRECENTONZE) headphones.CONFIG.TQUATTRECENTONZE)
@@ -1206,7 +1206,7 @@ def verifyresult(title, artistterm, term, lossless):
def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
choose_specific_download=False): choose_specific_download=False):
global apolloobj # persistent apollo.rip api object to reduce number of login attempts global apolloobj # persistent apollo.rip api object to reduce number of login attempts
global pthobj # persistent pth api object to reduce number of login attempts global redobj # persistent redacted api object to reduce number of login attempts
global ruobj # and rutracker global ruobj # and rutracker
reldate = album['ReleaseDate'] reldate = album['ReleaseDate']
@@ -1613,10 +1613,10 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
provider, provider,
'torrent', True)) 'torrent', True))
# PassTheHeadphones.me - Using same logic as What.CD as it's also Gazelle, so should really make this into something reusable # Redacted - Using same logic as What.CD as it's also Gazelle, so should really make this into something reusable
if headphones.CONFIG.PTH: if headphones.CONFIG.REDACTED:
provider = "PassTheHeadphones.me" provider = "Redacted"
providerurl = "https://passtheheadphones.me/" providerurl = "https://redacted.ch"
bitrate = None bitrate = None
bitrate_string = bitrate bitrate_string = bitrate
@@ -1639,7 +1639,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
bitrate_string = encoding_string bitrate_string = encoding_string
if bitrate_string not in gazelleencoding.ALL_ENCODINGS: if bitrate_string not in gazelleencoding.ALL_ENCODINGS:
logger.info( logger.info(
u"Your preferred bitrate is not one of the available PTH filters, so not using it as a search parameter.") u"Your preferred bitrate is not one of the available RED filters, so not using it as a search parameter.")
maxsize = 10000000000 maxsize = 10000000000
elif headphones.CONFIG.PREFERRED_QUALITY == 1 or allow_lossless: # Highest quality including lossless elif headphones.CONFIG.PREFERRED_QUALITY == 1 or allow_lossless: # Highest quality including lossless
search_formats = [gazelleformat.FLAC, gazelleformat.MP3] search_formats = [gazelleformat.FLAC, gazelleformat.MP3]
@@ -1648,28 +1648,28 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
search_formats = [gazelleformat.MP3] search_formats = [gazelleformat.MP3]
maxsize = 300000000 maxsize = 300000000
if not pthobj or not pthobj.logged_in(): if not redobj or not redobj.logged_in():
try: try:
logger.info(u"Attempting to log in to PassTheHeadphones.me...") logger.info(u"Attempting to log in to Redacted...")
pthobj = gazelleapi.GazelleAPI(headphones.CONFIG.PTH_USERNAME, redobj = gazelleapi.GazelleAPI(headphones.CONFIG.REDACTED_USERNAME,
headphones.CONFIG.PTH_PASSWORD, headphones.CONFIG.REDACTED_PASSWORD,
headphones.CONFIG.PTH_URL) providerurl)
pthobj._login() redobj._login()
except Exception as e: except Exception as e:
pthobj = None redobj = None
logger.error(u"PassTheHeadphones credentials incorrect or site is down. Error: %s %s" % ( logger.error(u"Redacted credentials incorrect or site is down. Error: %s %s" % (
e.__class__.__name__, str(e))) e.__class__.__name__, str(e)))
if pthobj and pthobj.logged_in(): if redobj and redobj.logged_in():
logger.info(u"Searching %s..." % provider) logger.info(u"Searching %s..." % provider)
all_torrents = [] all_torrents = []
for search_format in search_formats: for search_format in search_formats:
if usersearchterm: if usersearchterm:
all_torrents.extend( all_torrents.extend(
pthobj.search_torrents(searchstr=usersearchterm, format=search_format, redobj.search_torrents(searchstr=usersearchterm, format=search_format,
encoding=bitrate_string)['results']) encoding=bitrate_string)['results'])
else: else:
all_torrents.extend(pthobj.search_torrents(artistname=semi_clean_artist_term, all_torrents.extend(redobj.search_torrents(artistname=semi_clean_artist_term,
groupname=semi_clean_album_term, groupname=semi_clean_album_term,
format=search_format, format=search_format,
encoding=bitrate_string)['results']) encoding=bitrate_string)['results'])
@@ -1709,7 +1709,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
torrent.group.update_group_data() # will load the file_path for the individual torrents torrent.group.update_group_data() # will load the file_path for the individual torrents
resultlist.append((torrent.file_path, resultlist.append((torrent.file_path,
torrent.size, torrent.size,
pthobj.generate_torrent_link(torrent.id), redobj.generate_torrent_link(torrent.id),
provider, provider,
'torrent', True)) 'torrent', True))
@@ -2056,7 +2056,7 @@ def preprocess(resultlist):
headers['User-Agent'] = USER_AGENT headers['User-Agent'] = USER_AGENT
elif result[3] == 'Apollo.rip': elif result[3] == 'Apollo.rip':
headers['User-Agent'] = 'Headphones' headers['User-Agent'] = 'Headphones'
elif result[3] == 'PassTheHeadphones.me': elif result[3] == 'Redacted':
headers['User-Agent'] = 'Headphones' headers['User-Agent'] = 'Headphones'
elif result[3] == "The Pirate Bay" or result[3] == "Old Pirate Bay": elif result[3] == "The Pirate Bay" or result[3] == "Old Pirate Bay":
headers[ headers[
+4 -5
View File
@@ -1234,11 +1234,10 @@ class WebInterface(object):
"apollo_password": headphones.CONFIG.APOLLO_PASSWORD, "apollo_password": headphones.CONFIG.APOLLO_PASSWORD,
"apollo_ratio": headphones.CONFIG.APOLLO_RATIO, "apollo_ratio": headphones.CONFIG.APOLLO_RATIO,
"apollo_url": headphones.CONFIG.APOLLO_URL, "apollo_url": headphones.CONFIG.APOLLO_URL,
"use_pth": checked(headphones.CONFIG.PTH), "use_redacted": checked(headphones.CONFIG.REDACTED),
"pth_username": headphones.CONFIG.PTH_USERNAME, "redacted_username": headphones.CONFIG.REDACTED_USERNAME,
"pth_password": headphones.CONFIG.PTH_PASSWORD, "redacted_password": headphones.CONFIG.REDACTED_PASSWORD,
"pth_ratio": headphones.CONFIG.PTH_RATIO, "redacted_ratio": headphones.CONFIG.REDACTED_RATIO,
"pth_url": headphones.CONFIG.PTH_URL,
"use_strike": checked(headphones.CONFIG.STRIKE), "use_strike": checked(headphones.CONFIG.STRIKE),
"strike_ratio": headphones.CONFIG.STRIKE_RATIO, "strike_ratio": headphones.CONFIG.STRIKE_RATIO,
"use_tquattrecentonze": checked(headphones.CONFIG.TQUATTRECENTONZE), "use_tquattrecentonze": checked(headphones.CONFIG.TQUATTRECENTONZE),
+2 -3
View File
@@ -11,6 +11,7 @@ import sys
import json import json
import time import time
import requests as requests import requests as requests
import headphones
from .user import User from .user import User
from .artist import Artist from .artist import Artist
@@ -32,9 +33,7 @@ class GazelleAPI(object):
default_headers = { default_headers = {
'Connection': 'keep-alive', 'Connection': 'keep-alive',
'Cache-Control': 'max-age=0', 'Cache-Control': 'max-age=0',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3)'\ 'User-Agent': 'Headphones/%s' % headphones.CURRENT_VERSION,
'AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79'\
'Safari/535.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9'\ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9'\
',*/*;q=0.8', ',*/*;q=0.8',
'Accept-Encoding': 'gzip,deflate,sdch', 'Accept-Encoding': 'gzip,deflate,sdch',