forked from osleg/vksearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lfmsearch
executable file
·114 lines (101 loc) · 4.59 KB
/
lfmsearch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#################################################################
########### LastFM Saerch script (c) snoopcatt, 2010-2013 ############
########### Licensed under GNU GPL v2. ##########################
#################################################################
######################################################
sys_vksearch='vksearch'
sys_method='get-album'
sys_version='0.7b'
sys_temp='/tmp'
cfg_color_output=1
cfg_save_to='.'
######################################################
Info() {
[ "$cfg_color_output" -eq 1 ] && message_text="$(echo $1|sed 's/COLOR_WHITE/\\e[1;37m/g;s/COLOR_RED/\\e[1;31m/g;s/COLOR_PURPLE/\\e[1;35m/g;s/COLOR_GREEN/\\e[1;32m/g;s/COLOR_YELLOW/\\e[1;33m/g')" || message_text="$(echo $1|sed 's/COLOR_WHITE//g;s/COLOR_RED//g;s/COLOR_PURPLE//g;s/COLOR_GREEN//g;s/COLOR_YELLOW//g')"
[ "$cfg_color_output" -eq 1 ] && date_color="\e[1;36m" && color_reset="\e[00m"
echo -e "$date_color[$(date +%k:%M:%S)] ${color_reset}${message_text}${color_reset}"
[ "$2" == "die" ] && exit 1
}
ShowHelp() {
echo "LastFM Search $sys_version: Загрузка альбомов и дискографий."
echo "Для работы скрипта не требуется авторизация. by snoopcatt, © 2010-2013. Лицензировано под GNU GPL v2."
echo -e "* Использование: lfmsearch [опции] запрос"
echo -e "\t--help: показать это сообщение и закрыть lfmsearch\n"
echo -e "\t--get-album: скачиваем альбом"
echo -e "\t--get-discography: скачиваем дискографию"
echo -e "\t--save-to=PATH: сохранять треки в указанный PATH"
exit 0
}
GetParams() {
for var in $@
do
case $var in
--help) ShowHelp;;
--get-album) sys_method='get-album' ;;
--get-discography) sys_method='get-discography' ;;
--save-to=*) cfg_save_to=$(echo $var | cut -d '=' -f 2) ;;
--*) Info "Ошибка разбора аргументов: Неизвестный параметр $var" die ;;
*) [ -z "$query" ] && query="${var}" || query="${query} ${var}" ;;
esac
done
[ -z "$sys_method" ] && ShowHelp
[ -z "$query" ] && ShowHelp
}
GetAlbum() {
cd "$cfg_save_to"
rm ${sys_temp}/lastfm_tracks 2>/dev/null
artist="$(echo $query | cut -d '-' -f 1|sed 's/[ \t]$//')"
album="$(echo $query | cut -d '-' -f 2|sed 's/^[ \t]*//')"
Info "COLOR_WHITEСохранение: COLOR_PURPLE$artist - $album"
[ -d "$album" ] || mkdir "$album"
cd "$album"
[ -d lyrics ] || mkdir lyrics
wget "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=efe0e53182441c48f5b11f3565306e30&artist=$artist&album=$album" -qO ${sys_temp}/lastfm_request
album_art="$( grep -oE 'http://.*(png|jpg)' ${sys_temp}/lastfm_request|tail -n1 )";
year="$(grep release ${sys_temp}/lastfm_request|awk '{ print $4 }'|sed 's/,//')"
Info "COLOR_WHITEЗагрузка обложки альбома..."
[ -n "$album_art" ] && wget -qO cover.`basename $album_art|awk -F . '{print $NF}'` $album_art
grep -n '<duration>' ${sys_temp}/lastfm_request|while read line; do
ln="$(( ` echo $line | awk '{ print $1 }'|sed 's/://g' ` - 1 ))";
sed -n ${ln}p ${sys_temp}/lastfm_request|sed -n 's|<name>\(.*\)</name>|\1|p'|sed 's/^[ \t]*//' >> ${sys_temp}/lastfm_tracks
done
count=`cat ${sys_temp}/lastfm_tracks | wc -l`
current=1
OLD_IFS="$IFS"
IFS=$'\n'
Info "COLOR_WHITEЗагрузка песен начата."
for track in $(cat ${sys_temp}/lastfm_tracks) ; do
saved="$($sys_vksearch --silent --get-one $artist - $track)"
real="$artist - $track"
mv "$saved" "$real.mp3" 2>/dev/null
id3 -D "$real.mp3" >/dev/null 2>&1
id3 -2 -a "$artist" -A "$album" -t "$track" -y $year -T $current/$count "$real.mp3" >/dev/null 2>&1
saved_lyrics="$($sys_vksearch --silent --get-lyrics $artist - $track)"
mv "$saved_lyrics" "lyrics/$real.txt"
Info "COLOR_GREEN[$current/$count] COLOR_WHITEТрек COLOR_PURPLE${artist} - ${track}COLOR_WHITE загружен."
let current++;
done
IFS="$OLD_IFS"
}
GetDiscography() {
cd "$cfg_save_to"
rm ${sys_temp}/lastfm_albums 2>/dev/null
artist=$query
[ -d "$artist" ] || mkdir "$artist"
cd "$artist"
wget "http://ws.audioscrobbler.com/2.0/?method=artist.gettopalbums&artist=$query&api_key=efe0e53182441c48f5b11f3565306e30" -qO ${sys_temp}/lastfm_request
OLD_IFS="$IFS"
IFS=$'\n'
for album in $(cat ${sys_temp}/lastfm_request|grep name|grep -vEi ">$query<"|grep -oE '>.*<'|sed 's/<$//;s/^>//;') ; do
$0 --save-to=. --get-album "$artist" - "$album"
cd "$cfg_save_to"
done
}
GetParams $*;
case $sys_method in
get-album)
GetAlbum;;
get-discography)
GetDiscography;;
esac