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 1 commit
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
3 changes: 3 additions & 0 deletions bandcamp_dl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def main():
urls = Bandcamp.generate_album_url(arguments['--artist'], arguments['--track'], "track")
elif arguments['--artist']:
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
8 changes: 7 additions & 1 deletion bandcamp_dl/bandcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,16 @@ def get_album_art(self) -> str:
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])]
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