Требования к пакетам:
sed
awk
grep
wget
cat
echo
Сам скрипт:
Код: Выделить всё
#!/bin/bash
# This one downloading tracks from namba's playlists
# Need some customisation. And it fears whitespaces
#
# Author: Gen1us2k
# Thanks:
# - Romanius for support
# - Google for some useful methods
#
tmpfile=$(mktemp /tmp/namba_XXXXXX)
songlist=$(mktemp /tmp/songs_XXXXXX)
trackFile=$(mktemp /tmp/tracks_XXXXXX)
use_err(){
echo "Usage: `basename $0` [-d outputDir] playlist_id"
echo "Example: `basename $0` -d ~/Music/ 16278"
echo " Saves playlist with id 16278 to ~/Music folder"
echo
exit 65
}
getPlaylist() {
echo Getting Playlist Data ...
wget -O $tmpfile $link &> /dev/null
}
ParseJson() {
count=$(cat $tmpfile | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | grep '"file_name":' | sed 's/:/ /1' | awk -F \" '{ print $4 }'|sed -e 's/\#039\;/'\''/g'|wc -l)
cat $tmpfile | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | grep '"file_name":' | sed 's/:/ /1' | awk -F \" '{ print $4 }'|sed -e 's/\#039\;//g' |sed -e 's/amp;/\&/g'> $songlist
timestamp=$(cat $tmpfile | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | grep '"timestamp":' | sed 's/:/ /1'|awk -F \" '{ print $6}')
cat $tmpfile | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | grep '"url":' | sed 's/:/ /1'|awk -F \" {'print $4'}|awk -F \\\/ {'print $5'}|awk -F \\ '{print $1}' > $trackFile
}
downloader(){
for ((z=1; z<=$count; z++))
do
songName="`sed -n ${z}p $songlist`"
trackId=`sed -n ${z}p $trackFile`
url="http://download.files.namba.kg/files/`echo -n "uno/$trackId/audio.mp3$timestamp"|md5sum -|awk -F" " '{print $1}'`/$timestamp/$trackId/audio.mp3"
echo Saving $songName ...
wget -c -O "$fn/$songName" $url &> /dev/null
done
}
if [ $# -lt 2 ]; then use_err; fi
while getopts ":d:" Option
do
case $Option in
d) fn=$OPTARG;;
*) use_err;;
esac
done
shift $(($OPTIND - 1))
if [ -z $1 ]; then use_err; fi
if [ -z "$fn" ]; then fn="$1"; fi
link="http://music.namba.kg/service.php?_dc=0&action=getPlaylist&id=$1"
getPlaylist
ParseJson
downloader
rm $tmpfile $songlist $trackFile
https://github.com/gen1us2k/bash-scripts/commits/
Использовать так: ./downloader -d /dest/dir playlist_id
playlist_id - последние циферки в урле
ЗЫ баги, найденные вами, оставляйте в теме
минус: пока что не работает с русскими треками :(