bandcamp tweaks

This commit is contained in:
AdeHub
2024-01-26 21:11:29 +13:00
parent 152f5daa8c
commit 6afe31bffc
3 changed files with 24 additions and 20 deletions

View File

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

View File

@@ -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', '')
}

View File

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