-
Notifications
You must be signed in to change notification settings - Fork 0
/
iplayer.php
89 lines (84 loc) · 2.07 KB
/
iplayer.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
<?php
if(!defined('GET_IPLAYER_PATH')) define('GET_IPLAYER_PATH', '/usr/bin/get_iplayer');
if(!defined('FLVSTREAMER_PATH')) define('FLVSTREAMER_PATH', '/usr/bin/flvstreamer');
uses('execute');
/* iPlayer URLs take the form:
*
* iplayer://episode/<pid>.{mov|flv|rdf|jpg}
*/
class iPlayer
{
public $context;
public function recvFile($remote, $local)
{
if(!($info = parse_url($remote)))
{
return;
}
if(isset($info['path']))
{
$info = array_merge($info, pathinfo($info['path']));
}
if(!isset($info['filename']))
{
trigger_error('iPlayer: No PID specified', E_USER_WARNING);
return false;
}
if(!isset($info['extension']))
{
trigger_error('iPlayer: No file type (extension) specified', E_USER_WARNING);
return false;
}
if(is_dir($local))
{
$localdir = $local;
$local .= '/' . $info['basename'];
}
else
{
$localdir = dirname($local);
}
if($info['extension'] == 'jpg')
{
return copy('http://www.bbc.co.uk/iplayer/images/episode/' . $info['filename'] . '_832_468.jpg', $local);
}
if($info['extension'] == 'rdf')
{
return copy('http://www.bbc.co.uk/programmes/' . $info['filename'] . '.rdf', $local);
}
if($info['extension'] == 'flv')
{
$tmpfile = $localdir . '/.iplayer-tmp-' . $info['filename'] . '.flv';
if(!file_exists($tmpfile))
{
$args = array();
$args[] = GET_IPLAYER_PATH;
$args[] = '--flvstreamer';
$args[] = FLVSTREAMER_PATH;
$args[] = '--modes=flashhd1,flashhd2,flashvhigh,flashhigh';
$args[] = '--quiet';
$args[] = '--nocopyright';
$args[] = '--nopurge';
$args[] = '--file-prefix=.iplayer-tmp-' . $info['filename'];
$args[] = '--pid=' . $info['filename'];
$args[] = '--force';
$args[] = '--raw';
$args[] = '-o';
$args[] = $localdir;
$result = execute(GET_IPLAYER_PATH, $args, false);
if(!file_exists($tmpfile))
{
trigger_error('get_iplayer failed to download ' . $info['basename'], E_USER_NOTICE);
return false;
}
}
if(!rename($tmpfile, $local))
{
return false;
}
return true;
}
print_r($info);
die();
}
}