From e7b33d804cb3570e36af1755e32fbbfcdf7230bc Mon Sep 17 00:00:00 2001 From: Aaron Cohen Date: Sun, 8 Jul 2012 00:15:14 -0700 Subject: [PATCH] Adding Waffles.fm search capability --- data/interfaces/default/config.html | 14 ++++++ headphones/__init__.py | 19 ++++++-- headphones/searcher.py | 75 +++++++++++++++++++++++++++-- headphones/webserve.py | 8 ++- 4 files changed, 109 insertions(+), 7 deletions(-) diff --git a/data/interfaces/default/config.html b/data/interfaces/default/config.html index 8cac8612..fec251c0 100644 --- a/data/interfaces/default/config.html +++ b/data/interfaces/default/config.html @@ -252,6 +252,19 @@
+
+ +
+
+
+ + +
+
+ + +
+
@@ -764,6 +777,7 @@ initConfigCheckbox("#usenewznab"); initConfigCheckbox("#usenewzbin"); initConfigCheckbox("#usenzbsorg"); + initConfigCheckbox("#usewaffles"); initConfigCheckbox("#useblackhole"); initConfigCheckbox("#useapi"); } diff --git a/headphones/__init__.py b/headphones/__init__.py index 54512bd9..3c9196fc 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -142,6 +142,9 @@ NUMBEROFSEEDERS = 10 ISOHUNT = None KAT = None MININOVA = None +WAFFLES = None +WAFFLES_UID = None +WAFFLES_PASSKEY = None DOWNLOAD_TORRENT_DIR = None INTERFACE = None @@ -233,7 +236,7 @@ def initialize(): CURRENT_VERSION, LATEST_VERSION, CHECK_GITHUB, CHECK_GITHUB_ON_STARTUP, CHECK_GITHUB_INTERVAL, MUSIC_DIR, DESTINATION_DIR, PREFERRED_QUALITY, PREFERRED_BITRATE, DETECT_BITRATE, \ ADD_ARTISTS, CORRECT_METADATA, MOVE_FILES, RENAME_FILES, FOLDER_FORMAT, FILE_FORMAT, CLEANUP_FILES, INCLUDE_EXTRAS, AUTOWANT_UPCOMING, AUTOWANT_ALL, \ ADD_ALBUM_ART, EMBED_ALBUM_ART, EMBED_LYRICS, DOWNLOAD_DIR, BLACKHOLE, BLACKHOLE_DIR, USENET_RETENTION, SEARCH_INTERVAL, \ - TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, ISOHUNT, KAT, MININOVA, DOWNLOAD_TORRENT_DIR, \ + TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, ISOHUNT, KAT, MININOVA, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, DOWNLOAD_TORRENT_DIR, \ LIBRARYSCAN_INTERVAL, DOWNLOAD_SCAN_INTERVAL, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \ NZBMATRIX, NZBMATRIX_USERNAME, NZBMATRIX_APIKEY, NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, \ NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \ @@ -251,6 +254,7 @@ def initialize(): CheckSection('Newznab') CheckSection('NZBsorg') CheckSection('Newzbin') + CheckSection('Waffles') CheckSection('Prowl') CheckSection('XBMC') CheckSection('NMA') @@ -313,7 +317,11 @@ def initialize(): KAT = bool(check_setting_int(CFG, 'General', 'kat', 0)) MININOVA = bool(check_setting_int(CFG, 'General', 'mininova', 0)) DOWNLOAD_TORRENT_DIR = check_setting_str(CFG, 'General', 'download_torrent_dir', '') - + + WAFFLES = bool(check_setting_int(CFG, 'Waffles', 'waffles', 0)) + WAFFLES_UID = check_setting_str(CFG, 'Waffles', 'waffles_uid', '') + WAFFLES_PASSKEY = check_setting_str(CFG, 'Waffles', 'waffles_passkey', '') + SAB_HOST = check_setting_str(CFG, 'SABnzbd', 'sab_host', '') SAB_USERNAME = check_setting_str(CFG, 'SABnzbd', 'sab_username', '') SAB_PASSWORD = check_setting_str(CFG, 'SABnzbd', 'sab_password', '') @@ -570,7 +578,12 @@ def config_write(): new_config['General']['kat'] = int(KAT) new_config['General']['mininova'] = int(MININOVA) new_config['General']['download_torrent_dir'] = DOWNLOAD_TORRENT_DIR - + + new_config['Waffles'] = {} + new_config['Waffles']['waffles'] = int(WAFFLES) + new_config['Waffles']['waffles_uid'] = WAFFLES_UID + new_config['Waffles']['waffles_passkey'] = WAFFLES_PASSKEY + new_config['General']['search_interval'] = SEARCH_INTERVAL new_config['General']['libraryscan_interval'] = LIBRARYSCAN_INTERVAL new_config['General']['download_scan_interval'] = DOWNLOAD_SCAN_INTERVAL diff --git a/headphones/searcher.py b/headphones/searcher.py index f95bc2a3..41b6d49c 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -97,7 +97,7 @@ def searchforalbum(albumid=None, new=False, lossless=False): else: foundNZB = searchNZB(result['AlbumID'], new) - if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA) and foundNZB == "none": + if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA or headphones.WAFFLES) and foundNZB == "none": if result['Status'] == "Wanted Lossless": searchTorrent(result['AlbumID'], new, losslessOnly=True) else: @@ -109,7 +109,7 @@ def searchforalbum(albumid=None, new=False, lossless=False): if (headphones.NZBMATRIX or headphones.NEWZNAB or headphones.NZBSORG or headphones.NEWZBIN) and (headphones.SAB_HOST or headphones.BLACKHOLE): foundNZB = searchNZB(albumid, new, lossless) - if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA) and foundNZB == "none": + if (headphones.KAT or headphones.ISOHUNT or headphones.MININOVA or headphones.WAFFLES) and foundNZB == "none": searchTorrent(albumid, new, lossless) def searchNZB(albumid=None, new=False, losslessOnly=False): @@ -623,7 +623,8 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): # Replace bad characters in the term and unicode it term = re.sub('[\.\-\/]', ' ', term).encode('utf-8') artistterm = re.sub('[\.\-\/]', ' ', cleanartist).encode('utf-8') - + albumterm = re.sub('[\.\-\/]', ' ', cleanalbum).encode('utf-8') + logger.info("Searching torrents for %s since it was marked as wanted" % term) resultlist = [] @@ -699,6 +700,74 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False): except Exception, e: logger.error(u"An unknown error occured in the KAT parser: %s" % e) + if headphones.WAFFLES: +# https://www.waffles.fm/browse.php?uid=xxx&passkey=xxx&rss=1&q=artist%3A%22The%20Beatles%22%20album%3A%22Rubber%20Soul%22%20format%3A%22MP3%22%20bitrate%3A%28V0%20OR%20APX%29%20is%3A%28vbr%29&c0=1&s=added&d=desc + provider = "Waffles.fm" + providerurl = url_fix("https://www.waffles.fm/browse.php") + + bitrate = None + if headphones.PREFERRED_QUALITY == 3 or losslessOnly: + format = "FLAC" + bitrate = "(Lossless)" + maxsize = 10000000000 + elif headphones.PREFERRED_QUALITY: + format = "(FLAC OR MP3)" + maxsize = 10000000000 + else: + format = "MP3" + maxsize = 300000000 + + query_items = ['artist:"%s"' % artistterm, + 'album:"%s"' % albumterm, + 'format:"%s"' % format, + 'size:[0 TO %d]' % maxsize, + '-seeders:0'] # cut out dead torrents + if bitrate: + query_items.append('bitrate:"%s"' % bitrate) + + params = { + "uid": headphones.WAFFLES_UID, + "passkey": headphones.WAFFLES_PASSKEY, + "rss": "1", + "c0": "1", + "s": "seeders", # sort by + "d": "desc" # direction + } + + searchURL = "%s?%s&q=%s" % (providerurl, urllib.urlencode(params), urllib.quote(" ".join(query_items))) + + try: + data = urllib2.urlopen(searchURL, timeout=20).read() + except urllib2.URLError, e: + logger.warn('Error fetching data from %s: %s' % (provider, e)) + data = False + + if data: + + d = feedparser.parse(data) + if not len(d.entries): + logger.info(u"No results found from %s for %s" % (provider, term)) + pass + + else: + for item in d.entries: + try: + title_match = re.search(r"(.+)\[(.+)\]$", item.title) + title = title_match.group(1).strip() + details = title_match.group(2).split("-") + + desc_match = re.search(r"Size: (\d+)<", item.description) + size = desc_match.group(1) + + url = item.link + + resultlist.append((title, size, url, provider)) + logger.info('Found %s. Size: %s' % (title, helpers.bytes_to_mb(size))) + except Exception, e: + logger.error(u"An error occurred while trying to parse the response from Waffles.fm: %s" % e) + + + if headphones.ISOHUNT: provider = "ISOhunt" providerurl = url_fix("http://isohunt.com/js/rss/" + term) diff --git a/headphones/webserve.py b/headphones/webserve.py index 9b23824b..c477888e 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -394,6 +394,9 @@ class WebInterface(object): "use_isohunt" : checked(headphones.ISOHUNT), "use_kat" : checked(headphones.KAT), "use_mininova" : checked(headphones.MININOVA), + "use_waffles" : checked(headphones.WAFFLES), + "waffles_uid" : headphones.WAFFLES_UID, + "waffles_passkey": headphones.WAFFLES_PASSKEY, "pref_qual_0" : radio(headphones.PREFERRED_QUALITY, 0), "pref_qual_1" : radio(headphones.PREFERRED_QUALITY, 1), "pref_qual_3" : radio(headphones.PREFERRED_QUALITY, 3), @@ -454,7 +457,7 @@ class WebInterface(object): sab_host=None, sab_username=None, sab_apikey=None, sab_password=None, sab_category=None, download_dir=None, blackhole=0, blackhole_dir=None, usenet_retention=None, nzbmatrix=0, nzbmatrix_username=None, nzbmatrix_apikey=None, newznab=0, newznab_host=None, newznab_apikey=None, nzbsorg=0, nzbsorg_uid=None, nzbsorg_hash=None, newzbin=0, newzbin_uid=None, newzbin_password=None, preferred_quality=0, preferred_bitrate=None, detect_bitrate=0, move_files=0, - torrentblackhole_dir=None, download_torrent_dir=None, numberofseeders=10, use_isohunt=0, use_kat=0, use_mininova=0, + torrentblackhole_dir=None, download_torrent_dir=None, numberofseeders=10, use_isohunt=0, use_kat=0, use_mininova=0, waffles=0, waffles_uid=None, waffles_passkey=None, rename_files=0, correct_metadata=0, cleanup_files=0, add_album_art=0, embed_album_art=0, embed_lyrics=0, destination_dir=None, folder_format=None, file_format=None, include_extras=0, autowant_upcoming=False, autowant_all=False, interface=None, log_dir=None, music_encoder=0, encoder=None, bitrate=None, samplingfrequency=None, encoderfolder=None, advancedencoder=None, encoderoutputformat=None, encodervbrcbr=None, encoderquality=None, encoderlossless=0, prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=0, xbmc_enabled=0, xbmc_host=None, xbmc_username=None, xbmc_password=None, xbmc_update=0, xbmc_notify=0, @@ -497,6 +500,9 @@ class WebInterface(object): headphones.ISOHUNT = use_isohunt headphones.KAT = use_kat headphones.MININOVA = use_mininova + headphones.WAFFLES = waffles + headphones.WAFFLES_UID = waffles_uid + headphones.WAFFLES_PASSKEY = waffles_passkey headphones.PREFERRED_QUALITY = int(preferred_quality) headphones.PREFERRED_BITRATE = preferred_bitrate headphones.DETECT_BITRATE = detect_bitrate