【问题标题】:Retrieving Spotify Playlist in PHP在 PHP 中检索 Spotify 播放列表
【发布时间】:2012-06-20 21:11:48
【问题描述】:

目前我使用此代码使用 PHP 获取特定 Spotify 播放列表的信息(检索有关播放列表“最新”标题的信息):

$retu = getsrc("https://embed.spotify.com/?uri=spotify:user:1121975814:playlist:20uXqHNuHw7kR2KWYfQYRb");
$expl = explode('<li class="track-',$retu);

$artist = get_string_between($expl[count($expl)-1],'style="">','</li>');
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<br>";

$src2 = getsrc("http://open.spotify.com/track/$id");
$cover = get_string_between($src2,'<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;
}

问题如下:

  • 播放列表信息几乎从不刷新,或者如果刷新仍然包含过时的信息

您有什么更好的方法来获取播放列表曲目吗? 我可以使用任何 API 吗?

提前致谢

【问题讨论】:

    标签: php spotify playlist


    【解决方案1】:

    这应该会有所帮助。 libspotify 的 php 包装器。

    https://github.com/vilhelmk/libspotify-php

    【讨论】:

      猜你喜欢
      • 2012-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多