これを希望どおりに機能させるのに非常に苦労しています。プレイリストからすべてのビデオを取得しようとしています。現在は 20 件取得できますが、中には 100 件を超える動画を含むプレイリストもあります。これは私が問題を抱えているところです。考えられるすべてを使い果たしたので、ここで別のユーザーから見つけた次のコードを使用しています。
これにより、プロセスが開始されます。私がやろうとしていることについてGoogleの開発サイトには最小限の情報があるため、特定のURLを介してXMLフィードを呼び出していることに注意してください。
public function saveSpecificVideoFeed($id) {
$url = 'https://gdata.youtube.com/feeds/api/playlists/' . $id . '?v=2';
$feed = $this->yt->getPlaylistVideoFeed($url);
$this->saveEntireFeed($feed, 1);
}
これは私が上記の関数を渡すものです:
public function saveEntireFeed($videoFeed, $counter) {
foreach ($videoFeed as $videoEntry) {
if (self::saveVideoEntry($videoEntry)) {
$this->success++;
} else {
$this->failed++;
}
$counter++;
}
// See whether we have another set of results
try {
$videoFeed = $videoFeed->getNextFeed();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage() . "<br/>";
echo "Successfuly Pulled: <b>" . $this->success . "</b> Videos.<br/>";
echo "Failed to Pull: <b>" . $this->failed . "</b> Videos.<br/>";
echo "You Tryed to Insert: <b>" . $this->duplicate . "</b> Duplicate Videos.";
return;
}
if ($videoFeed) {
self::saveEntireFeed($videoFeed, $counter);
}
}
ビデオを個別に保存する方法は次のとおりです。
private function saveVideoEntry($videoEntry) {
if (self::videoExists($videoEntry->getVideoId())) {
// Do nothing if it exists
} else {
$videoThumbnails = $videoEntry->getVideoThumbnails();
$thumbs = null;
foreach ($videoThumbnails as $videoThumbnail) {
$thumbs .= $videoThumbnail['url'] . ',';
}
$binds = array(
'title' => $videoEntry->getVideoTitle(),
'videoId' => $videoEntry->getVideoId(),
'updated' => $videoEntry->getUpdated(),
'description' => $videoEntry->getVideoDescription(),
'category' => $videoEntry->getVideoCategory(),
'tags' => implode(", ", $videoEntry->getVideoTags()),
'watchPage' => $videoEntry->getVideoWatchPageUrl(),
'flashPlayerUrl' => $videoEntry->getFlashPlayerUrl(),
'duration' => $videoEntry->getVideoDuration(),
'viewCount' => $videoEntry->getVideoViewCount(),
'thumbnail' => $thumbs,
);
$sql = "INSERT INTO $this->tblName (title, videoId, updated, description, category, tags, watchPage, flashPlayerUrl, duration, viewCount, thumbnail)
VALUES (:title, :videoId, :updated, :description, :category, :tags, :watchPage, :flashPlayerUrl, :duration, :viewCount, :thumbnail)";
$sth = $this->db->prepare($sql);
foreach ($binds as $key => $value) {
if ($value == null) {
$value = '';
}
$sth->bindValue(":{$key}", $value);
}
if ($sth->execute()) {
return true;
} else {
print_r($sth->errorInfo());
return false;
}
}
}
これは、プルから得たものを読みやすい形式で知らせるためにブラウザー出力から取得したものです。
抽出を続行してテーブルが作成されました。次の結果セットへのリンクが見つかりません。プル成功: 20 本の動画。プルに失敗しました: 0 件の動画。挿入しようとしました: 0 件の重複動画。
ただし、これは 36 本の動画を含むプレイリストであるため、残りの動画にアクセスすることが問題です。これを行うための文書化されていない簡単な方法はありますか? どんな助けでも大歓迎です。
リクエスト URL で max-results 要素と start-index 要素を使用して、ループスルー時に必要な値まで増やしてみましたが、これは YouTube API からの XML 出力には影響しません。
どんな助けでも大歓迎です。