Hi there,

I have this script that helps with displaying my iTunes Playlist and showing images pulled from Amazon.com.

Now what I am trying to acheive is to show only the 1st image for the first item on the playlist. The other songs on the playlist should only display - title - artist - album.

Can anyone assit please?

Thanks

<?php


//_________C_O_N_F_I_G_U_R_A_T_I_O_N_S_____//


$conf['amazon_file'] = './AmazonSearch.php';

$conf['itunes_file'] = '/home/public_html/itunes/now_playing.xml';


//________F_U_N_C_T_I_O_N_S_______________//

if(file_exists($conf['amazon_file']))
{
	require($conf['amazon_file']);
}else{
	echo '
		<li>ERROR - Amazon file not found</li>';
}

function PrintIt($title, $album, $artist)
{
   $Tag   = 'webservices-20';
   $Token = 'D2A8O9KBF2OK4L';

   $AS = new AmazonSearch($Token, $Tag);

   if ( strlen( $artist ) && strlen( $album ) )
   {
      $Power = 'artist:' . $artist . ' and title:' . $album;
      $Result = $AS->DoPowerSearch($Power, 'lite', 'music', 1);
   }
   else
   {
      $Result = $AS->DoArtistSearch($artist, 'lite', 'music', 1);
   }

   if ($Result !== null && count($Result) )
   {
      $ResultRow = $Result[0];

  $ASIN        = $ResultRow['Asin'];
  $URL         = $ResultRow['Url'];
  $UPC         = $ResultRow['Upc'];
  $Price       = $ResultRow['OurPrice'];
  $ProductName = $ResultRow['ProductName'];
  $AlbumArtURL = $ResultRow['ImageUrlMedium'];

   }else{

   $AlbumArtURL = '/images/music-no-image.gif';
   $URL = 'http://music.barnesandnoble.com/search/results.asp?NME='.$artist.'&SNG=&INS=&LBL=&TYP=P&CAT=&Search=Search';

   }

   return '<a href="'.$URL.'" target="_blank"><img src="' . $AlbumArtURL . '" alt="' . $artist . '-' . $album . '" /></a>';
}

$xml_parser = xml_parser_create();

if (!($fp = fopen( $conf['itunes_file'], 'r'))) 
{
   die('ERROR - iTunes file not readable or not found');
}

$data = fread( $fp, filesize($conf['itunes_file']) );
fclose( $fp );
xml_parse_into_struct( $xml_parser, $data, $vals, $index );
xml_parser_free( $xml_parser );
$c = 0;

//___________H_T_M_L___O_U_T_P_U_T___________//


foreach ($index as $a)
{
	$d=13*$c+2;
	$e=13*$c+5;
	$f=13*$c+8;
	$title  = $vals[$d]['value'];
	$artist = $vals[$e]['value'];
	$album  = $vals[$f]['value'];
	$c++;

echo '
		<li>'.PrintIt($title, $album, $artist).'</li>
		<li><strong>'.$title.'</strong></li>
		<li>'.$artist.'</li>
		<li><em>'.$album.'</em></li>';

}

?>

    easiest way i reckon is to have a simple counter,
    you will need to change the main output though:

    //change
    
    echo ' 
                <li>'.PrintIt($title, $album, $artist).'</li> 
                <li><strong>'.$title.'</strong></li> 
                <li>'.$artist.'</li> 
                <li><em>'.$album.'</em></li>';
    
    //to
    
    if ($noofcursong == 1) {
    echo '<li>'.PrintIt($title, $album, $artist).'</li>';
    }
    echo '<li><strong>'.$title.'</strong></li>
             <li>'.$artist.'</li>
             <li><em>'.$album.'</em></li>';
    

    before the PrintIt function you need to put:
    $noofcursong = 0;
    and then within the PrintIt function put:
    global $noofcursong = 1;

    i think that should work :rolleyes:

      I think I am having a total mindmelt!

      Could you possibly tell me how I would write the code into the printit function?

      Many thanks for your help 🙂
      J

        sure
        heres the full code, as you can see i put big lines on either side of where its changed so you can see it:

        <?php 
        
        
        //_________C_O_N_F_I_G_U_R_A_T_I_O_N_S_____// 
        
        
        $conf['amazon_file'] = './AmazonSearch.php'; 
        
        $conf['itunes_file'] = '/home/public_html/itunes/now_playing.xml'; 
        
        
        //________F_U_N_C_T_I_O_N_S_______________// 
        
        if(file_exists($conf['amazon_file'])) 
        { 
            require($conf['amazon_file']); 
        }else{ 
            echo ' 
                <li>ERROR - Amazon file not found</li>'; 
        }
        //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
        $noofcursong = 0;
        //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
        function PrintIt($title, $album, $artist) 
        { 
           $Tag   = 'webservices-20'; 
           $Token = 'D2A8O9KBF2OK4L'; 
        
           $AS = new AmazonSearch($Token, $Tag); 
        
           if ( strlen( $artist ) && strlen( $album ) ) 
           { 
              $Power = 'artist:' . $artist . ' and title:' . $album; 
              $Result = $AS->DoPowerSearch($Power, 'lite', 'music', 1); 
           } 
           else 
           { 
              $Result = $AS->DoArtistSearch($artist, 'lite', 'music', 1); 
           } 
        
           if ($Result !== null && count($Result) ) 
           { 
              $ResultRow = $Result[0]; 
        
          $ASIN        = $ResultRow['Asin']; 
          $URL         = $ResultRow['Url']; 
          $UPC         = $ResultRow['Upc']; 
          $Price       = $ResultRow['OurPrice']; 
          $ProductName = $ResultRow['ProductName']; 
          $AlbumArtURL = $ResultRow['ImageUrlMedium']; 
        
           }else{ 
        
           $AlbumArtURL = '/images/music-no-image.gif'; 
           $URL = 'http://music.barnesandnoble.com/search/results.asp?NME='.$artist.'&SNG=&INS=&LBL=&TYP=P&CAT=&Search=Search'; 
        
           }
           //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
           global $noofcursong = 1;
           //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
           return '<a href="'.$URL.'" target="_blank"><img src="' . $AlbumArtURL . '" alt="' . $artist . '-' . $album . '" /></a>'; 
        } 
        
        $xml_parser = xml_parser_create(); 
        
        if (!($fp = fopen( $conf['itunes_file'], 'r')))  
        { die('ERROR - iTunes file not readable or not found'); } $data = fread( $fp, filesize($conf['itunes_file']) ); fclose( $fp ); xml_parse_into_struct( $xml_parser, $data, $vals, $index ); xml_parser_free( $xml_parser ); $c = 0; //___________H_T_M_L___O_U_T_P_U_T___________// foreach ($index as $a) { $d=13*$c+2; $e=13*$c+5; $f=13*$c+8; $title = $vals[$d]['value']; $artist = $vals[$e]['value']; $album = $vals[$f]['value']; $c++; //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- if ($noofcursong == 1) { echo '<li>'.PrintIt($title, $album, $artist).'</li>'; } echo '<li><strong>'.$title.'</strong></li> <li>'.$artist.'</li> <li><em>'.$album.'</em></li>'; //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- } ?>

          Hi Helz,

          Thanks for that 🙂

          the

          //---------------------------
          global $noofcursong = 1;
          //
          ---------------------------

          is throwing up a parse error:

          Parse error: parse error, expecting ','' or';'' in /home/public_html/itunes/newTunes.php on line 59

          Thanks anyway
          J

            just get rid of the global part of it

              Thanks for your efforts but it is still not working.

              It now causes an error with:

              if (!($fp = fopen( $conf['itunes_file'], 'r')))

              Thanks for the time you spent on this.
              Cheers
              Karl

                what is the error that it gives?

                  Sorry about that:

                  Warning: fopen(/home/public_html/itunes/now_playing.xml): failed to open stream: No such file or directory in /home/public_html/itunes/newTunes.php on line 64
                  ERROR - iTunes file not readable or not found

                  Line 64 is: if (!($fp = fopen( $conf['itunes_file'], 'r')))

                  Thanks 🙂

                    hmm, if the xml file that its trying to open is only created when actually playing the music, then the script wont work since the xml file doesn't exist.

                    did the script work before the changes?
                    when the music was playing and when it was not.

                      Hi there and sorry for the delay!

                      I had made an error with my path - sorry.

                      The playlist displays with your new code with the global removed but it does not show the image. Only shows title, artist and album name.

                      Many thanks
                      Karl

                        right okie
                        i was right in doing the global part except it has to be done is two parts.
                        put:
                        global $noofcursong;
                        before:
                        $noofcursong = 1;

                        in the PrintIt function

                          Write a Reply...