diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2014-12-14 19:50:39 +0000 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2014-12-14 19:50:39 +0000 |
commit | e1d4df7d36dd9cd11186cde6652485137fe5ace2 (patch) | |
tree | 60b58f4e886ee1604968a854bf3a51bf138b0ea1 |
First commit
-rw-r--r-- | iplayer.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/iplayer.php b/iplayer.php new file mode 100644 index 0000000..951cb1c --- /dev/null +++ b/iplayer.php @@ -0,0 +1,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(); + } +} +?> |