All pastes #1001779 Raw Edit

Stuff

public shellscript v1 · immutable
#1001779 ·published 2008-04-29 13:43 UTC
rendered paste body
#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 variablesdeclare -a SARRAYARTIST="none"AID="none"#Menu optionsOPTIONS="\"Change artist\" \"Change Artist ID\" \"Download information from last.fm\" \"Download and compare current information from what.cd\" \"Post all to what.cd\" \"Submit Similar Artists\" \"Post image to what.cd\" \"Post description 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">(.*?)</textarea>]sg' | 	 perl -0777 -lpe 's/\[.*?]//g' |	 sed -e 's/\&quot;/\"/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 postDesc {	if [ "$ARTIST" = "none" ]; then		echo "You need an artist!"	elif [ "$AID" = "none" ]; then		echo "You need an artist ID!"	else		getOldImg		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=$OLD&summary=automatically.generated.description&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" && OLD=""	fi}function getOldImg {	OLD=$( 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?action=edit&artistid=$AID" -O - | 		 grep "name=\"image\""  | sed 's/.*value=\"\(.*\)\".*/\1/' )}function postIMG {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="image=$IMG&summary=automatically.generated.image&action=edit" \		 --no-check-certificate "http://what.cd/artist.php?action=edit&artistid=$AID" && rm artist*	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">(.*?)</div>]sg' | 				sed 's/<br \/>//g' | sed 's/\&quot;/\"/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 "<img width=\"50\" src=\"http://user" | sed 's/.*alt=\"\(.*\)\".*/\1/g' > array	fi	exec 10<array	while read LINE <&10; do		SARRAY[$COUNT]=$LINE		((COUNT++))	done	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 menuseval set $OPTIONSresetMenuselect 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" = "Post all to what.cd" ]; then		submitSimilars		postIMG		postDesc	elif [ "$opt" = "Submit Similar Artists" ]; then		submitSimilars	elif [ "$opt" = "Post image to what.cd" ]; then		postIMG	elif [ "$opt" = "Post description to what.cd" ]; then		postDesc	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!"	fidone