-
Notifications
You must be signed in to change notification settings - Fork 0
/
play_list.php
48 lines (40 loc) · 1.05 KB
/
play_list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
// Show all errors
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
function setup() {
$ids = [];
// Get the RSS feed for this Youtube channel
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.youtube.com/feeds/videos.xml?channel_id=UCfRXKGrGO9h6O0lAsSjbsCw');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$data = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_status !== 200) {
return $ids;
}
// Parse the feed as XML
$feed = simplexml_load_string($data);
if ($feed === false) {
return $ids;
}
// Get the ids for all the videos
foreach ($feed->children() as $child) {
if ($child->getName() == "entry") {
foreach($child->children() as $sub_child) {
if ($sub_child->getName() == "id") {
$id = preg_replace('/^yt:video:/', '', $sub_child);
$ids[] = $id;
}
}
}
}
return $ids;
}
$ids = setup();
header('Content-Type: application/json');
echo json_encode($ids);
?>