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 2 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
9 changes: 5 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,10 @@ 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")
print(f"{len(urls)} albums/tracks have been found:")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than this print I don't really have an issue with the PR. I just don't see a reason to clutter the terminal with anything more than the existing progress bar especially considering its not really a value add to print the urls.

If you want to dump them in debug that is fine though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I decided to remove it. It's already committed.

for url in urls:
print(url)
else:
urls = arguments['URL']

Expand Down
15 changes: 15 additions & 0 deletions bandcamp_dl/bandcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,18 @@ 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 shoul 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

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