Current location: Hot Scripts Forums » Programming Languages » PHP » Album Artwork DB?


Album Artwork DB?

Reply
  #1 (permalink)  
Old 09-15-06, 04:53 PM
eviljoker7075 eviljoker7075 is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Album Artwork DB?

Hey all! I am currently setting up a CD review website, where users submit their own reviews, I am using the Drupal CMS and I need some help. Is there any way I can have the reviews automatically find an album front cover to display on the review page?

Users will obviusly be submitting the album and artist name in a form so I'm guessing I can pick the information up from that, but I don't know where I could look for the artwork... can anyone offer up any advice on this?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 09-15-06, 05:09 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Hmm... don't know where to move this really. I guess the PHP section is alright.

This is probably doable, but you can't really trust it.
Reply With Quote
  #3 (permalink)  
Old 09-15-06, 05:13 PM
eviljoker7075 eviljoker7075 is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
What do you mean can't really trust it?

I'm gonna need to find a way to do it as it is a really important feature of the site really lol!
Reply With Quote
  #4 (permalink)  
Old 09-16-06, 12:58 AM
duesi's Avatar
duesi duesi is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 225
Thanks: 0
Thanked 0 Times in 0 Posts
Just a side remark: what about copyright issues?
The music industry can be really aggressive when it comes to this issue, so make sure, you are allowed to display album covers (for example by associating with amazon).

Happy Coding!
__________________
Duesi

"One of the great skills in using any language is knowing what not to use, what not to say" (Ron Jeffries)

http://www.swissbytes.de
Reply With Quote
  #5 (permalink)  
Old 09-16-06, 03:46 AM
eviljoker7075 eviljoker7075 is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah I was thinking that too... hosting the images myself though is out of the question as I would need to have EVERY album concievable, just in case it was reviewed lol!
Reply With Quote
  #6 (permalink)  
Old 09-16-06, 03:51 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Okay, here a very simple example.

PHP Code:

<?php


if (isset($_POST['artist']))
{
    
$save_path './covers/';
    
    
$artist preg_replace('/\s/''+'$_POST['artist']);
    
$album preg_replace('/\s/''+'$_POST['album']);
    
    if (
$data = @file_get_contents('http://www.last.fm/music/'$artist .'/'$album))
    {
        
preg_match('/<div class=\"cover\"><a(.*?)><img src=\"(.*?)\"(.*?) \/><\/a><\/div>/'$data$matches);
        
        if (
$cover = @file_get_contents($matches[2]))
        {
            
$filepath $save_path basename($matches[2]);
            
$fp fopen($filepath'w');
            
fwrite($fp$cover);
            
fclose($fp);
            
            echo 
'<img src="'$filepath .'" />';
            echo 
'<br />Cover saved <a href="'$filepath .'">here</a>';
        }
    }
    else
    {
        echo 
'Could not find cover';
    }
}

?>

<form action="" method="post">
Artist: <input type="text" name="artist" />
Album: <input type="text" name="album" />
<input type="submit" />
</form>
It attempts to get the cover from www.last.fm
If it finds the cover, it will safe a copy in a directory on your server and display it.

You should keep Duesi's point in mind though. You could get in trouble with that... Use at own risk, lol.
Reply With Quote
  #7 (permalink)  
Old 09-16-06, 04:04 AM
eviljoker7075 eviljoker7075 is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
So, will it help if I asked them fior permission?

Would this be possible for amazon?
Reply With Quote
  #8 (permalink)  
Old 09-16-06, 04:12 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Amazon would probably be possible.. but more difficult cause they have weird URLs and it's hard to bulid it and get its contents. This is why I decided to use last.fm. If you don't plan to create a super underground music review site, I guess last.fm will be okay. They have nearly every album.

As for the permission... I have no idea. But I guess you can ask and try.
Reply With Quote
  #9 (permalink)  
Old 09-16-06, 04:13 AM
eviljoker7075 eviljoker7075 is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Excellent!! Will give it a go! I'll tell you what they say!

BTW, what happens if the album can't be found? Can I add a default 'not found' image?
Reply With Quote
  #10 (permalink)  
Old 09-16-06, 04:17 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Yes, sure. Just replace this line:
PHP Code:

echo 'Could not find cover'
And output your own HTML which displays the not found image. Since you didn't post any code can't I help more. I guess you will have to save the data in a database, which the code above doesn't.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML photo album flashieme Job Offers & Assistance 0 12-06-05 01:10 PM
SQL db - custom insert and select query app needed ATS16805 ASP.NET 1 06-24-05 04:38 PM
I can't get this to connect to the DB!!!! Noah PHP 1 06-20-05 12:29 PM
Passing Array values into the db Stripe-man PHP 2 05-14-05 02:59 AM
Compare Directory listing to db perleo PHP 0 05-24-04 12:45 PM


All times are GMT -5. The time now is 07:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.