summaryrefslogtreecommitdiff
path: root/lib/mediaselector.php
blob: df19c8d8e1f2e4d2132ba1e542655a4c162bfdee (plain)
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
<?php

const MEDIASELECTOR_BASE = 'https://open.live.bbc.co.uk/mediaselector/6/select';

function mediaselector_lookup(array $options): 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));
}

function mediaselector_findHls(string $vpid): ?string {
    $resp = mediaselector_lookup([
        'version' => '3.0',
        'proto' => 'https',
        'transferformat' => 'hls',
        'mediaset' => 'pc',
        'cvid' => "urn:bbc:pips:pid:$vpid",
    ]);
    if (isset($resp->result) && $resp->result == 'selectionunavailable') {
        return null;
    }
    return $resp->media[0]->connection[0]->href;
}