From 5f301e85b24f3a219c3020a8e24113c31a2a1058 Mon Sep 17 00:00:00 2001
From: jade (winter)
Date: Sun, 19 Jul 2026 17:51:11 +0100
Subject: fix so much stuff + add hls player
---
lib/bbcnext.php | 183 ++++++++++++++++++++++++++------------------------
lib/mediaselector.php | 27 ++++++++
lib/rms.php | 2 +-
3 files changed, 123 insertions(+), 89 deletions(-)
create mode 100644 lib/mediaselector.php
(limited to 'lib')
diff --git a/lib/bbcnext.php b/lib/bbcnext.php
index 988d248..ed58a4f 100644
--- a/lib/bbcnext.php
+++ b/lib/bbcnext.php
@@ -1,109 +1,116 @@
data);
+ next_renderExperience(rms_fetch($path)->data);
}
function next_renderExperience(array $modules) {
- foreach ($modules as $m) {
- next_renderModule($m);
- }
+ foreach ($modules as $m) {
+ next_renderModule($m);
+ }
}
function next_renderModule(stdClass $module) {
- $type = strtr($module->type, '_', '-');
- $titleTag = $type == 'inline-header-module' ? 'h1' : 'h2';
- echo "<$type id=\"$module->id\" module-style=\"$module->style\">";
- echo "<$titleTag>"
- . htmlspecialchars($module->title ?? '[no title]')
- . "$titleTag>";
- if (isset($module->description)) {
- echo ''
- . htmlspecialchars($module->description)
- . '';
- }
- echo '';
- if (!is_array($module->data)) {
- next_renderItem($module->data);
- } else {
- foreach ($module->data as $item) {
- next_renderItem($item);
- }
- }
- echo "$type>";
+ $type = strtr($module->type, '_', '-');
+ $titleTag = $type == 'inline-header-module' ? 'h1' : 'h2';
+ echo "<$type id=\"$module->id\" module-style=\"$module->style\">";
+ echo "<$titleTag>"
+ . htmlspecialchars($module->title ?? '[no title]')
+ . "$titleTag>";
+ if (isset($module->description)) {
+ echo ''
+ . htmlspecialchars($module->description)
+ . '';
+ }
+ echo '';
+ if (!is_array($module->data)) {
+ next_renderItem($module->data);
+ } else {
+ foreach ($module->data as $item) {
+ next_renderItem($item);
+ }
+ }
+ echo "";
+ if ($module->id == 'aod_play_area') {
+ $url = mediaselector_findHls($module->data[0]->id);
+ echo '';
+ echo '';
+ }
+ echo "$type>";
}
function next_renderItem(stdClass $item) {
- $type = strtr($item->type, '_', '-');
- $primaryTag = $type == 'segment-item' ? 'primary-title' : 'h3';
- echo "<$type id=\"$item->id\">";
- echo '';
- echo "<$primaryTag>"
- . htmlspecialchars($item->titles?->primary ?? '[no primary]')
- . "$primaryTag>";
- if (isset($item->network)) {
- echo ''
- . htmlspecialchars($item->network->short_title)
- . '';
- }
- echo '';
- if (isset($item->titles->secondary)) {
- echo ''
- . htmlspecialchars($item->titles->secondary)
- . '';
- }
- if (isset($item->titles->tertiary)) {
- echo ''
- . htmlspecialchars($item->titles->tertiary)
- . '';
- }
- echo '';
- if (isset($item->synopses?->short, $item->synopses?->medium)) {
- echo ''
- . htmlspecialchars($item->synopses->short)
- . '
'
- . htmlspecialchars($item->synopses->long ?? $item->synopses->medium)
- . ' ';
- } elseif (isset($item->synopses?->short)) {
- echo '' . htmlspecialchars($item->synopses->short)
- . '';
- }
+ $type = strtr($item->type, '_', '-');
+ $primaryTag = $type == 'segment-item' ? 'primary-title' : 'h3';
+ echo "<$type id=\"$item->id\">";
+ echo '';
+ echo "<$primaryTag>"
+ . htmlspecialchars($item->titles?->primary ?? '[no primary]')
+ . "$primaryTag>";
+ if (isset($item->network)) {
+ echo ''
+ . htmlspecialchars($item->network->short_title)
+ . '';
+ }
+ echo '';
+ if (isset($item->titles->secondary)) {
+ echo ''
+ . htmlspecialchars($item->titles->secondary)
+ . '';
+ }
+ if (isset($item->titles->tertiary)) {
+ echo ''
+ . htmlspecialchars($item->titles->tertiary)
+ . '';
+ }
+ echo '';
+ if (isset($item->synopses?->short, $item->synopses?->medium)) {
+ echo ''
+ . htmlspecialchars($item->synopses->short)
+ . '
'
+ . htmlspecialchars($item->synopses->long ?? $item->synopses->medium)
+ . ' ';
+ } elseif (isset($item->synopses?->short)) {
+ echo '' . htmlspecialchars($item->synopses->short)
+ . '';
+ }
- if (isset($item->item)) {
- next_renderItem($item->item);
- }
+ if (isset($item->item)) {
+ next_renderItem($item->item);
+ }
- if (isset($item->offset)) {
- echo ''
- . gmdate('H:i:s', $item->offset->start)
- . '';
- echo ''
- . gmdate('H:i:s', $item->offset->end)
- . '';
- }
+ if (isset($item->offset)) {
+ echo ''
+ . gmdate('H:i:s', $item->offset->start)
+ . '';
+ echo ''
+ . gmdate('H:i:s', $item->offset->end)
+ . '';
+ }
- if ($type == 'container-item') {
- $href = '?path=' . RMS_SOUNDS_CONTAINER . '/' . $item->urn;
- echo "View";
- } elseif ($type == 'playable-item') {
- $pid = explode(':', $item->urn)[4];
- $href = '?path=' . RMS_SOUNDS_PLAYABLE . '/' . $pid;
- echo "Listen";
- }
+ if ($type == 'container-item') {
+ $href = '?path=' . RMS_SOUNDS_CONTAINER . '/' . $item->urn;
+ echo "View";
+ } elseif ($type == 'playable-item') {
+ $pid = explode(':', $item->urn)[4];
+ $href = '?path=' . RMS_SOUNDS_PLAYABLE . '/' . $pid;
+ echo "Listen";
+ }
- foreach ($item->uris ?? [] as $uri) {
- if ($uri->type != 'link') continue;
- echo ''
- . htmlspecialchars($uri->label) . '';
- }
+ foreach ($item->uris ?? [] as $uri) {
+ if ($uri->type != 'link') continue;
+ echo ''
+ . htmlspecialchars($uri->label) . '';
+ }
- if (isset($item->download) && $item->download->type == 'non_drm') {
- $variant = $item->download->quality_variants->high;
- echo ''
- . "Download ($variant->label)";
- }
+ if (isset($item->download) && $item->download->type == 'non_drm') {
+ $variant = $item->download->quality_variants->high;
+ echo ''
+ . "Download ($variant->label)";
+ }
- echo "$type>";
+ echo "$type>";
}
diff --git a/lib/mediaselector.php b/lib/mediaselector.php
new file mode 100644
index 0000000..df19c8d
--- /dev/null
+++ b/lib/mediaselector.php
@@ -0,0 +1,27 @@
+ '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;
+}
diff --git a/lib/rms.php b/lib/rms.php
index 1e76d53..8b92e49 100644
--- a/lib/rms.php
+++ b/lib/rms.php
@@ -6,5 +6,5 @@ const RMS_SOUNDS_CONTAINER = '/experience/inline/container';
const RMS_SOUNDS_PLAYABLE = '/experience/inline/play';
function rms_fetch(string $path): stdClass {
- return json_decode(file_get_contents(RMS_API_BASE . $path));
+ return json_decode(file_get_contents(RMS_API_BASE . $path));
}
--
cgit v1.3