Adding Waffles.fm search capability

This commit is contained in:
Aaron Cohen
2012-07-08 00:15:14 -07:00
parent be69c0c649
commit e7b33d804c
4 changed files with 109 additions and 7 deletions

View File

@@ -252,6 +252,19 @@
</div>
<div class="row checkbox">
<input type="checkbox" name="use_kat" value="1" ${config['use_kat']} /><label>Kick Ass Torrents</label></div>
<div class="row checkbox">
<input id="usewaffles" type="checkbox" name="waffles" onclick="initConfigCheckbox($(this));" value="1" ${config['use_waffles']} /><label>Use Waffles.fm</label>
</div>
<div class="config">
<div class="row">
<label>Waffles UID Number: </label>
<input type="text" name="waffles_uid" value="${config['waffles_uid']}" size="36" maxlength="40">
</div>
<div class="row">
<label>Waffles Passkey: </label>
<input type="text" name="waffles_passkey" value="${config['waffles_passkey']}" size="36" maxlength="40">
</div>
</div>
</fieldset>
</td>
@@ -764,6 +777,7 @@
initConfigCheckbox("#usenewznab");
initConfigCheckbox("#usenewzbin");
initConfigCheckbox("#usenzbsorg");
initConfigCheckbox("#usewaffles");
initConfigCheckbox("#useblackhole");
initConfigCheckbox("#useapi");
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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