-
Notifications
You must be signed in to change notification settings - Fork 6
/
modarchive.sh
executable file
·304 lines (264 loc) · 8.27 KB
/
modarchive.sh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/bash
###############################################################################
# MODARCHIVE JUKEBOX SCRIPT
#
# Made by: Fernando Sancho AKA 'toptnc'
# email: [email protected]
#
# This script plays mods from http://modarchive.org in random order
# It can fetch files from various categories
#
# This script is released under the terms of GNU GPL License
#
###############################################################################
MODPATH='/tmp/modarchive'
SHUFFLE=
PLAYLISTFILE='modarchive.url'
RANDOMSONG=
PAGES=
MODLIST=
PL_AGE="3600"
PLAYER='/usr/bin/mikmod'
PLAYEROPTS='-i -X --surround --hqmixer -f 48000 -X'
PLAYERBG='false'
TRACKSNUM=0
#Configuration file overrides defaults
if [ -f $HOME/.modarchiverc ];
then
source $HOME/.modarchiverc
fi
usage()
{
cat << EOF
usage: $0 [options]
Modarchive Jukebox can be used with one of the following options:
-h : Show this help message
-n <number> Number of tracks to play
-r Shuffle playlist
-p <player> Select player profile: Supported players are:
mikmod This is the default player. Runs in console and uses
libmikmod to decode files
audacious This is an X11 player. Uses modplug tu decode files
opencp This is Open Cubic Player, a console/x11 classic player.
It's really buggy but, who cares?
-s <section> Play from selected section: Can be one of this
featured These modules have been nominated by the crew for either
outstanding quality, technique or creativity
(or combination of).
favourites These modules have been nominated by the members via their
favourites.
downloads The top 1000 most downloaded modules, recorded since circa
2002.
topscore This chart lists the most revered modules on the archive.
newadd New additions by Date
newratings Recent rated modules
random Ramdom module from entire archive
-a <artist> Search in artist database
-m <module> Search in module database (Title and Filename)
Hint: Use + symbol instead blankspaces in search strings.
EOF
}
create_playlist()
{
PLAYLIST=""
if [ ! -e "$MODPATH/$MODLIST" ] || [ "$(( $(date +"%s") - $(stat -c "%Y" "${MODPATH}/${MODLIST}") ))" -gt $PL_AGE ];
then
if [ ! -z $PAGES ];
then
PLAYLIST=$(curl -s "${MODURL}" | grep href | sed 's/href=/\n/g' | sed 's/>/\n/g' | grep downloads.php | sed 's/\"//g' | sed 's/'\''//g'|cut -d " " -f 1| uniq)
else
PAGES=$(curl -s $MODURL | html2text | grep "Jump" | sed 's/\//\n/g' | tail -1 | cut -d "]" -f1)
[ -z $PAGES ] && PAGES=1
echo "Need to download ${PAGES} pages of results. This may take a while..."
for (( PLPAGE = 1; PLPAGE <= PAGES; PLPAGE ++ ))
do
(( PERCENT = PLPAGE * 100 / PAGES ))
echo -ne "${PERCENT}% completed\r"
PLPAGEARG="&page=$PLPAGE";
LIST=$(curl -s "${MODURL}${PLPAGEARG}"| grep href | sed 's/href=/\n/g' | sed 's/>/\n/g' | grep downloads.php | sed 's/\"//g' | sed 's/'\''//g'|cut -d " " -f 1| uniq )
PLAYLIST=$(printf "${PLAYLIST}\n${LIST}")
done
fi
echo ""
echo "$PLAYLIST" | sed '/^$/d' > "$MODPATH/$MODLIST"
fi
if [ -z $SHUFFLE ];
then
cat "$MODPATH/$MODLIST" > "$MODPATH/$PLAYLISTFILE"
else
cat "$MODPATH/$MODLIST" | awk 'BEGIN { srand() } { print rand() "\t" $0 }' | sort -n | cut -f2- > "$MODPATH/$PLAYLISTFILE"
fi
}
while getopts "hrm:a:s:n:p:" OPTION
do
case $OPTION in
h)
usage
exit 0;
;;
s)
case $OPTARG in
featured)
MODURL="http://modarchive.org/index.php?request=view_chart&query=featured"
MODLIST="list.featured"
#PAGES=$(curl -s $MODURL | html2text | grep "Jump" | sed 's/\//\n/g' | tail -1 | cut -d "]" -f1)
;;
favourites)
MODURL="http://modarchive.org/index.php?request=view_top_favourites"
MODLIST="list.favourites"
#PAGES=$(curl -s $MODURL | html2text | grep "Jump" | sed 's/\//\n/g' | tail -1 | cut -d "]" -f1)
;;
downloads)
MODURL="http://modarchive.org/index.php?request=view_chart&query=tophits"
MODLIST="list.downloads"
#PAGES=$(curl -s $MODURL | html2text | grep "Jump" | sed 's/\//\n/g' | tail -1 | cut -d "]" -f1)
;;
topscore)
MODURL="http://modarchive.org/index.php?request=view_chart&query=topscore"
MODLIST="list.topscore"
#PAGES=$(curl -s $MODURL | html2text | grep "Jump" | sed 's/\//\n/g' | tail -1 | cut -d "]" -f1)
;;
newadd)
MODURL="http://modarchive.org/index.php?request=view_actions_uploads"
MODLIST="list.newadd"
PAGES='0'
;;
newratings)
MODURL="http://modarchive.org/index.php?request=view_actions_ratings"
MODLIST="list.newratings"
PAGES='0'
;;
random)
RANDOMSONG="true"
MODURL="http://modarchive.org/index.php?request=view_random"
PAGES='0'
;;
?)
usage
exit 1
;;
esac
;;
a)
QUERY=$(echo ${OPTARG} | sed 's/\ /\+/g')
QUERYURL="http://modarchive.org/index.php?query=$QUERY&submit=Find&request=search&search_type=search_artist"
ARTISTNO=$(curl -s $QUERYURL | grep -A 10 "Search Results" | grep member.php | sed 's/>/>\n/g' | head -1 | cut -d "?" -f 2 | cut -d "\"" -f 1)
if [ -z $ARTISTNO ];
then
echo "The query returned no results"
exit 1
fi
MODURL="http://modarchive.org/index.php?request=view_artist_modules&query=${ARTISTNO}"
MODLIST="artist.${OPTARG}"
#PAGES=$(curl -s $MODURL | html2text | grep "Jump" | sed 's/\//\n/g' | tail -1 | cut -d "]" -f1)
;;
m)
MODURL="http://modarchive.org/index.php?request=search&query=${OPTARG}&submit=Find&search_type=filename_or_songtitle"
MODLIST="search.${OPTARG}"
#PAGES=$(curl -s $MODURL | html2text | grep "Jump" | sed 's/\//\n/g' | tail -1 | cut -d "]" -f1)
;;
r)
SHUFFLE="true"
;;
n)
expr $OPTARG + 1 > /dev/null
if [ $? = 0 ];
then
TRACKSNUM=${OPTARG};
else
echo "ERROR -n requires a number as argument"
usage
exit 1
fi
;;
p)
case $OPTARG in
audacious)
PLAYER='/usr/bin/audacious'
PLAYEROPTS='-e'
PLAYERBG='true'
;;
mikmod)
PLAYER='/usr/bin/mikmod'
PLAYEROPTS='-i -X --surround --hqmixer -f 48000 -X'
PLAYERBG='false'
;;
opencp)
PLAYER='/usr/bin/ocp'
PLAYEROPTS='-p'
PLAYERBG='false'
;;
?)
echo "ERROR: ${OPTARG} player is not supported."
echo ""
usage
exit 1
;;
esac
;;
?)
usage
exit 1
;;
esac
done
if [ ! -e $PLAYER ];
then
echo "This scripts needs $PLAYER to run. Please install it or change the script"
usage
exit 1
fi
if [ ${PLAYERBG} = "true" ] && [ -z $(pidof $PLAYER) ];
then
echo "$PLAYER isn't running. Please, launch it first"
usage
exit 1
fi
if [ -z $MODURL ];
then
usage
exit 1
fi
echo "Starting Modarchive JukeBox Player"
mkdir -p $MODPATH
LOOP="true"
if [ -z $RANDOMSONG ];
then
echo "Creating playlist"
create_playlist
TRACKSFOUND=$(wc -l "$MODPATH/$PLAYLISTFILE" | cut -d " " -f 1)
echo "Your query returned ${TRACKSFOUND} results"
fi
COUNTER=1
while [ $LOOP = "true" ]; do
if [ -z $RANDOMSONG ];
then
SONGURL=$(cat "$MODPATH/$PLAYLISTFILE" | head -n ${COUNTER} | tail -n 1)
let COUNTER=$COUNTER+1
if [ $TRACKSNUM -gt 0 ];
then
if [ $COUNTER -gt $TRACKSNUM ] || [ $COUNTER -gt $TRACKSFOUND ];
then
LOOP="false"
fi
elif [ $COUNTER -gt $TRACKSFOUND ];
then
LOOP="false"
fi
else
SONGURL=$(curl -s "$MODURL" | sed 's/href=\"/href=\"\n/g' | sed 's/\">/\n\">/g' | grep downloads.php | head -n 1);
let COUNTER=$COUNTER+1
if [ $TRACKSNUM -gt 0 ] && [ $COUNTER -gt $TRACKSNUM ];
then
LOOP="false"
fi
fi
MODFILE=$(echo "$SONGURL" | cut -d "#" -f 2)
if [ ! -e "${MODPATH}/${MODFILE}" ]; then
echo "Downloading $SONGURL to $MODPATH/$MODFILE";
curl -s -o "${MODPATH}/${MODFILE}" "$SONGURL";
fi
if [ -e "${MODPATH}/${MODFILE}" ];then
$PLAYER $PLAYEROPTS "${MODPATH}/${MODFILE}";
fi
done