diff options
| author | jade (winter) | 2026-07-20 13:35:01 +0100 |
|---|---|---|
| committer | jade (winter) | 2026-07-20 13:35:01 +0100 |
| commit | d5ea0f332bf8e5f0745e2c0e592ee895423a70ad (patch) | |
| tree | 1649ba6a70b64623b5b1692359b4a70cb89970f1 /lib/mediaselector.php | |
| parent | 5f301e85b24f3a219c3020a8e24113c31a2a1058 (diff) | |
add live playback support
Diffstat (limited to 'lib/mediaselector.php')
| -rw-r--r-- | lib/mediaselector.php | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/mediaselector.php b/lib/mediaselector.php index df19c8d..2adaf71 100644 --- a/lib/mediaselector.php +++ b/lib/mediaselector.php @@ -1,27 +1,39 @@ <?php +require_once __DIR__ . '/sounds-auth.php'; + const MEDIASELECTOR_BASE = 'https://open.live.bbc.co.uk/mediaselector/6/select'; -function mediaselector_lookup(array $options): stdClass { +function mediaselector_lookup(array $options, ?string $token = null): stdClass { // ['version' => '3.0', 'cvid' => 'urn:bbc:pips:pid:...'] $url = MEDIASELECTOR_BASE; $options['format'] = 'json'; foreach ($options as $k => $v) { $url .= "/$k/$v"; } - return json_decode(file_get_contents($url)); + $ctx = stream_context_get_default(); + if (isset($token)) { + stream_context_set_option($ctx, 'http', + 'header', "Authorization: Bearer $token"); + } + return json_decode(file_get_contents($url, context: $ctx)); } -function mediaselector_findHls(string $vpid): ?string { +function mediaselector_findHls(string $vpid, ?string $token = null): ?string { $resp = mediaselector_lookup([ 'version' => '3.0', 'proto' => 'https', 'transferformat' => 'hls', 'mediaset' => 'pc', 'cvid' => "urn:bbc:pips:pid:$vpid", - ]); + ], $token); if (isset($resp->result) && $resp->result == 'selectionunavailable') { return null; } return $resp->media[0]->connection[0]->href; } + +function mediaselector_findLiveHls(string $service): ?string { + $jwt = sounds_getLiveBearerToken($service); + return mediaselector_findHls($service, $jwt); +} |
