Skip to content

Instantly share code, notes, and snippets.

@lamanotrama
Created February 17, 2014 13:31
Show Gist options
  • Save lamanotrama/9050505 to your computer and use it in GitHub Desktop.
Save lamanotrama/9050505 to your computer and use it in GitHub Desktop.
#!/bin/bash
# kuroda
list=$1
para=5
export dl_path=~/music
mkdir -p "$dl_path"
log="/tmp/music_dl.log"
error_log="/tmp/music_dl_error.log"
download() {
url=$( echo "$1" | perl -MURI::Escape -lne 'print uri_unescape($_)' )
info=${url##*/}
set $( echo $info | perl -nle 'print join " ", (split "_?-_", $_, 3)' )
artist=$1
release=$2
track=$3
release_path="$dl_path/$artist/$release"
track_path="$release_path/$track"
tmp="/tmp/${track}.part"
test -f "$release_path/.skip" && return
if [ ! -f "$track_path" ]; then
echo -e "START:\t$url"
mkdir -p $( dirname "$track_path" )
wget -q -t 3 -O "$tmp" "$url"
if [ "x$?" = "x0" ]; then
mv "$tmp" "$track_path"
echo -e "OK:\t$track_path"
else
echo -e "NG:\t$track_path" 1>&2
fi
else
#echo -e "SKIP:\t$track_path"
:
fi
}
export -f download
tr -d "\r" < $list > /tmp/download_list.txt
(
cat /tmp/download_list.txt |
perl -MURI::Escape -lne 'print uri_escape($_)' |
xargs -P $para -n 1 -I % bash -c 'download %'
) 2> "$error_log" | tee "$log"
cat $error_log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment