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

Added full discography download #211

Merged
merged 4 commits into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bandcamp_dl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
-h --help Show this screen.
-v --version Show version.
-d --debug Verbose logging.
--artist=<artist> The artist's slug (from the URL, --track or --album is required)
--artist=<artist> The artist's slug (from the URL)
--track=<track> The track's slug (from the URL, for use with --artist)
--album=<album> The album's slug (from the URL, for use with --artist)
--template=<template> Output filename template.
Expand Down Expand Up @@ -83,9 +83,7 @@ def main():
elif arguments['--artist'] and arguments['--track']:
urls = Bandcamp.generate_album_url(arguments['--artist'], arguments['--track'], "track")
elif arguments['--artist']:
print(__doc__)
os.remove(f"{config['--base-dir']}/{__version__}.not.finished")
exit()
urls = Bandcamp.get_full_discography(arguments['--artist'], "music")
else:
urls = arguments['URL']

Expand Down
18 changes: 18 additions & 0 deletions bandcamp_dl/bandcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,21 @@ def get_album_art(self) -> str:
return url
except None:
pass

def get_full_discography(artist: str, page_type: str) -> list:
"""Generate a list of album and track urls based on the artist name

:param artist: artist name
:param page_type: Type of page, it should be music but it's a parameter so it's not hardcoded
:return: urls as list of strs
"""
html = requests.get(f"https://{artist}.bandcamp.com/{page_type}").text

try:
soup = BeautifulSoup(html, "lxml")
except FeatureNotFound:
soup = BeautifulSoup(html, "html.parser")

urls = [f"https://{artist}.bandcamp.com{a['href']}" for a in soup.find_all("a", href=True) if ("/" == a["href"].split("album")[0] or "/" == a["href"].split("track")[0])]

return urls