Skip to content

Commit 6afe31b

Browse files
committed
bandcamp tweaks
1 parent 152f5da commit 6afe31b

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

headphones/bandcamp.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020

2121
from headphones import logger, helpers, metadata, request
2222
from headphones.common import USER_AGENT
23+
from headphones.types import Result
2324

2425
from beets.mediafile import MediaFile, UnreadableFileError
2526
from bs4 import BeautifulSoup
27+
from bs4 import FeatureNotFound
2628

2729

2830
def search(album, albumlength=None, page=1, resultlist=None):
@@ -50,7 +52,10 @@ def search(album, albumlength=None, page=1, resultlist=None):
5052
params=params,
5153
headers=headers
5254
).decode('utf8')
53-
soup = BeautifulSoup(content, "html5lib")
55+
try:
56+
soup = BeautifulSoup(content, "html5lib")
57+
except FeatureNotFound:
58+
soup = BeautifulSoup(content, "html.parser")
5459

5560
for item in soup.find_all("li", class_="searchresult"):
5661
type = item.find('div', class_='itemtype').text.strip().lower()
@@ -66,7 +71,7 @@ def search(album, albumlength=None, page=1, resultlist=None):
6671
cleanalbum, cleanalbum_found))
6772
if (cleanartist.lower() == cleanartist_found.lower() and
6873
cleanalbum.lower() == cleanalbum_found.lower()):
69-
resultlist.append((
74+
resultlist.append(Result(
7075
data['title'], data['size'], data['url'],
7176
'bandcamp', 'bandcamp', True))
7277
else:
@@ -82,7 +87,7 @@ def search(album, albumlength=None, page=1, resultlist=None):
8287

8388

8489
def download(album, bestqual):
85-
html = request.request_content(url=bestqual[2]).decode('utf-8')
90+
html = request.request_content(url=bestqual.url).decode('utf-8')
8691
trackinfo = []
8792
try:
8893
trackinfo = json.loads(

headphones/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def __repr__(self):
318318
'XBMC_UPDATE': (int, 'XBMC', 0),
319319
'XBMC_USERNAME': (str, 'XBMC', ''),
320320
'XLDPROFILE': (str, 'General', ''),
321-
'BANDCAMP': (int, 'General', 1),
321+
'BANDCAMP': (int, 'General', 0),
322322
'BANDCAMP_DIR': (path, 'General', '')
323323
}
324324

headphones/searcher.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from headphones.types import Result
4141
from headphones import logger, db, helpers, classes, sab, nzbget, request
4242
from headphones import utorrent, transmission, notifiers, rutracker, deluge, qbittorrent, bandcamp
43-
from bencode import bencode, bdecode
4443

4544
# Magnet to torrent services, for Black hole. Stolen from CouchPotato.
4645
TORRENT_TO_MAGNET_SERVICES = [
@@ -852,7 +851,7 @@ def send_to_downloader(data, result, album):
852851
return
853852

854853
elif kind == 'bandcamp':
855-
folder_name = bandcamp.download(album, bestqual)
854+
folder_name = bandcamp.download(album, result)
856855
logger.info("Setting folder_name to: {}".format(folder_name))
857856

858857
else:
@@ -1924,20 +1923,8 @@ def set_proxy(proxy_url):
19241923

19251924
def preprocess(resultlist):
19261925
for result in resultlist:
1927-
if result[4] == 'bandcamp':
1928-
return True, result
1929-
1930-
if result[4] == 'torrent':
19311926

1932-
if result.provider in ["The Pirate Bay", "Old Pirate Bay"]:
1933-
headers = {
1934-
'User-Agent':
1935-
'Mozilla/5.0 (Windows NT 6.3; Win64; x64) \
1936-
AppleWebKit/537.36 (KHTML, like Gecko) \
1937-
Chrome/41.0.2243.2 Safari/537.36'
1938-
}
1939-
else:
1940-
headers = {'User-Agent': USER_AGENT}
1927+
headers = {'User-Agent': USER_AGENT}
19411928

19421929
if result.kind == 'torrent':
19431930

@@ -1984,12 +1971,24 @@ def preprocess(resultlist):
19841971
return True, result
19851972

19861973
# Download the torrent file
1974+
1975+
if result.provider in ["The Pirate Bay", "Old Pirate Bay"]:
1976+
headers = {
1977+
'User-Agent':
1978+
'Mozilla/5.0 (Windows NT 6.3; Win64; x64) \
1979+
AppleWebKit/537.36 (KHTML, like Gecko) \
1980+
Chrome/41.0.2243.2 Safari/537.36'
1981+
}
1982+
19871983
return request.request_content(url=result.url, headers=headers), result
19881984

1989-
if result.kind == 'magnet':
1985+
elif result.kind == 'magnet':
19901986
magnet_link = result.url
19911987
return "d10:magnet-uri%d:%se" % (len(magnet_link), magnet_link), result
19921988

1989+
elif result.kind == 'bandcamp':
1990+
return True, result
1991+
19931992
else:
19941993
if result.provider == 'headphones':
19951994
return request.request_content(

0 commit comments

Comments
 (0)