mirror of
https://github.com/rembo10/headphones.git
synced 2026-06-25 20:13:51 +01:00
What.cd WIP, now using api rather than RSS
This commit is contained in:
@@ -155,8 +155,8 @@ WAFFLES = None
|
||||
WAFFLES_UID = None
|
||||
WAFFLES_PASSKEY = None
|
||||
WHATCD = None
|
||||
WHATCD_UID = None
|
||||
WHATCD_PASSKEY = None
|
||||
WHATCD_USERNAME = None
|
||||
WHATCD_PASSWORD = None
|
||||
DOWNLOAD_TORRENT_DIR = None
|
||||
|
||||
INTERFACE = None
|
||||
@@ -251,7 +251,7 @@ def initialize():
|
||||
LOSSLESS_DESTINATION_DIR, PREFERRED_QUALITY, PREFERRED_BITRATE, DETECT_BITRATE, ADD_ARTISTS, CORRECT_METADATA, MOVE_FILES, \
|
||||
RENAME_FILES, FOLDER_FORMAT, FILE_FORMAT, CLEANUP_FILES, INCLUDE_EXTRAS, 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, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, WHATCD, WHATCD_UID, WHATCD_PASSKEY, DOWNLOAD_TORRENT_DIR, \
|
||||
TORRENTBLACKHOLE_DIR, NUMBEROFSEEDERS, ISOHUNT, KAT, MININOVA, WAFFLES, WAFFLES_UID, WAFFLES_PASSKEY, WHATCD, WHATCD_USERNAME, WHATCD_PASSWORD, 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, NEWZNAB_ENABLED, EXTRA_NEWZNABS,\
|
||||
NZBSORG, NZBSORG_UID, NZBSORG_HASH, NEWZBIN, NEWZBIN_UID, NEWZBIN_PASSWORD, LASTFM_USERNAME, INTERFACE, FOLDER_PERMISSIONS, \
|
||||
@@ -348,8 +348,8 @@ def initialize():
|
||||
WAFFLES_PASSKEY = check_setting_str(CFG, 'Waffles', 'waffles_passkey', '')
|
||||
|
||||
WHATCD = bool(check_setting_int(CFG, 'What.cd', 'whatcd', 0))
|
||||
WHATCD_UID = check_setting_str(CFG, 'What.cd', 'whatcd_uid', '')
|
||||
WHATCD_PASSKEY = check_setting_str(CFG, 'What.cd', 'whatcd_passkey', '')
|
||||
WHATCD_USERNAME = check_setting_str(CFG, 'What.cd', 'whatcd_username', '')
|
||||
WHATCD_PASSWORD = check_setting_str(CFG, 'What.cd', 'whatcd_password', '')
|
||||
|
||||
SAB_HOST = check_setting_str(CFG, 'SABnzbd', 'sab_host', '')
|
||||
SAB_USERNAME = check_setting_str(CFG, 'SABnzbd', 'sab_username', '')
|
||||
@@ -631,8 +631,8 @@ def config_write():
|
||||
|
||||
new_config['What.cd'] = {}
|
||||
new_config['What.cd']['whatcd'] = int(WHATCD)
|
||||
new_config['What.cd']['whatcd_uid'] = WHATCD_UID
|
||||
new_config['What.cd']['whatcd_passkey'] = WHATCD_PASSKEY
|
||||
new_config['What.cd']['whatcd_username'] = WHATCD_USERNAME
|
||||
new_config['What.cd']['whatcd_password'] = WHATCD_PASSWORD
|
||||
|
||||
new_config['General']['search_interval'] = SEARCH_INTERVAL
|
||||
new_config['General']['libraryscan_interval'] = LIBRARYSCAN_INTERVAL
|
||||
|
||||
+48
-46
@@ -15,6 +15,7 @@
|
||||
|
||||
import urllib, urllib2, urlparse
|
||||
import lib.feedparser as feedparser
|
||||
import lib.whatapi as whatapi
|
||||
from xml.dom import minidom
|
||||
from xml.parsers.expat import ExpatError
|
||||
from StringIO import StringIO
|
||||
@@ -808,69 +809,70 @@ def searchTorrent(albumid=None, new=False, losslessOnly=False):
|
||||
|
||||
if headphones.WHATCD:
|
||||
provider = "What.cd"
|
||||
providerurl = url_fix("https://www.what.cd/browse.php")
|
||||
|
||||
bitrate = None
|
||||
if headphones.PREFERRED_QUALITY == 3 or losslessOnly:
|
||||
format = "FLAC"
|
||||
bitrate = "(Lossless)"
|
||||
format_regex = "FLAC"
|
||||
maxsize = 10000000000
|
||||
elif headphones.PREFERRED_QUALITY:
|
||||
format = "FLAC OR MP3"
|
||||
format_regex = "(FLAC|MP3)"
|
||||
maxsize = 10000000000
|
||||
else:
|
||||
format = "MP3"
|
||||
format_regex = "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.WHATCD_UID,
|
||||
"passkey": headphones.WHATCD_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
|
||||
whatcd = whatapi.getWhatcdNetwork(headphones.WHATCD_USERNAME, headphones.WHATCD_PASSWORD)
|
||||
except:
|
||||
whatcd = None
|
||||
logger.warn("What.cd credentials incorrect or site is down.")
|
||||
|
||||
if data:
|
||||
if whatcd:
|
||||
whatcd.enableCaching()
|
||||
|
||||
d = feedparser.parse(data)
|
||||
if not len(d.entries):
|
||||
logger.info(u"No results found from %s for %s" % (provider, term))
|
||||
pass
|
||||
artist = whatcd.getArtist(artistterm)
|
||||
artist_id = artist.getArtistId()
|
||||
else:
|
||||
artist_id = None
|
||||
|
||||
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("-")
|
||||
if artist_id: # will be None if artist not found
|
||||
logger.info(u"What.cd artist ID: %s" % artist_id)
|
||||
artist_releases = artist.getArtistReleases()
|
||||
logger.info(u"Found %d releases on what.cd for %s" % (len(artist_releases), artistterm))
|
||||
#Returns a list with all artist's releases in form of dictionary {releasetype, year, name, id}
|
||||
else:
|
||||
artist_releases = []
|
||||
|
||||
desc_match = re.search(r"Size: (\d+)<", item.description)
|
||||
size = desc_match.group(1)
|
||||
possible_matches = [ release for release in artist_releases if albumterm in release['name'] ]
|
||||
|
||||
url = item.link
|
||||
# cap at 10 matches, 1 per second to reduce hits on API...don't wanna get in trouble.
|
||||
# Might want to turn up number of matches later.
|
||||
max_torrent_info_reads = 10
|
||||
info_read_rate = 1
|
||||
|
||||
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 What.cd: %s" % e)
|
||||
match_torrents = []
|
||||
for i, release in enumerate(possible_matches[:max_torrent_info_reads]):
|
||||
if i > 0:
|
||||
time.sleep(info_read_rate)
|
||||
match_torrents.append(whatcd.getTorrent(release['id']))
|
||||
|
||||
# filter on format, size, and num seeders
|
||||
match_torrents = [ torrent for torrent in match_torrents
|
||||
if re.search(format_regex, torrent.getTorrentDetails(), flags=re.I)
|
||||
and torrent.getTorrentSize() <= maxsize
|
||||
and torrent.getTorrentSeeders() >= minimumseeders ]
|
||||
|
||||
# sort by times d/l'd
|
||||
if not len(possible_matches):
|
||||
logger.info(u"No results found from %s for %s after filtering" % (provider, term))
|
||||
elif len(match_torrents) > 1:
|
||||
match_torrents.sort(match_torrents, key=whatapi.Torrent.getTorrentSeeders)
|
||||
|
||||
for torrent in match_torrents:
|
||||
resultlist.append((torrent.getTorrentFolderName(),
|
||||
torrent.getTorrentSize(),
|
||||
torrent.getTorrentDownloadURL(),
|
||||
provider))
|
||||
|
||||
if headphones.ISOHUNT:
|
||||
provider = "isoHunt"
|
||||
|
||||
+10
-10
@@ -541,21 +541,21 @@ class WebInterface(object):
|
||||
|
||||
return serve_template(templatename="config.html", title="Settings", config=config)
|
||||
config.exposed = True
|
||||
|
||||
|
||||
|
||||
|
||||
def configUpdate(self, http_host='0.0.0.0', http_username=None, http_port=8181, http_password=None, launch_browser=0, api_enabled=0, api_key=None,
|
||||
download_scan_interval=None, nzb_search_interval=None, libraryscan_interval=None, 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, newznab_enabled=0, 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, 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, lossless_destination_dir=None, folder_format=None, file_format=None,
|
||||
include_extras=0, single=0, ep=0, compilation=0, soundtrack=0, live=0, remix=0, spokenword=0, audiobook=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, delete_lossless_files=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, nma_enabled=False,
|
||||
nma_apikey=None, nma_priority=0, nma_onsnatch=0, synoindex_enabled=False, mirror=None, customhost=None, customport=None, customsleep=None, hpuser=None, hppass=None,
|
||||
preferred_bitrate_high_buffer=None, preferred_bitrate_low_buffer=None, **kwargs):
|
||||
numberofseeders=10, use_isohunt=0, use_kat=0, use_mininova=0, waffles=0, waffles_uid=None, waffles_passkey=None, whatcd=0, whatcd_uid=None, whatcd_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, lossless_destination_dir=None,
|
||||
folder_format=None, file_format=None, include_extras=0, single=0, ep=0, compilation=0, soundtrack=0, live=0, remix=0, spokenword=0, audiobook=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, delete_lossless_files=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, nma_enabled=False, nma_apikey=None, nma_priority=0, nma_onsnatch=0, synoindex_enabled=False, mirror=None, customhost=None, customport=None,
|
||||
customsleep=None, hpuser=None, hppass=None, preferred_bitrate_high_buffer=None, preferred_bitrate_low_buffer=None, **kwargs):
|
||||
|
||||
headphones.HTTP_HOST = http_host
|
||||
headphones.HTTP_PORT = http_port
|
||||
|
||||
Executable
+1442
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user