grabbing Album art [Solved]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

grabbing Album art [Solved]

#1 Post by zigbert »

Downloading album art should be easy, but I can't get it work every time - even if I know that the album art is present on the webpage.

Can you see what I am doing wrong? - thank you.

Code: Select all

#!/bin/bash 
STRING="madonna like a virgin" #artist album
URL="`echo "http://www.freecovers.net/api/search/$STRING/Music+CD" | tr ' ' '-'`"
URL2=`wget -q -O - "$@" $URL | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
wget "$URL2" -O $HOME/album_art.jpg
Last edited by zigbert on Fri 20 May 2011, 15:11, edited 1 time in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#2 Post by L18L »

# wget $URL -O $HOME/album_art.jpg
--2011-05-17 18:16:54-- http://www.freecovers.net/api/search/ma ... n/Music+CD
Auflösen des Hostnamen »www.freecovers.net (www.freecovers.net)«.... 204.45.50.211
Verbindungsaufbau zu www.freecovers.net (www.freecovers.net)|204.45.50.211|:80... verbunden.
HTTP Anforderung gesendet, warte auf Antwort... 200 OK
Cookie von »www.freecovers.net« versuchte die Domain auf »www.freecovers.net« zu ändern
Länge: nicht spezifiziert [application/xml]
Saving to: `/root/album_art.jpg'

[ <=> ] 28.609 4,86K/s in 5,7s

2011-05-17 18:17:07 (4,86 KB/s) - `/root/album_art.jpg' saved [28609]

#

$URL not $URL2 :)

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

Re: grabbing Album art

#3 Post by Dougal »

zigbert wrote:Can you see what I am doing wrong? - thank you.

Code: Select all

STRING="madonna like a virgin" #artist album
Sigmund, have you been sniffing your paints??

Code: Select all

URL2=`wget -q -O - "$@" $URL | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
What's supposed to be in $@?

Anyway, the problem is that the search doesn't return anything sometimes... I just tried your example search and three times out of five it returned nothing, so you might want to do something ugly like

Code: Select all

for i in 1 2 3 4 5 ; do
  URL2=`wget -q -O - "$@" $URL | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
  [ -n "$URL2" ] && break
done

if [ -z "$URL2" ] ; then 
# tell user there's no cover
fi
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#4 Post by seaside »

Probably something on the server because the pure url line failed 3 out of five for me.

Dougal's solution brings it down to 1 failure in the 15 tries I attempted with this -

Code: Select all

for i in 1 2 3 4 5 ; do
  URL2=`wget -q -O - "$@" $URL | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
  wget "$URL2" -O $HOME/album_art.jpg
  [ -n "$URL2" ] && break
done
How can something be ugly if it works :)

Cheers,
s

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#5 Post by Dougal »

seaside wrote:

Code: Select all

for i in 1 2 3 4 5 ; do
  URL2=`wget -q -O - "$@" $URL | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
  wget "$URL2" -O $HOME/album_art.jpg
  [ -n "$URL2" ] && break
done
That should be

Code: Select all

for i in 1 2 3 4 5 ; do
  URL2=`wget -q -O - "$@" $URL | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
  [ -n "$URL2" ] && break
done
wget "$URL2" -O $HOME/album_art.jpg
there's no point in trying to download if you found nothing (I copied the wrong line in my previous post...)

Anyway, URL2 is unnecessary:

Code: Select all

for i in 1 2 3 4 5 ; do
  URL=`wget -q -O - "$@" "http://www.freecovers.net/api/search/${STRING// /-}/Music+CD" | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
  [ -n "$URL" ] && break
done
wget "$URL" -O $HOME/album_art.jpg
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#6 Post by zigbert »

Dougal, you're just great.

Code: Select all

for i in 1 2 3 4 5 ; do
  URL=`wget -q -O - "$@" "http://www.freecovers.net/api/search/${STRING// /-}/Music+CD" | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
  [ -n "$URL" ] && break
done
wget "$URL" -O $HOME/album_art.jpg
The only thing I don't understand is the "$@" :lol:
I have of course grabbed the code somewhere out there....... I rarely do anything on my own :)


Thank you
Sigmund

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

album art

#7 Post by vovchik »

Dear Dougal,

Works great for me too. I only wish there were some way of getting better search results. If you run it with Beatles "Abbey Road" as parameters, for example, www.freecovers.net offers up a rather weird cover. Also, if you change the search to "DVD+Movie" and type bananas, you won't get Woody Allen's film by that name, but you do get Zelig, Manhattan and Sleeper using those words. :(

With kind regards,
vovchik

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#8 Post by technosaurus »

I had a similar problem with wget in a simple flash download script - the problem ended up being output to stdout (piped through tar) instead of just doing a straight download and then manipulating the file. The for loop seems like an odd fix, but I'm not sure how to narrow down the problem to verify that it isn't the server - maybe try busybox wget?
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

#9 Post by Dougal »

technosaurus wrote:I had a similar problem with wget in a simple flash download script - the problem ended up being output to stdout (piped through tar) instead of just doing a straight download and then manipulating the file.
No, I tried without the -q and redirection to stdout and it still fails but wget reports success, so it's a problem with the server.

Sigmund, I just had about 15 minutes where freecovers.net completely failed, no matter how many times I tried... you might want to try a different server, like for example:

Code: Select all

URL=$(wget -q -O - "http://www.albumart.org/index.php?srchkey=${STRING// /+}&itempage=1&newsearch=1&searchindex=Music" | grep -F 'View larger image' | grep -m1 -o 'http://ecx.images-amazon.com/images/.*.jpg"' | cut -d'"' -f1)
(note that this gives you the smaller image, the one you see in the Amazon entry and is clickable.
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

Re: album art

#10 Post by Dougal »

vovchik wrote:if you change the search to "DVD+Movie" and type bananas, you won't get Woody Allen's film by that name, but you do get Zelig, Manhattan and Sleeper using those words. :(
I don't know... I tried "woody allen bananas" and it got me crap like "bananas in pajamas"! then it stopped working and I gave up.
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#11 Post by zigbert »

Omair
Great stuff, I have implemented it like this:

Code: Select all

album_art (){
	rm $WORKDIR/album_art.jpg
	for i in 1 2 3 4 5 ; do
		URL=`wget -q -O - "http://www.freecovers.net/api/search/${1// /-}/Music+CD" | grep -o -m 1 -i 'http:\/\/www\.freecovers.net\/preview\/0\/[a-z0-9]*\/big.jpg'`
	  [ -n "$URL" ] && break
	done
	#if no go, use another server (smaller image)
	[ ! "$URL" ] && URL=$(wget -q -O - "http://www.albumart.org/index.php?srchkey=${STRING// /+}&itempage=1&newsearch=1&searchindex=Music" | grep -F 'View larger image' | grep -m1 -o 'http://ecx.images-amazon.com/images/.*.jpg"' | cut -d'"' -f1)
	#download
	wget "$URL" -O $WORKDIR/album_art.jpg
}
The smaller alternative is better than nothing.


Thank you
Sigmund

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

Re: album art

#12 Post by technosaurus »

Dougal wrote:
vovchik wrote:if you change the search to "DVD+Movie" and type bananas, you won't get Woody Allen's film by that name, but you do get Zelig, Manhattan and Sleeper using those words. :(
I don't know... I tried "woody allen bananas" and it got me crap like "bananas in pajamas"! then it stopped working and I gave up.
damn "filter bubble" must assume that children use your computer with all of the puppy googling ... probably even worse if you use pfix=ram
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Post Reply