从CURL请求获取特定内容

时间:2015-10-18 04:45:38

标签: php curl

我试图从Spotify URI中获取歌曲标题和艺术家

目前 - > 获取用户ID和播放列表ID - >创建嵌入式播放列表 - > 吐出整个播放列表

RESULT from Embedded playlist

我真正想要做的就是用纯文本打印歌曲列表。我希望尽可能避免使用Spotify API

- index.php

<html>

<link rel="stylesheet" href="_/css/style.css" />
<script src="_/js/inputcheck.js"></script>
<body>

<section id="outPopUp">
    <form name="myForm" class="input-list style-1 clearfix" action="get_playlist.php" onsubmit="return validateForm()" method="get">
    Spotify URI to MP3:
    <input type="text" name="uri"><br>
    <input class="myButton" type="submit">

</section>
</body>
</html>

- get_playlist.php

<?php

$uri = $_GET['uri'];

// Match exact Spotify playlist URI pattern
if ($c=preg_match_all("/".'(spotify)'.'(:)'.'(user)'.'(:)'.'((?:[A-Za-z0-9_-]*))'.'(:)'.'(playlist)'.'(:)'.'((?:[A-Za-z0-9]*))'."/is", $uri, $matches)) {
    $userID = $matches[5][0];
    $playlistID = $matches[9][0];
} else {
echo 'Error: Could not parse URI. Script needs ?uri= with the Spotify playlist URI.';
die;
}

$url = "https://embed.spotify.com/?uri=spotify:user:".$userID.":playlist:".$playlistID."&output=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; curl)");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$embeddedplayer = curl_exec($ch);
curl_close($ch);

echo $embeddedplayer;

?>

如果有人可以提供帮助,那就太棒了

0 个答案:

没有答案