Last active
August 7, 2016 16:00
-
-
Save criztovyl/f31c050956982934ff6e to your computer and use it in GitHub Desktop.
Sorts a Bandcamp discography by release date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Utility for Bandcamp discographies | |
# Copyright (C) 2016 Christoph "criztovyl" Schulz | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
if [[ "$1" =~ ^-{0,2}h(elp)?$ ]]; then | |
echo "Usage: $0 [USER] [ACTION]" >&2 | |
echo " USER: " >&2 | |
echo " bandcamp artist domain, i.e. \"shirobon\" for \"https://shirobon.bandcamp.com\"" >&2 | |
echo " ACTION: " >&2 | |
echo " releases: list releases (sorted)" >&2 | |
echo " covers: download all release covers to current folder (artist-album.jpg)" >&2 | |
echo " urls: display releases urls" >&2 | |
echo " if invalid falls back to releases" >&2 | |
echo | |
echo "Generates status output (on stderr), disable by setting BC_ODS to any value." >&2 | |
echo "Artist page has own domain? Look at OpenGraph url prop: I.e. for J-M-R try $ curl https://j-m-r.net | grep \"og:url\" " >&2 | |
exit 0 | |
fi | |
CURL="curl" | |
[ "$BC_ODS" ] && CURL=$CURL" -s" | |
[ -z "$1" ] && { echo "No user given!" >&2; exit 2; } | |
user=$1 | |
url="https://$user.bandcamp.com" | |
urls=`$CURL -L "$url""/music" | perl -ne '/<a href="(\/(track|album).*?)"/ && print "'$url'".$1."\n"'` | |
[ -z "$urls" ] && { echo "No releases found." >&2; exit 1; } | |
case $2 in | |
"urls") | |
echo $urls | |
;; | |
"covers") | |
re='\s*artFullsizeUrl: "(.*)"' | |
for url in $urls | |
do | |
echo $url | |
slug=${url##*/} | |
[[ `curl -L $url | grep artFullsizeUrl` =~ $re ]] && wget -O $user"-"$slug.${BASH_REMATCH[1]##*.} ${BASH_REMATCH[1]} | |
done | |
;; | |
*|"releases") | |
# all-in-one command to let curl reuse connection | |
$CURL $urls | | |
grep "released " | | |
perl -ne '/(.*), released (\d{2}) (\w{3})\w* (\d{4})/ && print $4." ".$3." ".$2.": ".$1."\n"' | | |
LANG=en sort -t" " -k1n,1 -k2M,2 -k3n,3 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment