Repository navigation
Expand file tree
/
Copy pathplaylist.php
More file actions
94 lines (83 loc) · 2.94 KB
/
Copy pathplaylist.php
File metadata and controls
94 lines (83 loc) · 2.94 KB
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
<?php
/*
* Playlist generator
*
* @version 2015-08-30
* @author François LASSERRE <choiz@me.com>
* @license GNU GPL {@link http://www.gnu.org/licenses/gpl.html}
*/
class Playlist
{
private $available_format = array(
'asx' => 'audio/x-ms-asf',
'm3u' => 'audio/x-mpegurl',
'pls' => 'audio/x-scpls',
'qtl' => 'application/x-quicktimeplayer',
'wax' => 'audio/x-ms-wax'
);
private $station;
private $extension;
public function __construct(Station $station, $extension = 'm3u')
{
$this->station = $station;
$this->extension = $extension;
if (!empty($extension)) {
$extension = strtolower($extension);
}
if (in_array($extension, $this->available_format)) {
$this->extension = $extension;
}
}
public function getStationName()
{
return $this->station->getName();
}
public function getStationDescription()
{
return $this->station->getDescription();
}
public function getStationUrl()
{
return $this->station->getUrl();
}
public function getStationServers()
{
return $this->station->getServers();
}
public function generate()
{
if (!headers_sent()) {
header('Content-Type: '.$this->available_format[$this->extension]);
header('Content-Disposition: attachment; filename='.$this->getStationName().$this->extension);
}
if ($this->extension === 'asx') {
echo '<ASX Version="3.0">'."\n".'<PARAM name="HTMLView" value="'.$this->stationGetUrl().'" />'."\n";
foreach($this->getStationServers() as $url) {
echo '<ENTRY>'."\n".'<REF HREF="http://'.$url.'" />'."\n".'</ENTRY>'."\n";
}
echo '<Title>'.$this->getStationDescription().'</Title>'."\n".'</ASX>';
} else if ($this->extension === 'm3u') {
echo '#EXTM3U';
foreach($this->getStationServers() as $url) {
echo "\n".'#EXTINF:-1, '.$this->getStationDescription()."\n".$url;
}
} else if ($this->extension === 'pls') {
echo '[playlist]'."\n".'NumberOfEntries='.count($this->stationGetUrl())."\n";
$i=0;
foreach($this->getStationServers() as $url) {
$i++;
echo "\n".'File'.$i.'=http://'.$url."\n".'Title'.$i.'='.$this->getStationDescription()."\n".'Length'.$i.'=-1'."\n";
}
echo "\n".'Version=2';
} else if ($this->extension === 'qtl') {
echo '<?xml version="1.0"?>'."\n".'<?quicktime type="application/x-quicktime-media-link"?>';
foreach($this->getStationServers() as $url) {
echo "\n".'<embed src="icy://'.$url.'" autoplay="true" />';
}
} else if ($this->extension === 'wax') {
foreach($this->getStationServers() as $url) {
echo $url."\n";
}
}
}
}