Merge pull request #2790 from noam09/develop

Apollo replaces WCD, PTH object fix, Deluge logging tweak
This commit is contained in:
AdeHub
2016-12-11 17:17:38 +13:00
committed by GitHub
5 changed files with 59 additions and 52 deletions

View File

@@ -633,24 +633,24 @@
<fieldset>
<div class="row checkbox left">
<input id="use_whatcd" type="checkbox" class="bigcheck" name="use_whatcd" value="1" ${config['use_whatcd']} /><label for="use_whatcd"><span class="option">What.cd</span></label>
<input id="use_apollo" type="checkbox" class="bigcheck" name="use_apollo" value="1" ${config['use_apollo']} /><label for="use_apollo"><span class="option">Apollo.rip</span></label>
</div>
<div class="config">
<div class="row">
<label>Username</label>
<input type="text" name="whatcd_username" value="${config['whatcd_username']}" size="36">
<input type="text" name="apollo_username" value="${config['apollo_username']}" size="36">
</div>
<div class="row">
<label>Password</label>
<input type="password" name="whatcd_password" value="${config['whatcd_password'] | h}" size="36">
<input type="password" name="apollo_password" value="${config['apollo_password'] | h}" size="36">
</div>
<div class="row">
<label>URL</label>
<input type="text" name="whatcd_url" value="${config['whatcd_url']}" size="36">
<input type="text" name="apollo_url" value="${config['apollo_url']}" size="36">
</div>
<div class="row">
<label>Seed Ratio</label>
<input type="text" class="override-float" name="whatcd_ratio" value="${config['whatcd_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="apollo_ratio" value="${config['apollo_ratio']}" size="10" title="Stop seeding when ratio met, 0 = unlimited. Scheduled job will remove torrent when post processed and finished seeding">
</div>
</div>
</fieldset>
@@ -2439,7 +2439,7 @@
initConfigCheckbox("#use_mininova");
initConfigCheckbox("#use_waffles");
initConfigCheckbox("#use_rutracker");
initConfigCheckbox("#use_whatcd");
initConfigCheckbox("#use_apollo");
initConfigCheckbox("#use_pth");
initConfigCheckbox("#use_strike");
initConfigCheckbox("#api_enabled");

View File

@@ -39,6 +39,11 @@ _CONFIG_DEFINITIONS = {
'ALBUM_COMPLETION_PCT': (int, 'Advanced', 80),
'API_ENABLED': (int, 'General', 0),
'API_KEY': (str, 'General', ''),
'APOLLO': (int, 'Apollo.rip', 0),
'APOLLO_PASSWORD': (str, 'Apollo.rip', ''),
'APOLLO_RATIO': (str, 'Apollo.rip', ''),
'APOLLO_USERNAME': (str, 'Apollo.rip', ''),
'APOLLO_URL': (str, 'Apollo.rip', 'https://apollo.rip'),
'AUTOWANT_ALL': (int, 'General', 0),
'AUTOWANT_MANUALLY_ADDED': (int, 'General', 1),
'AUTOWANT_UPCOMING': (int, 'General', 1),
@@ -290,11 +295,6 @@ _CONFIG_DEFINITIONS = {
'WAFFLES_PASSKEY': (str, 'Waffles', ''),
'WAFFLES_RATIO': (str, 'Waffles', ''),
'WAFFLES_UID': (str, 'Waffles', ''),
'WHATCD': (int, 'What.cd', 0),
'WHATCD_PASSWORD': (str, 'What.cd', ''),
'WHATCD_RATIO': (str, 'What.cd', ''),
'WHATCD_USERNAME': (str, 'What.cd', ''),
'WHATCD_URL': (str, 'What.cd', 'https://what.cd'),
'PTH': (int, 'PassTheHeadphones.me', 0),
'PTH_PASSWORD': (str, 'PassTheHeadphones.me', ''),
'PTH_RATIO': (str, 'PassTheHeadphones.me', ''),

View File

@@ -80,7 +80,7 @@ def addTorrent(link, data=None, name=None):
result = {}
retid = False
url_what = ['https://what.cd/', 'http://what.cd/']
url_apollo = ['https://apollo.rip/', 'http://apollo.rip/']
url_waffles = ['https://waffles.ch/', 'http://waffles.ch/']
if link.lower().startswith('magnet:'):
@@ -94,7 +94,7 @@ def addTorrent(link, data=None, name=None):
if link.lower().startswith(tuple(url_waffles)):
if 'rss=' not in link:
link = link + '&rss=1'
if link.lower().startswith(tuple(url_what)):
if link.lower().startswith(tuple(url_apollo)):
logger.debug('Deluge: Using different User-Agent for this site')
user_agent = 'Headphones'
# This method will make Deluge download the file
@@ -135,7 +135,10 @@ def addTorrent(link, data=None, name=None):
# remove '.torrent' suffix
if name[-len('.torrent'):] == '.torrent':
name = name[:-len('.torrent')]
logger.debug('Deluge: Sending Deluge torrent with name %s and content [%s...]' % (name, str(torrentfile)[:40]))
try:
logger.debug('Deluge: Sending Deluge torrent with name %s and content [%s...]' % (name, str(torrentfile)[:40]))
except:
logger.debug('Deluge: Sending Deluge torrent with problematic name and some content')
result = {'type': 'torrent',
'name': name,
'content': torrentfile}
@@ -445,6 +448,7 @@ def _add_torrent_file(result):
try:
# content is torrent file contents that needs to be encoded to base64
# this time let's try leaving the encoding as is
logger.debug('Deluge: There was a decoding issue, let\'s try again')
post_data = json.dumps({"method": "core.add_torrent_file",
"params": [result['name'] + '.torrent', b64encode(result['content']), {}],
"id": 22})

View File

@@ -45,9 +45,11 @@ TORRENT_TO_MAGNET_SERVICES = [
'https://torcache.net/torrent/%s.torrent',
]
# Persistent What.cd API object
gazelle = None
# Persistent Apollo.rip API object
apolloobj = None
# Persistent PTH API object
ruobj = None
pthobj = None
def fix_url(s, charset="utf-8"):
@@ -160,8 +162,8 @@ def get_seed_ratio(provider):
seed_ratio = headphones.CONFIG.RUTRACKER_RATIO
elif provider == 'Kick Ass Torrents':
seed_ratio = headphones.CONFIG.KAT_RATIO
elif provider == 'What.cd':
seed_ratio = headphones.CONFIG.WHATCD_RATIO
elif provider == 'Apollo.rip':
seed_ratio = headphones.CONFIG.APOLLO_RATIO
elif provider == 'PassTheHeadphones.Me':
seed_ratio = headphones.CONFIG.PTH_RATIO
elif provider == 'The Pirate Bay':
@@ -274,7 +276,7 @@ def do_sorted_search(album, new, losslessOnly, choose_specific_download=False):
headphones.CONFIG.MININOVA or
headphones.CONFIG.WAFFLES or
headphones.CONFIG.RUTRACKER or
headphones.CONFIG.WHATCD or
headphones.CONFIG.APOLLO or
headphones.CONFIG.PTH or
headphones.CONFIG.STRIKE)
@@ -1176,7 +1178,8 @@ def verifyresult(title, artistterm, term, lossless):
def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
choose_specific_download=False):
global gazelle # persistent what.cd 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 ruobj # and rutracker
reldate = album['ReleaseDate']
@@ -1468,9 +1471,9 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
if rulist:
resultlist.extend(rulist)
if headphones.CONFIG.WHATCD:
provider = "What.cd"
providerurl = "http://what.cd/"
if headphones.CONFIG.APOLLO:
provider = "Apollo.rip"
providerurl = "http://apollo.rip/"
bitrate = None
bitrate_string = bitrate
@@ -1493,7 +1496,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
bitrate_string = encoding_string
if bitrate_string not in gazelleencoding.ALL_ENCODINGS:
logger.info(
u"Your preferred bitrate is not one of the available What.cd filters, so not using it as a search parameter.")
u"Your preferred bitrate is not one of the available Apollo.rip filters, so not using it as a search parameter.")
maxsize = 10000000000
elif headphones.CONFIG.PREFERRED_QUALITY == 1 or allow_lossless: # Highest quality including lossless
search_formats = [gazelleformat.FLAC, gazelleformat.MP3]
@@ -1502,28 +1505,28 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
search_formats = [gazelleformat.MP3]
maxsize = 300000000
if not gazelle or not gazelle.logged_in():
if not apolloobj or not apolloobj.logged_in():
try:
logger.info(u"Attempting to log in to What.cd...")
gazelle = gazelleapi.GazelleAPI(headphones.CONFIG.WHATCD_USERNAME,
headphones.CONFIG.WHATCD_PASSWORD,
headphones.CONFIG.WHATCD_URL)
gazelle._login()
logger.info(u"Attempting to log in to Apollo.rip...")
apolloobj = gazelleapi.GazelleAPI(headphones.CONFIG.APOLLO_USERNAME,
headphones.CONFIG.APOLLO_PASSWORD,
headphones.CONFIG.APOLLO_URL)
apolloobj._login()
except Exception as e:
gazelle = None
logger.error(u"What.cd credentials incorrect or site is down. Error: %s %s" % (
apolloobj = None
logger.error(u"Apollo.rip credentials incorrect or site is down. Error: %s %s" % (
e.__class__.__name__, str(e)))
if gazelle and gazelle.logged_in():
if apolloobj and apolloobj.logged_in():
logger.info(u"Searching %s..." % provider)
all_torrents = []
for search_format in search_formats:
if usersearchterm:
all_torrents.extend(
gazelle.search_torrents(searchstr=usersearchterm, format=search_format,
apolloobj.search_torrents(searchstr=usersearchterm, format=search_format,
encoding=bitrate_string)['results'])
else:
all_torrents.extend(gazelle.search_torrents(artistname=semi_clean_artist_term,
all_torrents.extend(apolloobj.search_torrents(artistname=semi_clean_artist_term,
groupname=semi_clean_album_term,
format=search_format,
encoding=bitrate_string)['results'])
@@ -1563,7 +1566,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
torrent.group.update_group_data() # will load the file_path for the individual torrents
resultlist.append((torrent.file_path,
torrent.size,
gazelle.generate_torrent_link(torrent.id),
apolloobj.generate_torrent_link(torrent.id),
provider,
'torrent', True))
@@ -1593,7 +1596,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
bitrate_string = encoding_string
if bitrate_string not in gazelleencoding.ALL_ENCODINGS:
logger.info(
u"Your preferred bitrate is not one of the available What.cd filters, so not using it as a search parameter.")
u"Your preferred bitrate is not one of the available PTH filters, so not using it as a search parameter.")
maxsize = 10000000000
elif headphones.CONFIG.PREFERRED_QUALITY == 1 or allow_lossless: # Highest quality including lossless
search_formats = [gazelleformat.FLAC, gazelleformat.MP3]
@@ -1602,28 +1605,28 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
search_formats = [gazelleformat.MP3]
maxsize = 300000000
if not gazelle or not gazelle.logged_in():
if not pthobj or not pthobj.logged_in():
try:
logger.info(u"Attempting to log in to PassTheHeadphones.me...")
gazelle = gazelleapi.GazelleAPI(headphones.CONFIG.PTH_USERNAME,
pthobj = gazelleapi.GazelleAPI(headphones.CONFIG.PTH_USERNAME,
headphones.CONFIG.PTH_PASSWORD,
headphones.CONFIG.PTH_URL)
gazelle._login()
pthobj._login()
except Exception as e:
gazelle = None
pthobj = None
logger.error(u"PassTheHeadphones credentials incorrect or site is down. Error: %s %s" % (
e.__class__.__name__, str(e)))
if gazelle and gazelle.logged_in():
if pthobj and pthobj.logged_in():
logger.info(u"Searching %s..." % provider)
all_torrents = []
for search_format in search_formats:
if usersearchterm:
all_torrents.extend(
gazelle.search_torrents(searchstr=usersearchterm, format=search_format,
pthobj.search_torrents(searchstr=usersearchterm, format=search_format,
encoding=bitrate_string)['results'])
else:
all_torrents.extend(gazelle.search_torrents(artistname=semi_clean_artist_term,
all_torrents.extend(pthobj.search_torrents(artistname=semi_clean_artist_term,
groupname=semi_clean_album_term,
format=search_format,
encoding=bitrate_string)['results'])
@@ -1663,7 +1666,7 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None,
torrent.group.update_group_data() # will load the file_path for the individual torrents
resultlist.append((torrent.file_path,
torrent.size,
gazelle.generate_torrent_link(torrent.id),
pthobj.generate_torrent_link(torrent.id),
provider,
'torrent', True))
@@ -2008,7 +2011,7 @@ def preprocess(resultlist):
if result[3] == 'Kick Ass Torrents':
headers['Referer'] = 'https://torcache.net/'
headers['User-Agent'] = USER_AGENT
elif result[3] == 'What.cd':
elif result[3] == 'Apollo.rip':
headers['User-Agent'] = 'Headphones'
elif result[3] == 'PassTheHeadphones.me':
headers['User-Agent'] = 'Headphones'

View File

@@ -1224,11 +1224,11 @@ class WebInterface(object):
"rutracker_user": headphones.CONFIG.RUTRACKER_USER,
"rutracker_password": headphones.CONFIG.RUTRACKER_PASSWORD,
"rutracker_ratio": headphones.CONFIG.RUTRACKER_RATIO,
"use_whatcd": checked(headphones.CONFIG.WHATCD),
"whatcd_username": headphones.CONFIG.WHATCD_USERNAME,
"whatcd_password": headphones.CONFIG.WHATCD_PASSWORD,
"whatcd_ratio": headphones.CONFIG.WHATCD_RATIO,
"whatcd_url": headphones.CONFIG.WHATCD_URL,
"use_apollo": checked(headphones.CONFIG.APOLLO),
"apollo_username": headphones.CONFIG.APOLLO_USERNAME,
"apollo_password": headphones.CONFIG.APOLLO_PASSWORD,
"apollo_ratio": headphones.CONFIG.APOLLO_RATIO,
"apollo_url": headphones.CONFIG.APOLLO_URL,
"use_pth": checked(headphones.CONFIG.PTH),
"pth_username": headphones.CONFIG.PTH_USERNAME,
"pth_password": headphones.CONFIG.PTH_PASSWORD,
@@ -1435,7 +1435,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", "use_tquattrecentonze", "preferred_bitrate_allow_lossless", "detect_bitrate",
"use_apollo", "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",