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
|
<?php
// Grab the programme ID with GET, or with POST, or present a URL form
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else if (isset($_POST['url'])) {
$idpos = strpos($_POST['url'], "/episode/") + 9;
$idlen = strpos($_POST['url'], "/", $idpos) - $idpos;
$id = substr($_POST['url'], $idpos, $idlen);
} else {
?>
<form action="./" method="post">
<p>Enter a non-live iPlayer URL:<br>
<input name="url" id="url" size="40" type="text">
<input type="submit">
</p>
<?php
exit();
}
// Grab iPlayer HTML page
$html = file_get_contents("http://www.bbc.co.uk/iplayer/episode/$id/");
// Extract the VPID from the page
$vpidpos = strpos($html, 'vpid":"') + 7;
$vpidlen = strpos($html, '"', $vpidpos) - $vpidpos;
$vpid = substr($html, $vpidpos, $vpidlen);
// Grab the JSON which appears to be within some JavaScript
$notjson = file_get_contents("http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/vpid/$vpid/format/json/mediaset/apple-ipad-hls/jsfunc/JS_callbacks39");
// Extract the actual JSON inside the JavaScript
$jsonpos = strpos($notjson, '{');
$json = json_decode(substr($notjson, $jsonpos, strlen($notjson) - $jsonpos - 3), true);
// Find an akamai_hls_open stream and HTTP redirect to it
foreach ($json['media']['0']['connection'] as $connection) {
if ($connection['supplier'] == "akamai_hls_open") {
header("Location: " . $connection['href']);
exit();
}
}
?>
|