Author Topic: Batch lookup artists from last.fm  (Read 2495 times)

jesperts

  • Singing for myself
  • *
  • Posts: 5
  • Karma: +1/-0
  • Newbie :)
    • View Profile
Batch lookup artists from last.fm
« on: 30-08-2012 00:13 »
This scripts updates all images, bios and related artist for a performer

$special = artistnumber to start with (first is 2)
$antal = number of artists to process

Save as file in root of ampjuke install dir

Code: [Select]

<?php
// auto_performers.php: Automatically fetch artist images
//
// By: Jesper S.

require_once('./sql.php');
require_once(
'./set_td_colors.php');
require_once(
'./disp.php');
require_once(
'./lastfm_lib.php');
require_once(
'./google_lib.php'); // 0.8.6: Introduced
require_once('./configuration.php');
$special=1;
$antal=700;
echo 
"processing: " $antal;

$special=only_digits($special); // 0.7.6

while($special $antal){
// get+display headline: performer's name:
$qry="SELECT * FROM performer WHERE performer.pid=".$special;
$header_result=execute_sql($qry,0,1,$nr);
$header_row=mysql_fetch_array($header_result);
print($header_row['pname']);
//echo $special;

$bio=lastfm_get_bio($header_row['pid'],urlencode($header_row['pname']),0,1);

$total_related_performers=lastfm_get_number_of_related_performers($header_row['pid'],urlencode($header_row['pname']),
$lastfm_min_related_match,$lastfm_max_related_artists);
//print $total_related_performers;
$total_related_performers=0;

if ($total_related_performers==0) { // ask last.fm:
$total_related_performers=lastfm_update_related_performers($header_row['pid'],urlencode($header_row['pname']),
$lastfm_min_related_match,$lastfm_max_related_artists);
$total_related_performers=lastfm_get_number_of_related_performers($header_row['pid'],urlencode($header_row['pname']),
$lastfm_min_related_match,$lastfm_max_related_artists);
}

$lastfm_img_url='http://ws.audioscrobbler.com/2.0/?method=artist.getimages';
$lastfm_img_url.='&artist='.str_replace(' ','+',urlencode($header_row['pname']));
$lastfm_img_url.='&api_key=b25b959554ed76058ac220b7b2e0a026';
$img_xml=retrieve_xml($lastfm_img_url,$n,$n);

$img_url='';
if (isset($img_xml->images->image[0]->sizes->size[2])) { 
$img_url=$img_xml->images->image[0]->sizes->size[2];
}  

if ($img_url<>'') { 
$rel_pid=$header_row['pid'];

if ($rel_pid>0) {
$rel_filename=' ./lastfm/'.$rel_pid.'.jpg'
if (!file_exists($rel_filename)) {
$data=file_get_contents($img_url);
$handle=fopen('./lastfm/'.$rel_pid.'.jpg''w');
fwrite($handle,$data);
fclose($handle);
} else { 
touch($rel_filename);
}
}
}

$special++;
}
?>