From 6b30ed0ba6a338bd5df238fc244ddf8e14ef4379 Mon Sep 17 00:00:00 2001 From: lepricon49 Date: Sat, 12 Sep 2015 13:35:48 -0700 Subject: [PATCH 1/3] Stop JS links from scrolling to the top of the page Changed all Using href="#" to href="javascript:void(0)". Using "#" causes the browser to jump to the top of the page when the hyperlink is clicked (default empty # anchor position). Using "javascript:void(0)" will not change the browser's scroll position. --- data/interfaces/default/album.html | 22 +++++++++--------- data/interfaces/default/artist.html | 24 ++++++++++---------- data/interfaces/default/base.html | 6 ++--- data/interfaces/default/config.html | 2 +- data/interfaces/default/history.html | 14 ++++++------ data/interfaces/default/manage.html | 18 +++++++-------- data/interfaces/default/managemanual.html | 8 +++---- data/interfaces/default/manageunmatched.html | 8 +++---- data/interfaces/default/upcoming.html | 2 +- 9 files changed, 52 insertions(+), 52 deletions(-) diff --git a/data/interfaces/default/album.html b/data/interfaces/default/album.html index 06ac7e10..13223743 100644 --- a/data/interfaces/default/album.html +++ b/data/interfaces/default/album.html @@ -14,15 +14,15 @@ Delete Album %if album['Status'] == 'Skipped' or album['Status'] == 'Ignored': - Mark Album as Wanted + Mark Album as Wanted %elif album['Status'] == 'Wanted': - Force Check - Mark Album as Skipped + Force Check + Mark Album as Skipped %else: - Retry Download - Try New Version + Retry Download + Try New Version %endif - Choose Alternate Release + Choose Alternate Release - Edit Search Term + Edit Search Term - Choose Specific Download + Choose Specific Download @@ -66,7 +66,7 @@
- + @@ -78,7 +78,7 @@
Are you sure you want to ignore Local Album: ${album['AlbumTitle']} from future matching?

- +
@@ -97,7 +97,7 @@
- + diff --git a/data/interfaces/default/upcoming.html b/data/interfaces/default/upcoming.html index dbe7b254..97046f1c 100644 --- a/data/interfaces/default/upcoming.html +++ b/data/interfaces/default/upcoming.html @@ -3,7 +3,7 @@ <%def name="headerIncludes()">
From 7f4d10c85d5537528d1eb2b9e5e12979bfc51039 Mon Sep 17 00:00:00 2001 From: lepricon49 Date: Sun, 13 Sep 2015 10:54:05 -0700 Subject: [PATCH 2/3] Add magnet support for KAT rTorrent via blackhole KAT torrents downloads were 100% broken. This is a temporary hack to get KAT partially working. --- data/interfaces/default/config.html | 7 +++- data/interfaces/default/css/style.css | 4 +-- data/interfaces/default/css/style.less | 4 +-- headphones/config.py | 2 +- headphones/searcher.py | 49 ++++++++++++++++++++------ headphones/webserve.py | 1 + 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index bf99dafd..aad752a5 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -336,9 +336,14 @@ Convert + +
- Note: opening magnet URL's is not suitable for headless/console/terminal servers. + Note: Opening magnet URLs is not suitable for headless/console/terminal servers.
Embed only works for rTorrent.
diff --git a/data/interfaces/default/css/style.css b/data/interfaces/default/css/style.css index a6723818..ef8047c7 100644 --- a/data/interfaces/default/css/style.css +++ b/data/interfaces/default/css/style.css @@ -334,7 +334,7 @@ form .row label { font-size: 12px; line-height: normal; padding-top: 7px; - width: 175px; + width: 170px; } form .row label.inline { margin-right: 5px; @@ -368,7 +368,7 @@ form .row small { display: block; font-size: 9px; line-height: 12px; - margin-left: 175px; + margin-left: 170px; margin-top: 3px; } form .left label { diff --git a/data/interfaces/default/css/style.less b/data/interfaces/default/css/style.less index b03057c2..3e0f9659 100644 --- a/data/interfaces/default/css/style.less +++ b/data/interfaces/default/css/style.less @@ -190,7 +190,7 @@ form { font-size: 12px; line-height: normal; padding-top: 7px; - width: 175px; + width: 170px; &.inline { margin-right: 5px; @@ -216,7 +216,7 @@ form { display: block; font-size: 9px; line-height: 12px; - margin-left: 175px; + margin-left: 170px; margin-top: 3px; } } diff --git a/headphones/config.py b/headphones/config.py index e2a122e2..7db9509b 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -160,7 +160,7 @@ _CONFIG_DEFINITIONS = { 'OMGWTFNZBS': (int, 'omgwtfnzbs', 0), 'OMGWTFNZBS_APIKEY': (str, 'omgwtfnzbs', ''), 'OMGWTFNZBS_UID': (str, 'omgwtfnzbs', ''), - 'OPEN_MAGNET_LINKS': (int, 'General', 0), # 0: Ignore, 1: Open, 2: Convert + 'OPEN_MAGNET_LINKS': (int, 'General', 0), # 0: Ignore, 1: Open, 2: Convert, 3: Embed (rtorrent) 'MAGNET_LINKS': (int, 'General', 0), 'OSX_NOTIFY_APP': (str, 'OSX_Notify', '/Applications/Headphones'), 'OSX_NOTIFY_ENABLED': (int, 'OSX_Notify', 0), diff --git a/headphones/searcher.py b/headphones/searcher.py index 7dbcf5ba..6f9ea87a 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -165,7 +165,7 @@ def get_seed_ratio(provider): elif provider == 'Mininova': seed_ratio = headphones.CONFIG.MININOVA_RATIO elif provider == 'Strike': - seed_ratio = headphones.CONFIG.STRIKE_RATIO + seed_ratio = headphones.CONFIG.STRIKE_RATIO else: seed_ratio = None @@ -711,7 +711,7 @@ def searchNZB(album, new=False, losslessOnly=False, albumlength=None, choose_spe def send_to_downloader(data, bestqual, album): - logger.info(u'Found best result from %s: %s - %s', bestqual[3], bestqual[2], bestqual[0], helpers.bytes_to_mb(bestqual[1])) + logger.info(u'Found best result from %s: [%s] - %s - %s', bestqual[3], bestqual[2], bestqual[0], helpers.bytes_to_mb(bestqual[1])) # Get rid of any dodgy chars here so we can prevent sab from renaming our downloads kind = bestqual[4] seed_ratio = None @@ -810,8 +810,11 @@ def send_to_downloader(data, bestqual, album): logger.warning("Unable to convert magnet with hash " \ "'%s' into a torrent file.", torrent_hash) return + elif headphones.CONFIG.MAGNET_LINKS == 3: + torrent_to_file(download_path, data) + return else: - logger.error("Cannot save magnet link in blackhole. " \ + logger.error("Ignoring magnet links for blackhole. " \ "Please switch your torrent downloader to " \ "Transmission or uTorrent, or allow Headphones " \ "to open or convert magnet links") @@ -1198,20 +1201,41 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, choose seeders = item['seeds'] url = item['torrentLink'] size = int(item['size']) + hash = item['hash'] + # The "tr" querystring used in magnetUri is a hack since it assumes the tracker is always the same for KAT. + # It currently works for all torrents tested but it should be changed to load the HTML, and parse out the real magnet URI. + magnetUri = r"magnet:?xt=urn:btih:" + hash + r"&tr=udp%3A%2F%2Fopen.demonii.com%3A1337" if format == "2": torrent = request.request_content(url, headers=headers) if not torrent or (int(torrent.find(".mp3")) > 0 and int(torrent.find(".flac")) < 1): rightformat = False - if rightformat and size < maxsize and minimumseeders < int(seeders): - match = True - logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) - else: - match = False - logger.info('%s is larger than the maxsize, the wrong format or has too little seeders for this category, skipping. (Size: %i bytes, Seeders: %d, Format: %s)', title, size, int(seeders), rightformat) + #if rightformat and size < maxsize and minimumseeders < int(seeders): + # match = True + # logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) + #else: + # match = False + # logger.info('%s is larger than the maxsize, the wrong format or has too little seeders for this category, skipping. (Size: %i bytes, Seeders: %d, Format: %s)', title, size, int(seeders), rightformat) - resultlist.append((title, size, url, provider, 'torrent', match)) + match = False + if rightformat: + if size < maxsize: + if minimumseeders < int(seeders): + match = True + logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) + else: + logger.info('%s has too little seeders for this category, skipping. (Size: %i bytes, Seeders: %d, Format: %s)', title, size, int(seeders), rightformat) + else: + logger.info('%s is larger than the maxsize for this category, skipping. (Size: %i bytes, Seeders: %d, Format: %s)', title, size, int(seeders), rightformat) + else: + logger.info('%s is the wrong format for this category, skipping. (Size: %i bytes, Seeders: %d, Format: %s)', title, size, int(seeders), rightformat) + + + # The URL returned from KAT is NOT a torrent URL. It is a jump page. + # More work needs to be done here to get this to work right for real torrent files. Refer to CouchPotatos HTML parsing method. + #resultlist.append((title, size, url, provider, 'torrent', match)) + resultlist.append((title, size, magnetUri, provider, 'magnet', match)) except Exception as e: logger.exception("Unhandled exception in the KAT parser") @@ -1669,7 +1693,6 @@ def preprocess(resultlist): headers = {} if result[3] == 'Kick Ass Torrents': - #headers['Referer'] = 'http://kat.ph/' headers['User-Agent'] = USER_AGENT elif result[3] == 'What.cd': headers['User-Agent'] = 'Headphones' @@ -1677,6 +1700,10 @@ def preprocess(resultlist): headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2243.2 Safari/537.36' return request.request_content(url=result[2], headers=headers), result + if result[4] == 'magnet': + magnet_link = result[2] + return "d10:magnet-uri%d:%se" % (len(magnet_link), magnet_link), result + else: headers = {'User-Agent': USER_AGENT} diff --git a/headphones/webserve.py b/headphones/webserve.py index 121e8667..4966ec5b 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1153,6 +1153,7 @@ class WebInterface(object): "magnet_links_0": radio(headphones.CONFIG.MAGNET_LINKS, 0), "magnet_links_1": radio(headphones.CONFIG.MAGNET_LINKS, 1), "magnet_links_2": radio(headphones.CONFIG.MAGNET_LINKS, 2), + "magnet_links_3": radio(headphones.CONFIG.MAGNET_LINKS, 3), "log_dir": headphones.CONFIG.LOG_DIR, "cache_dir": headphones.CONFIG.CACHE_DIR, "interface_list": interface_list, From c78e8764a0799ba974daa94247c97ace40c4f0bd Mon Sep 17 00:00:00 2001 From: lepricon49 Date: Sun, 13 Sep 2015 10:57:14 -0700 Subject: [PATCH 3/3] Add snatched email indicator prefix Prefix subject with "Snatched: " to make it more apparent that it is not the final download email notification. --- headphones/searcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headphones/searcher.py b/headphones/searcher.py index 6f9ea87a..530cc339 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -951,7 +951,7 @@ def send_to_downloader(data, bestqual, album): logger.info(u"Sending Email notification") email = notifiers.Email() message = 'Snatched from ' + provider + '. ' + name - email.notify(title, message) + email.notify("Snatched: " + title, message) def verifyresult(title, artistterm, term, lossless):