diff --git a/headphones/bandcamp.py b/headphones/bandcamp.py index f399c5d4..cf1af68e 100644 --- a/headphones/bandcamp.py +++ b/headphones/bandcamp.py @@ -20,9 +20,11 @@ import re from headphones import logger, helpers, metadata, request from headphones.common import USER_AGENT +from headphones.types import Result from beets.mediafile import MediaFile, UnreadableFileError from bs4 import BeautifulSoup +from bs4 import FeatureNotFound def search(album, albumlength=None, page=1, resultlist=None): @@ -50,7 +52,10 @@ def search(album, albumlength=None, page=1, resultlist=None): params=params, headers=headers ).decode('utf8') - soup = BeautifulSoup(content, "html5lib") + try: + soup = BeautifulSoup(content, "html5lib") + except FeatureNotFound: + soup = BeautifulSoup(content, "html.parser") for item in soup.find_all("li", class_="searchresult"): type = item.find('div', class_='itemtype').text.strip().lower() @@ -66,7 +71,7 @@ def search(album, albumlength=None, page=1, resultlist=None): cleanalbum, cleanalbum_found)) if (cleanartist.lower() == cleanartist_found.lower() and cleanalbum.lower() == cleanalbum_found.lower()): - resultlist.append(( + resultlist.append(Result( data['title'], data['size'], data['url'], 'bandcamp', 'bandcamp', True)) else: @@ -82,7 +87,7 @@ def search(album, albumlength=None, page=1, resultlist=None): def download(album, bestqual): - html = request.request_content(url=bestqual[2]).decode('utf-8') + html = request.request_content(url=bestqual.url).decode('utf-8') trackinfo = [] try: trackinfo = json.loads( diff --git a/headphones/config.py b/headphones/config.py index 717434ee..6b8dabac 100644 --- a/headphones/config.py +++ b/headphones/config.py @@ -318,7 +318,7 @@ _CONFIG_DEFINITIONS = { 'XBMC_UPDATE': (int, 'XBMC', 0), 'XBMC_USERNAME': (str, 'XBMC', ''), 'XLDPROFILE': (str, 'General', ''), - 'BANDCAMP': (int, 'General', 1), + 'BANDCAMP': (int, 'General', 0), 'BANDCAMP_DIR': (path, 'General', '') } diff --git a/headphones/searcher.py b/headphones/searcher.py index 93ec607a..303f1cd1 100644 --- a/headphones/searcher.py +++ b/headphones/searcher.py @@ -40,7 +40,6 @@ from headphones.common import USER_AGENT from headphones.types import Result from headphones import logger, db, helpers, classes, sab, nzbget, request from headphones import utorrent, transmission, notifiers, rutracker, deluge, qbittorrent, bandcamp -from bencode import bencode, bdecode # Magnet to torrent services, for Black hole. Stolen from CouchPotato. TORRENT_TO_MAGNET_SERVICES = [ @@ -852,7 +851,7 @@ def send_to_downloader(data, result, album): return elif kind == 'bandcamp': - folder_name = bandcamp.download(album, bestqual) + folder_name = bandcamp.download(album, result) logger.info("Setting folder_name to: {}".format(folder_name)) else: @@ -1924,20 +1923,8 @@ def searchTorrent(album, new=False, losslessOnly=False, albumlength=None, def preprocess(resultlist): for result in resultlist: - if result[4] == 'bandcamp': - return True, result - if result[4] == 'torrent': - - if result.provider in ["The Pirate Bay", "Old Pirate Bay"]: - 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' - } - else: - headers = {'User-Agent': USER_AGENT} + headers = {'User-Agent': USER_AGENT} if result.kind == 'torrent': @@ -1984,12 +1971,24 @@ def preprocess(resultlist): return True, result # Download the torrent file + + if result.provider in ["The Pirate Bay", "Old Pirate Bay"]: + 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.url, headers=headers), result - if result.kind == 'magnet': + elif result.kind == 'magnet': magnet_link = result.url return "d10:magnet-uri%d:%se" % (len(magnet_link), magnet_link), result + elif result.kind == 'bandcamp': + return True, result + else: if result.provider == 'headphones': return request.request_content(