#AutoArtist by oorza # #Copies information from last.fm and submits it to artist wiki's on what.cd #Current version is 0.7.1 #! /bin/bash #script wide variables declare -a SARRAY ARTIST="none" AID="none" #Menu options OPTIONS="\"Change artist\" \"Change Artist ID\" \"Download information from last.fm\" \"Download and compare current information from what.cd\" \"Submit Similar Artists\" \"Post information to what.cd\" \"Show current info\" \"quit\"" function getInfo { wget -q --keep-session-cookies --load-cookies=./cookies.txt --save-cookies=./cookies.txt \ -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" \ --no-check-certificate "http://last.fm/music/$ARTIST/+wiki?action=edit" -O - | perl -0777 -lne 'print for m[id="wikitextarea">(.*?)]sg' | perl -0777 -lpe 's/\[.*?]//g' | sed -e 's/\"/\"/g' > ./information/$ARTIST IMG=$( wget -q --keep-session-cookies --load-cookies=./cookies.txt --save-cookies=./cookies.txt \ -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" \ --no-check-certificate "http://last.fm/music/$ARTIST/+wiki?action=edit" -O - | grep imgHolder | grep -o 'src=".*[png|jpg|jpeg|gif]"' | sed 's/src="\(.*\)" alt.*/\1/' ) echo Using image: $IMG } function postWhat { if [ "$ARTIST" = "none" ]; then echo "You need an artist!" elif [ "$AID" = "none" ]; then echo "You need an artist ID!" else wget -q --keep-session-cookies --load-cookies=./cookies.txt --save-cookies=./cookies.txt \ -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" \ --post-data="body=$( cat ./information/$ARTIST )&image=$IMG&summary=automatically.generated&action=edit" \ --no-check-certificate "http://what.cd/artist.php?action=edit&artistid=$AID" && rm artist* && echo "Successfully updated what.cd! Artist and Artist ID reset." && ARTIST="none" && AID="none" fi } function resetMenu { PS3="Main menu (press Enter for options): " } function whatSearch { PS3="Search menu (press Enter for options): " select choice in Search Manual Return; do if [ "$choice" = "Search" ]; then if [ "$ARTIST" = "none" ]; then echo "you need an artist!" break else echo "Search for $ARTIST returns: " wget -q --keep-session-cookies --load-cookies=./cookies.txt --save-cookies=./cookies.txt \ -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" \ --no-check-certificate "http://what.cd/torrents.php?artistname=$ARTIST&action=advanced" -O - | grep "a href=\"artist.php" | sed 's/.*id=\(.*\)\" title=\"View Artist\">\(.*\)<\/a> -.*/\1 \2/g' echo -e "\nWhat is the Artist ID?" read -e AID resetMenu break fi elif [ "$choice" = "Manual" ]; then echo "What is the artist ID?" read -e AID resetMenu break elif [ "$choice" = "Return" ]; then resetMenu break else echo "Not a valid choice, try again!" fi done } function getArtist { echo "Artist?" read -e ARTIST ARTIST=$( echo $ARTIST | sed -e 's/ /+/g' ) if [ -e information/$ARTIST ]; then rm ./information/$ARTIST echo "old $ARTIST information removed!" fi AID="none" } function compareOldNew { PS3="Compare menu (press Enter for options):" select compChoice in Current Last.fm Return; do if [ "$compChoice" = "Current" ]; then if [ "$AID" = "none" ]; then echo "You need an artist ID!" PS3="Press enter for options or select a number: " break else wget -q --keep-session-cookies --load-cookies=./cookies.txt --save-cookies=./cookies.txt \ -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" \ --no-check-certificate "http://what.cd/artist.php?id=$AID" -O - | perl -0777 -lne 'print for m[class="body">(.*?)]sg' | sed 's/
//g' | sed 's/\"/\"/g' echo -e "\n" fi elif [ "$compChoice" = "Last.fm" ]; then cat ./information/$ARTIST echo -e "\n" elif [ "$compChoice" = "Return" ]; then resetMenu break else echo "Not a valid choice, try again!" fi done } function getSimilars { COUNT=0 if [ "$ARTIST" = "none" ]; then echo "You need an artist!" else wget -q http://last.fm/music/$ARTIST -O - | grep " array fi exec 10&- } function submitSimilars { if [ "$ARTIST" = "none" ]; then echo "You need an artist!" elif [ "$AID" = "none" ]; then echo "You need an artist ID!" else for (( i=0; i<${#SARRAY[@]}; i++ )); do wget -q --keep-session-cookies --load-cookies=./cookies.txt --save-cookies=./cookies.txt \ -U "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" \ --post-data="action=add_similar&artistid=$AID&submit=+&artistname=${SARRAY[i]}" \ --no-check-certificate "http://what.cd/artist.php?id=$AID" rm artist.php* SARRAY[$i]="" done fi rm array } if [ -d information/ ]; then echo "directory exists!" else mkdir information echo "directory created!" fi # and this is why I love bash menus eval set $OPTIONS resetMenu select opt in "$@"; do if [ "$opt" = "Change artist" ]; then getArtist elif [ "$opt" = "Change Artist ID" ]; then whatSearch elif [ "$opt" = "Download information from last.fm" ]; then getInfo getSimilars elif [ "$opt" = "Download and compare current information from what.cd" ]; then compareOldNew elif [ "$opt" = "Submit Similar Artists" ]; then submitSimilars elif [ "$opt" = "Post information to what.cd" ]; then postWhat elif [ "$opt" = "Show current info" ]; then echo "Current artist: $ARTIST, Artist ID: $AID" elif [ "$opt" = "quit" ]; then exit else echo "Not a valid selection, try again!" fi done