aboutsummaryrefslogtreecommitdiff
path: root/THASearch.sh
blob: f5f68b518f2a2f980dd78ca49912b5fb69083eb6 (plain)
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
#!/bin/bash
if [[ $1 != "" ]];then
    curl -s "http://modarchive.org/index.php?request=search&query=$1&submit=Find&search_type=filename_or_songtitle" > .list
    number_of_page=$(cat .list | grep -i ">[0-9]</option>$" | rev | cut -d'<' -f2 | cut -d'>' -f1 | sed -n '1p')

    if [[ $number_of_page != "" ]];then
        for ((i=1; i <= $number_of_page; i++ ))
        do
            if [[ $i != "1" ]];then
                curl -s "http://modarchive.org/index.php?request=search&query=chiptune&submit=Find&search_type=filename_or_songtitle&page="$i"#mods" > .list
            fi
            while IFS='' read -r line || [[ -n "$line"  ]]; do
                if [[ $line =~ "downloads.php" ]];then
                    line=$(echo $line | grep "downloads.php" | awk '{print $9}' | cut -d'"' -f2 | cut -d'"' -f1)
                    echo $line
                fi
            done < ".list"
        done
    else
        echo "not found"
    fi
    rm .list
else
    echo "Usage :  TMASearch.sh <search_query>"
fi