Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bandcamp support #3252

Merged
merged 15 commits into from
Nov 26, 2023
Prev Previous commit
Next Next commit
Add bandcamp search support
  • Loading branch information
b10m committed Jun 6, 2020
commit 2698e32065656b25360b071c440e9861f6535093
19 changes: 16 additions & 3 deletions headphones/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import headphones
from headphones.common import USER_AGENT
from headphones import logger, db, helpers, classes, sab, nzbget, request
from headphones import utorrent, transmission, notifiers, rutracker, deluge, qbittorrent
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.
Expand Down Expand Up @@ -285,15 +285,17 @@ def do_sorted_search(album, new, losslessOnly, choose_specific_download=False):
[album['AlbumID']])[0][0]

if headphones.CONFIG.PREFER_TORRENTS == 0 and not choose_specific_download:

results = searchBandcamp(album, new, albumlength)
if NZB_PROVIDERS and NZB_DOWNLOADERS:
results = searchNZB(album, new, losslessOnly, albumlength)

if not results and TORRENT_PROVIDERS:
results = searchTorrent(album, new, losslessOnly, albumlength)

elif headphones.CONFIG.PREFER_TORRENTS == 1 and not choose_specific_download:
if not results:
results = searchBandcamp(album, new, albumlength)

elif headphones.CONFIG.PREFER_TORRENTS == 1 and not choose_specific_download:
if TORRENT_PROVIDERS:
results = searchTorrent(album, new, losslessOnly, albumlength)

Expand Down Expand Up @@ -505,6 +507,9 @@ def get_year_from_release_date(release_date):
return year


def searchBandcamp(album, new=False, albumlength=None):
return bandcamp.search(album)

def searchNZB(album, new=False, losslessOnly=False, albumlength=None,
choose_specific_download=False):
reldate = album['ReleaseDate']
Expand Down Expand Up @@ -829,6 +834,11 @@ def send_to_downloader(data, bestqual, album):
except Exception as e:
logger.error('Couldn\'t write NZB file: %s', e)
return

elif kind == 'bandcamp':
folder_name = bandcamp.download(album, bestqual)
logger.info("Setting folder_name to: {}".format(folder_name))

else:
folder_name = '%s - %s [%s]' % (
helpers.latinToAscii(album['ArtistName']).encode('UTF-8').replace('/', '_'),
Expand Down Expand Up @@ -1856,6 +1866,9 @@ def set_proxy(proxy_url):

def preprocess(resultlist):
for result in resultlist:
if result[4] == 'bandcamp':
return True, result

if result[4] == 'torrent':

headers = {}
Expand Down