Created
August 30, 2011 16:58
-
-
Save sebix/1181355 to your computer and use it in GitHub Desktop.
This small Shell-Script can download tracks, albums and many albums (just give the tag or a list) at once!
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 | |
# Version: 30.08.2011 19:00 | |
# Author: sebix (https://github.com/sebix) | |
USAGE="jamendo_dl.sh | |
Download free Music from Jamendo.com | |
Usage: jamendo_dl.sh [ -opts] | |
Options: | |
-h --help Display this help message. | |
-t --track ID Download the given Track | |
-a --album ID Download the given Album | |
--tag NAME Download all albums from the given track | |
-al --album-list FILE | |
Download all albums from the given File (ID must be given!) | |
-tl --track-list FILE | |
Download all tracks from the given File (ID must be given!) | |
-l --limit * Download a maximum of albums (with --tag or --*-list); | |
-f --format ogg|mp3 | |
Download mp3 or ogg files | |
Author: sebix (https://github.com/sebix) | |
Handling with Lists: | |
* jamendo_dl.sh will create a tempoary copy of the file and deletes the finished lines, so you can continue your downloads. | |
* After all downloads are finished, the copy will be removed. | |
* If you are using --tag, a file (named like the tag) will be created, conaining all IDs." | |
dl_track () { | |
ALBUM=`wget http://www.jamendo.com/get/album/id/track/title/plain/$1 -4 -O - 2>/dev/null` | |
INTERPRET=`wget http://www.jamendo.com/get/artist/id/track/title/plain/$1/ -4 -O - 2>/dev/null` | |
TITLE=`wget http://www.jamendo.com/get/track/id/track/title/plain/$1 -4 -O - 2>/dev/null` | |
if [ -z "$ALBUM" ]; then echo "Could not fetch album!"; exit; fi | |
if [ -z "$INTERPRET" ]; then echo "Could not fetch interpret!"; exit; fi | |
if [ -z "$TITLE" ]; then echo "Could not fetch title!"; exit; fi | |
DESTINATION="$INTERPRET/$ALBUM" | |
if [ ! -d "$DESTINATION" ]; then | |
mkdir -p "$DESTINATION" | |
fi | |
echo -e -n "Downloading track $1 ($DESTINATION/$TITLE.$FORMAT)...\r" | |
wget "http://www.jamendo.com/get/track/id/track/audio/plain/$1?aue=$FORMAT" -4 -O - 2>/dev/null | xargs wget -4 -c -O "$DESTINATION/$TITLE.$FORMAT" 2>/dev/null | |
if [ $? ]; then | |
echo "Track $1 ($DESTINATION/$TITLE.$FORMAT) successfully downloaded" | |
else | |
echo "Error while downloading track $1 ($DESTINATION/$TITLE.$FORMAT)!" | |
fi | |
} | |
dl_album () { | |
INFOS=`wget http://www.jamendo.com/get/track/id/album/id/plain/$1 -4 -O - 2>/dev/null` | |
if [ -z "$INFOS" ]; then | |
echo "Error while downloading album informations ($1)!" | |
exit | |
fi | |
for i in $INFOS; do | |
dl_track $i | |
done | |
echo -e "\tAlbum $1 downloaded" | |
} | |
dl_album_list () { | |
if [ ! -f $1.tmp ]; then | |
cp $1 $1.tmp | |
fi | |
for i in `cat $1.tmp`; do | |
if [ $LIMIT ]; then | |
dl_album $i | |
fi | |
((LIMIT=$LIMIT-1)) | |
sed -i '1d' $1.tmp | |
done | |
rm $1.tmp | |
} | |
dl_track_list () { | |
if [ ! -f $1.tmp ]; then | |
cp $1 $1.tmp | |
fi | |
for i in `cat $1.tmp`; do | |
if [ $LIMIT ]; then | |
dl_track $i | |
fi | |
((LIMIT=$LIMIT-1)) | |
sed -i '1d' $1.tmp | |
done | |
rm $1.tmp | |
} | |
dl_tag () { | |
if [ ! -f $1 ]; then | |
LIST=`wget http://www.jamendo.com/get/album/name/tag/page/plain/${1}?n=all -4 -O - | awk -F/ '{print $5}' | tee $1` | |
fi | |
dl_album_list $1 | |
} | |
while [[ "$1" == -* ]]; do | |
[[ "$1" == "-t" || "$1" == "--track" ]] && DL="dl_track" && ID=$2 | |
[[ "$1" == "-a" || "$1" == "--album" ]] && DL="dl_album" && ID=$2 | |
[[ "$1" == "-f" || "$1" == "--format" ]] && FORMAT=$2 && ID=$2 | |
[[ "$1" == "-l" || "$1" == "--limit" ]] && LIMIT=$2 | |
[[ "$1" == "--tag" ]] && DL="dl_tag" && ID=$2 | |
[[ "$1" == "-al" || "$1" == "--album-list" ]] && DL="dl_album_list" && ID=$2 | |
[[ "$1" == "-tl" || "$1" == "--track-list" ]] && DL="dl_track_list" && ID=$2 | |
[[ "$1" == "-h" || "$1" == "--help" ]] && echo "$USAGE" && exit | |
shift 2 | |
done | |
FORMAT=${FORMAT:-'ogg2'} | |
[[ $FORMAT == 'ogg' ]] && FORMAT='ogg2' | |
[[ $FORMAT == 'mp3' ]] && FORMAT='mp31' | |
$DL $ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment