Skip to content

Instantly share code, notes, and snippets.

@azimut
Last active October 19, 2021 18:13
Show Gist options
  • Save azimut/115de58a90ce375a8dc951f2de675fb2 to your computer and use it in GitHub Desktop.
Save azimut/115de58a90ce375a8dc951f2de675fb2 to your computer and use it in GitHub Desktop.
List bandcamp album links
#!/bin/bash
set -x
set -e
LIST_ALBUMS=~/projects/115de58a90ce375a8dc951f2de675fb2/listalbums.py
export ALBUM_LINK="$1"
export FOLDER="$2"
for album_link in $( python2 $LIST_ALBUMS "$ALBUM_LINK"); do
mkdir -p ~/music/$FOLDER
cd ~/music/$FOLDER
album="${album_link##*/}"
artist="${album_link##*://}"
artist="${artist%%/*}"
artist="${artist%%.*}"
bandcamp-dl --album="$album" --artist="$artist"
done
#!/usr/bin/env python3
# References:
# https://docs.python.org/2/howto/argparse.html
# https://validators.readthedocs.io/en/latest/
import argparse
import validators
import sys
from bs4 import BeautifulSoup
from urllib.request import urlopen
from urllib.parse import urlparse
import re
parser = argparse.ArgumentParser()
parser.add_argument("BANDCAMP_URL")
args = parser.parse_args()
def parse_artist(soup):
midcolumn = soup.find('div',{"class":"leftMiddleColumns"})
if midcolumn.find('ol'):
for album_list in midcolumn.findAll('ol'):
for album in album_list.findAll('li'):
album_link = album.a['href']
if re.match('^http[s]?.*',album_link):
print('https://' + urlparse(album_link).hostname + urlparse(album_link).path)
else:
print('https://' + urlparse(args.BANDCAMP_URL).hostname + album_link)
elif midcolumn.find('span','indexpage_list'):
for album_link in midcolumn.find('span','indexpage_list').findAll('span',{'class':'indexpage_list_row'}):
for album in album_link.findAll('span'):
album_link = album.find('a')['href']
if re.match('^http[s]?.*',album_link):
print('https://' + urlparse(album_link).hostname + urlparse(album_link).path)
#print album_link
else:
print('https://' + urlparse(args.BANDCAMP_URL).hostname + album_link)
def parse_user(soup):
for album in soup.find('div',id='collection-items').findAll('li',id=re.compile('collection-item-container_[0-9]*')):
# lazy...
try:
album_link = album.find('a',{"class":"item-link"})['href']
print(album_link)
except:
continue
if validators.url( args.BANDCAMP_URL ):
page = urlopen(args.BANDCAMP_URL)
soup = BeautifulSoup(page.read(), "xml")
if re.match('.*/music$', args.BANDCAMP_URL):
#print "Parsing artist"
parse_artist(soup)
elif re.match('.*/bandcamp.com/[A-Za-z0-9_-]+$', args.BANDCAMP_URL):
parse_user(soup)
elif re.match('.*/tag/.*', args.BANDCAMP_URL):
parse_search(soup)
else:
sys.exit(1)
else:
sys.exit(1)
#!/bin/bash
set -x
set -e
LIST_ALBUMS=~/projects/115de58a90ce375a8dc951f2de675fb2/listalbums.py
export ALBUM_LINK="$1"
export FOLDER="$2"
for album_link in $( python2 $LIST_ALBUMS "$ALBUM_LINK"); do
album="${album_link##*/}"
artist="${album_link##*://}"
artist="${artist%%/*}"
artist="${artist%%.*}"
mkdir -p ~/music/$FOLDER/"${artist}"/"${album}"
cd ~/music/$FOLDER/"${artist}"/"${album}"
youtube-dl -c "${album_link}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment