【发布时间】:2014-04-27 14:53:58
【问题描述】:
我遇到了问题。我正在尝试使用 iTunes 搜索 API 生成一个预览歌曲按钮来预览存储在 MySQL 数据库中的歌曲。
我写了以下代码:
<?php
// Script de conexión a la base de datos.
include "includes/connect.php";
$songs = "";
$query = $db->prepare("SELECT artista, titulo, nombre, count(id) as uploadCount FROM canciones GROUP BY artista, titulo ORDER BY uploadCount DESC");
$query->execute(array($songs));
$songs = $query->fetchAll(PDO::FETCH_ASSOC);
echo '<table id="tblCanciones" width="95%" border="0" align="center" cellpadding="0">
<tr align="left">
<th class="tblCancionesHeader" width="33%">Artista</th>
<th class="tblCancionesHeader" width="32%">Título</th>
<th class="tblCancionesHeader" width="20%">Pedida por</th>
<th class="tblCancionesHeader" width="10%">Veces</th>
<th class="tblCancionesHeader" width="4%"></th>
</tr>';
foreach($songs as $song) {
// Buscar el link de la preview de la canción en la iTunes store...
$term = urlencode($song["artista"])."+".urlencode($song["titulo"]);
$json = file_get_contents('http://itunes.apple.com/search?term='.$term.'&limit=1&entity=musicArtist,musicTrack,album,mix,song');
$array = json_decode($json, true);
echo '<tr align="left">
<td nowrap="nowrap" class="tblCancionesFila">'.$song["artista"].'</td>
<td nowrap="nowrap" class="tblCancionesFila">'.$song["titulo"].'</td>
<td nowrap="nowrap" class="tblCancionesFila">'.$song["nombre"].'</td>
<td nowrap="nowrap" class="tblCancionesFila">'.$song["uploadCount"].'</td>';
if (!isset($array['results'][0]['previewUrl'])) {
echo '<td nowrap="nowrap" class="tblCancionesFila">---</td>';
} else {
echo '<td nowrap="nowrap" class="tblCancionesFila"><a href="'.$array['results'][0]['previewUrl'].'"><img src="images/imgPreview.jpg" width="20" height="20" alt="preview" title="preview" border="0" /></a></td>';
}
echo '</tr>';
}
echo '</table>';
?>
它或多或少有一些限制。我只是想让它获取预览链接,所以我将结果限制为 1。所以有时它找不到结果...
主要问题是它很慢,获取结果很慢......
我想我做错了什么。
是否有任何其他简单的方法可以获得相同的功能,但可能使用 itunes 以外的其他服务,如 spotify、soundcloud 或其他?
谢谢!
【问题讨论】:
-
您能告诉我如何使用 php 从 iTunes 获取所有游戏(应用程序)的详细信息吗?我正在寻找,但我无法得到答案。我也使用过搜索 API。但我不知道如何使用它?这是我的问题stackoverflow.com/questions/23696311/…