title: Retrieving Spotify Playlist in PHP
body: <p>At the moment i use this code to fetch the information of a specific Spotify Playlist using PHP (retrieves informations about the "newest" title of the playlist):</p>
  
  <pre><code>$retu = getsrc("https://embed.spotify.com/?uri=spotify:user:1121975814:playlist:20uXqHNuHw7kR2KWYfQYRb");
  $expl = explode('&lt;li class="track-',$retu);
  
  $artist = get_string_between($expl[count($expl)-1],'style=""&gt;','&lt;/li&gt;');
  if(empty($artist)) die($retu);
  $name = get_string_between($expl[count($expl)-1],'. ','"');
  $id = get_string_between($expl[count($expl)-1],'title ',' ');
  echo "$name ($artist) - $id&lt;br&gt;";
  
  $src2 = getsrc("http://open.spotify.com/track/$id");
  $cover = get_string_between($src2,'&lt;img id="cover-art" src="','"');
  
  function get_string_between($string, $start, $end)
  {
      $string = " ".$string;
      $ini = strpos($string,$start);
      if ($ini == 0) return "";
      $ini += strlen($start);
      $len = strpos($string,$end,$ini) - $ini;
      return substr($string,$ini,$len);
  }
  
  function getsrc($url)
  {
      $ch = curl_init();
      $cookies = tmpfile();
      $user_agent="Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
      curl_setopt($ch, CURLOPT_POST, 0);
      curl_setopt($ch, CURLOPT_HEADER, 1);
      curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
      curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
      $retu = curl_exec($ch);
  
      curl_close($ch);
      return $retu;
  }
  </code></pre>
  
  <p>The problem are the following ones:</p>
  
  <ul>
  <li>Slow</li>
  <li>Playlists information refresh close to never, or if, the refresh still contains outdated informations</li>
  </ul>
  
  <p>Do you have any better methods for getting the playlist tracks?
  Any API i can use for that?</p>
  
  <p>Thanks in Advance</p>