This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.php
executable file
·135 lines (114 loc) · 4.64 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/***********************************
config stuff up here
************************************/
date_default_timezone_set('America/New_York');
$my_podcast = ''; /* www.mixcloud.com/THISBIT/ */
$my_feed_url = ""; /* url where your cron job saves the output feed - used for self-reference */
$language = "en-us";
/***************************************
nothing to configure below this line
****************************************/
include_once('curl.php');
$user_info = json_decode(curlGet('http://api.mixcloud.com/'.$my_podcast .'/'));
$itunes_image = $user_info->pictures->large;
$my_description = stripslashes($user_info->biog);
$updated = date(DATE_RSS,strtotime($user_info->updated_time));
$my_title = $user_info->name;
$my_link = $user_info->url;
/* write out the outer shell, channel, globals */
$updated= date("D, d M Y H:i:s T",strtotime("now"));
$output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\"
xmlns:atom=\"http://www.w3.org/2005/Atom\">
<channel>
<title><![CDATA[$my_title]]></title>
<link>$my_link</link>
<description><![CDATA[$my_description]]></description>
<image>
<url>$itunes_image</url>
<link>$my_link</link>
<description><![CDATA[$my_title]]></description>
<title><![CDATA[$my_title]]></title>
</image>
<language>$language</language>
<lastBuildDate>$updated</lastBuildDate>
<pubDate>$updated</pubDate>
<itunes:explicit>no</itunes:explicit>
<atom:link href=\"$my_feed_url\" rel=\"self\" type=\"application/rss+xml\" />
";
$nextURL = null;
do {
/* First get the info page for this playlist */
$url = $nextURL ? $nextURL : $my_podcast;
$my_podcast_page = file_get_contents('http://www.mixcloud.com/'.$url);
$my_podcast_page = mb_convert_encoding($my_podcast_page, 'HTML-ENTITIES', "UTF-8");
$doc = new DOMDocument();
/* hide warnings - html docs likely won't parse correctly */
libxml_use_internal_errors(true);
$doc->loadHTML($my_podcast_page);
$xpath = new DOMXpath($doc);
if ($xpath->query('//div[@class="infinitescroll-end"]')->length == 0) {
break;
}
$nextURL = $xpath->query('//div[@class="infinitescroll-end"]')->item(0)->getAttribute("m-next-page-url");
$episodes = $xpath->query('//span[@class="play-button "]');
//echo '<p>episodes has '. $episodes->length .'</p>';
if($episodes->length > 0) {
//echo '<p>List of episodes:</p><ol>';
foreach ($episodes as $episode) {
//$episode_image = $xpath->query('.//div[@class="card-cloudcast-image"]/a/img',$container);
//$large_photo = 'http:' . $episode_image->item(0)->getAttribute("src");
$episode_info = $xpath->query('//span[@class="play-button "]');
//if ($episode_info->length == 0) { //episodes that are disabled have no title
// continue;
//}
$e_title = $episode->getAttribute("m-title");
$e_url = 'http://www.mixcloud.com'. $episode->getAttribute("m-url");
$e_description = json_decode(curlGet('http://api.mixcloud.com'.$episode->getAttribute("m-url")))->description;
$e_preview = $episode->getAttribute("m-preview");
$length = strpos($e_preview, "preview");
$e_server = substr($e_preview,0,$length - 1);
$e_server = str_replace("audiocdn", "stream", $e_server);
// todo - should not just be 39 magic number, but where 'preview/' is in url
$e_identifier = substr($e_preview,$length + 9);
$e_identifier = rtrim($e_identifier,".mp3");
$e_download = $e_server . '/c/m4a/64/'. $e_identifier .'.m4a';
$e_original = $e_server . '/c/originals/' . $e_identifier . '.mp3';
$item_size = get_Size($e_download);
/* if $item_size is 168 this means not found */
if($item_size > 200) {
$episode_update = $xpath->query('.//div[@class="card-stats cf"]/span[@class="card-date"]/time',$container);
if($episode_update) {
$pubDate = strtotime($episode_update->item(0)->nodeValue);
} else {
$pubDate = "false";
}
$output .= "<item>
<pubDate>". date(DATE_RSS,$pubDate) ."</pubDate>
<title><![CDATA[$e_title]]></title>
<link>$e_url</link>
<description><![CDATA[$e_description]]></description>
<itunes:image href=\"$large_photo\" />
<enclosure url=\"$e_download\" length=\"$item_size\" type=\"audio/mp4\" />
<guid isPermaLink=\"true\">$e_url</guid>
</item>
";
}
}
}
} while ($nextURL);
/* seems like we're getting the closing footer too early */
sleep(2);
/* and output the closing footer */
$output .= "
</channel>
</rss>";
header("Content-Type: application/rss+xml; charset=UTF-8");
echo $output;
/*
Create a xml file containing the podcast feed
file_put_contents($my_podcast.".xml", $output);
header("Location: $my_podcast.".xml");
*/
?>