-
Notifications
You must be signed in to change notification settings - Fork 2
/
m3u.sh
executable file
·42 lines (27 loc) · 1.64 KB
/
m3u.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
#!/bin/bash
# take the list to scrape from, don't include the extension like .txt
#echo "insert the name of text file including different archive.org pages to scrape from"
#read list
# remove extra part of the links to make naming the output files easier
#sed -e 's!https://archive.org/details/!!' $list.txt > temp_a.txt
sed -e 's!https://archive.org/details/!!' $1 > temp_a.txt
# fix filename errors that some times occur on windows
sed -i 's/\r$//' temp_a.txt
echo "start scraping the links for mp3 files - 128kb"
# for links containing the 128kb.mp3 string
for i in $(cat temp_a.txt) ; do lynx --dump --listonly --nonumbers "https://archive.org/download/$i" | grep -iF "128kb.mp3" | grep -iFv "64kb" | grep -iFv ".zip" | sed 's/ /%20/g' > $i.txt ; done
# find empty files if there is any and copy their names for the next command
find *.txt -size 0 | sed 's/.txt//g' > temp_b.txt
echo "start scraping the links for mp3 files - generic mp3"
# for other links if there is any
for i in $(cat temp_b.txt) ; do lynx --dump --listonly --nonumbers "https://archive.org/download/$i" | grep -iF ".mp3" | grep -iFv "64kb" | grep -iFv ".zip" > $i.txt ; done
echo "create m3u playlists out of text files"
# add #EXTINF:-1 at the begining of every other line and #EXTM3U at the first line and convert the text file to m3u stream
for i in $(cat temp_a.txt) ; do sed "s/^/#EXTINF:-1\n/" $i.txt | sed '1s/^/#EXTM3U\n/' > $i.m3u ; done
echo "remove empty and temp files"
# remove temp files
for i in $(cat temp_a.txt) ; do rm $i.txt ; done
rm temp_a.txt temp_b.txt
# remove empty files (links that didn't have mp3 files in them)
find . -type f -empty -delete
echo "job done"