Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions webos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ This has not been tried with Sozo, and Sozo is not in the Homebrew Channel repos

## Sources

The backend lists 42 ordinary sources. The app allows nine (`js/lib/providers.js`), and shows one only if
The backend lists 42 ordinary sources. The app allows 16 (`js/lib/providers.js`), and shows one only if
the live API still offers it. This is a snapshot from November 2026, and the catalogue changes often.

Results are from one live run in desktop Chrome, with one title per source:
Expand All @@ -101,6 +101,34 @@ Results are from one live run in desktop Chrome, with one title per source:
| vidapi | Films and series | English | **Did not play.** Its segment host sends no CORS header, so hls.js cannot read it. The chooser appears. |
| sportstv | Live | Many | **Did not play**, cause not checked. The chooser appears. It also has a plain-HTTP host and one HEVC channel. |

Seven more play on webOS only, through the relay with the headers the API declares (see below). Most of
their hosts answer 403 without them, and a browser `<video>` cannot send a Referer or Origin of its choice.
All seven played, seeked and exited on an LG webOS 10.3 TV in November 2026:

| Source | Type | Language | Through the relay |
| --- | --- | --- | --- |
| anikage | Anime | English | HLS: playlist, variant and segment. Needs Referer and Origin `anikage.cc`. |
| rareanimes | Anime | Hindi | HLS: playlist, variant and segment. Needs the declared User-Agent. |
| tioanime | Anime | Spanish | mp4 byte ranges. Needs the declared Referer. |
| animeav1 | Anime | Spanish | mp4 byte ranges, needs the declared Referer. The mp4 is AV1, so older TVs fall to the next source. |
| yummyanime | Anime | Russian | HLS: playlist and segment. 10 of 10 titles resolved in 1 to 2 s. |
| uhdmovies | Films | Many | mkv byte ranges: h264 or HEVC with EAC3 audio. |
| cinestream | Films | Many | mkv byte ranges, often labelled mp4: h264 or HEVC 10-bit with EAC3 audio. |

uhdmovies and cinestream are marked `mkv: true`, so the app accepts Matroska from them and plays it as a
file through the relay, which names it `video/x-matroska`. The TV's own media pipeline decodes it. Other
providers still reject mkv.

Many of these files carry several audio tracks, Hindi first. The player enables the viewer's last chosen
language, then the UI language, then English, over the file's default, and the Audio panel saves a new choice.

Their subtitles are inside the file. The TV does not expose them as `textTracks`, and its media service sends
the track list only to the web engine. So the relay reads the Matroska header (`/t`, the first 512 KB, or
the Tracks element its SeekHead points to) and lists the text subtitles. Picking one calls `selectTrack` and
`setSubtitleEnable` on `com.webos.media`, both open to apps, and the TV draws the subtitles itself. Image
subtitles (PGS, VobSub) are left out, as the TV does not number them either. Embedded subtitles start off,
and a chosen language is remembered, with a full track preferred over a forced one.

A TV takes a different path for HLS: it tries the platform's native player first, which needs no CORS, and
uses hls.js only as a fallback where the source allows it. vidapi's segments are named `.html` and sent as
`text/html`. On an LG webOS 10.3 TV the native player rejects them at once (`MEDIA_ELEMENT_ERROR: Format
Expand All @@ -122,19 +150,26 @@ On an LG webOS 10.3 TV a vidapi film started in 1.7 s at 1920x800 this way, and
plain hls.js starts on the lowest level. If the service is missing or down, the URL is left as it is,
the native player fails, and the ladder falls back to hls.js. Off webOS nothing calls the service.

### Why the other 33 are left out
For a provider also marked `relayHeaders: true`, the app adds `&h=<JSON>` with the headers the API declares
for that source, and the relay sends them upstream. They are also carried on every playlist URI it rewrites.
Only `User-Agent`, `Referer`, `Origin`, `Accept` and `Accept-Language` pass, each printable and at most 1024
characters. Anything else, such as `Cookie` or `Authorization`, still rejects the source in the app and is
dropped by the relay. mp4 sources from these providers go through the relay too. They never use hls.js,
which cannot send those headers. Off webOS they fail and the chooser appears.

### Why the other 26 are left out

| Reason | Sources |
| --- | --- |
| 18+ titles in their results | thenkiri, internetarchive, peertube, wikimedia, musictv |
| Need a Referer, User-Agent or header set a TV `<video>` cannot send | anikai, anikoto, hianimes, anikage, rareanimes, primesrc, tioanime, animeav1 |
| Headers alone are not enough: anikai answers 400, anikoto's CDN has a broken TLS chain, hianimes is iframes with WebView sniffing, primesrc links answer 403 even with the headers | anikai, anikoto, hianimes, primesrc |
| Need a signer, local proxy or device resolver | asilmedia, uzmovi, animeheaven, vsmov |
| Iframes with WebView sniffing only | multimovies |
| Run on the device, or blocked for the backend | kisskh, coflix, animehay, animedia, kkphim, phimnhua |
| mkv only or mislabelled, often with EAC3 audio | hdhub4u, fourkhdhub, uhdmovies, cinestream |
| mkv only or mislabelled, often with EAC3 audio | hdhub4u, fourkhdhub |
| `magnet:` links | nyaa, torastream |
| Video with no audio | filmzie |
| Unreliable: timeouts or most titles failing | yummyanime, animexin |
| Unreliable: timeouts or most titles failing | animexin |

Adult providers are never listed or opened, and the `X-Sozo-Adult` header is never sent.

Expand Down Expand Up @@ -179,5 +214,6 @@ on Chromium 53. Nothing here has run on Chromium 53.
- Install on the oldest TV available and check Home, Search, Detail and the exit dialog.
- Play one mp4 source and one HLS source, then seek, change source and resume.
- Try vidapi and sportstv with native HLS on webOS older than 10.3.
- Play the seven relayed sources on webOS older than 10.3, mkv especially.
- Use the Magic Remote pointer, the arrows, OK and Back, including held keys.
- Check that the screensaver stays off during playback and how `ended` behaves.
1 change: 1 addition & 0 deletions webos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<script src="js/lib/relabel.js"></script>
<script src="js/lib/playback.js"></script>
<script src="js/lib/subtitles.js"></script>
<script src="js/lib/mediatracks.js"></script>
<script src="js/lib/i18n.js"></script>
<script src="js/ui/dom.js"></script>
<script src="js/ui/nav.js"></script>
Expand Down
135 changes: 135 additions & 0 deletions webos/js/lib/mediatracks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
(function (root) {
'use strict';
var Sozo = root.Sozo || (root.Sozo = {});

var MEDIA = 'luna://com.webos.media/';
var TIMEOUT = 15000;
var THREE = { spa: 'es', ger: 'de', deu: 'de', chi: 'zh', zho: 'zh', fre: 'fr', fra: 'fr', per: 'fa', fas: 'fa', dut: 'nl', nld: 'nl', gre: 'el', ell: 'el', cze: 'cs', ces: 'cs', rum: 'ro', ron: 'ro', slo: 'sk', slk: 'sk', ice: 'is', isl: 'is', nno: 'nn', nob: 'nb', bul: 'bg', est: 'et', swe: 'sv', dan: 'da', pol: 'pl', ukr: 'uk', hrv: 'hr', lit: 'lt', lav: 'lv', slv: 'sl', srp: 'sr', heb: 'he', ind: 'id', may: 'ms', msa: 'ms', vie: 'vi', kor: 'ko', mal: 'ml', kan: 'kn', ben: 'bn', mar: 'mr', urd: 'ur' };
var NAMES = { en: 'English', hi: 'Hindi', es: 'Spanish', fr: 'French', de: 'German', pt: 'Portuguese', ru: 'Russian', uz: 'Uzbek', ta: 'Tamil', te: 'Telugu', ar: 'Arabic', ja: 'Japanese', zh: 'Chinese', it: 'Italian', ko: 'Korean', tr: 'Turkish', pl: 'Polish', nl: 'Dutch', sv: 'Swedish', da: 'Danish', fi: 'Finnish', nb: 'Norwegian', nn: 'Norwegian', cs: 'Czech', el: 'Greek', hu: 'Hungarian', ro: 'Romanian', uk: 'Ukrainian', th: 'Thai', vi: 'Vietnamese', id: 'Indonesian', ms: 'Malay', he: 'Hebrew', fa: 'Persian', bg: 'Bulgarian', hr: 'Croatian', sk: 'Slovak', sl: 'Slovenian', lt: 'Lithuanian', lv: 'Latvian', et: 'Estonian', is: 'Icelandic', sr: 'Serbian', ml: 'Malayalam', kn: 'Kannada', bn: 'Bengali', mr: 'Marathi', ur: 'Urdu' };

// Two-letter language code from "en", "eng", "en-US" or "hin"; empty when unknown.
function langCode(v) {
var s = typeof v === 'string' ? v.toLowerCase().split(/[-_]/)[0] : '';
if (!/^[a-z]{2,3}$/.test(s)) return '';
return THREE[s] || s.slice(0, 2);
}

// Index of the audio track to enable: saved language, then UI language, then English; -1 to leave it.
function pickAudio(langs, saved, ui) {
var wants = [langCode(saved), langCode(ui), 'en'];
for (var w = 0; w < wants.length; w++) {
if (!wants[w]) continue;
for (var i = 0; i < langs.length; i++) if (langCode(langs[i]) === wants[w]) return i;
}
return -1;
}

function clean(v) {
return typeof v === 'string' ? v.replace(/[\u0000-\u001f<>]/g, '').replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '').slice(0, 60) : '';
}

// Subtitle choices from the relay's track list; the index is what the TV's selectTrack expects.
function subtitleChoices(list) {
var src = Array.isArray(list) ? list : [];
var out = [];
var seen = {};
for (var i = 0; i < src.length; i++) {
var t = src[i];
if (!t || typeof t !== 'object' || typeof t.index !== 'number' || t.index < 0 || t.index % 1) continue;
var code = langCode(t.language);
var lang = NAMES[code] || (code ? code.toUpperCase() : '');
var name = clean(t.name);
var label = !name ? lang : !lang || name.toLowerCase().indexOf(lang.toLowerCase()) === 0 ? name : lang + ' · ' + name;
if (!label) label = 'Track ' + (t.index + 1);
seen[label] = (seen[label] || 0) + 1;
if (seen[label] > 1) label += ' (' + seen[label] + ')';
out.push({ index: t.index, label: label, base: 'embedded:' + (code || 'und'), forced: t.forced === true, embedded: true });
}
return out;
}

// The remembered embedded language, preferring a full track over a forced one; null when none matches.
function pickSubtitle(choices, remembered) {
var hit = null;
for (var i = 0; i < choices.length; i++) {
if (choices[i].base !== remembered) continue;
if (!choices[i].forced) return choices[i];
if (!hit) hit = choices[i];
}
return hit;
}

// webOS only: subtitles inside a Matroska file are listed by the relay and drawn by the TV's media pipeline.
function create(options) {
var o = options || {};
var Bridge = o.Bridge || root.PalmServiceBridge;
var newXhr = o.xhr || function () { return new root.XMLHttpRequest(); };
var req = null;
var mediaId = null;

function call(method, params) {
if (typeof Bridge !== 'function') return;
try {
var b = new Bridge();
b.onservicecallback = function () {};
b.call(MEDIA + method, JSON.stringify(params));
} catch (e) { return; }
}

function stop() {
if (req) {
var x = req;
req = null;
x.onload = null;
x.onerror = null;
x.ontimeout = null;
try { x.abort(); } catch (e) { mediaId = null; }
}
mediaId = null;
}

// cb(choices) once, with [] on any failure.
function load(id, tracksUrl, cb) {
stop();
if (!o.isWebOS || typeof id !== 'string' || !id || !tracksUrl) return;
mediaId = id;
var x = newXhr();
req = x;
function end(list) {
if (req !== x) return;
req = null;
cb(subtitleChoices(list));
}
x.onload = function () {
var body = null;
try { body = x.status === 200 ? JSON.parse(x.responseText) : null; } catch (e) { body = null; }
end(body && body.subtitles);
};
x.onerror = function () { end([]); };
x.ontimeout = function () { end([]); };
try {
x.open('GET', tracksUrl, true);
x.timeout = TIMEOUT;
x.send();
} catch (e) {
end([]);
}
}

return {
load: load,
stop: stop,
// index null turns the pipeline's subtitles off.
selectText: function (index) {
if (!mediaId) return;
if (index === null) { call('setSubtitleEnable', { mediaId: mediaId, enable: false }); return; }
call('selectTrack', { mediaId: mediaId, type: 'text', index: index });
call('setSubtitleEnable', { mediaId: mediaId, enable: true });
}
};
}

var api = { create: create, langCode: langCode, pickAudio: pickAudio, subtitleChoices: subtitleChoices, pickSubtitle: pickSubtitle };
Sozo.MediaTracks = api;
if (typeof module !== 'undefined' && module.exports) module.exports = api;
}(typeof window !== 'undefined' ? window : global));
28 changes: 23 additions & 5 deletions webos/js/lib/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
var MEDIA_EXT = { m3u8: 1, mp4: 1, m4v: 1, mov: 1 };
var SOURCE_DIRECTIVES = ['useLocalProxy', 'localProxy', 'requestTransform', 'signer', 'useWebViewSniff', 'drm', 'audioTracks'];
var ENVELOPE_DIRECTIVES = ['signer', 'useWebViewSniff', 'drm'];
// Headers the webOS relay can send for a provider marked relayHeaders; service/proxy.js enforces the same list.
var RELAY_HEADERS = { 'user-agent': 1, referer: 1, origin: 1, accept: 1, 'accept-language': 1 };

function text(v) {
if (typeof v === 'number' && isFinite(v)) return String(v);
Expand Down Expand Up @@ -62,17 +64,19 @@
if (Sozo.Model.isPrivateHost(parsed.host)) return 'private-host';
var type = (text(raw.type) || text(envelope.type)).toLowerCase();
var ext = extension(parsed.path);
if (BAD_TYPES[type]) return 'type';
if (ext === 'mpd' || ext === 'html' || ext === 'htm' || ext === 'mkv') return 'path';
var mkvOk = provider.mkv === true;
if (BAD_TYPES[type] && !(mkvOk && type === 'mkv')) return 'type';
if (ext === 'mpd' || ext === 'html' || ext === 'htm' || (ext === 'mkv' && !mkvOk)) return 'path';
if (parsed.path.indexOf('/embed/') >= 0 || parsed.path.indexOf('/e/') === 0) return 'path';
if (hasDirective(raw, SOURCE_DIRECTIVES)) return 'directive';
if (raw.accessible === false) return 'inaccessible';
var declared = headerNames(envelope.headers, raw.headers);
for (var i = 0; i < declared.length; i++) {
if (provider.relayHeaders === true && RELAY_HEADERS[declared[i]]) continue;
if (provider.ignoreHeaders.indexOf(declared[i]) < 0) return 'header';
}
if (provider.hosts && !provider.hosts.test(parsed.host) && declared.length) return 'host';
if (!HLS_TYPES[type] && !FILE_TYPES[type] && !MEDIA_EXT[ext]) return 'not-media';
if (!HLS_TYPES[type] && !FILE_TYPES[type] && !MEDIA_EXT[ext] && !(mkvOk && (type === 'mkv' || ext === 'mkv'))) return 'not-media';
return null;
}

Expand All @@ -81,6 +85,18 @@
return !!HLS_TYPES[type] || (!!parsed && extension(parsed.path) === 'm3u8');
}

// Envelope headers, overridden per source; string values only.
function mergedHeaders(a, b) {
var out = {};
[a, b].forEach(function (headers) {
if (!headers || typeof headers !== 'object') return;
for (var k in headers) {
if (Object.prototype.hasOwnProperty.call(headers, k) && typeof headers[k] === 'string') out[k] = headers[k];
}
});
return out;
}

function candidates(envelope) {
var list = Array.isArray(envelope.videoSources) ? envelope.videoSources.slice() : [];
var seen = {};
Expand Down Expand Up @@ -120,10 +136,12 @@
var key = label || '#';
labels[key] = (labels[key] || 0) + 1;
if (labels[key] > 1 && label) label += ' (' + labels[key] + ')';
result.sources.push({
var source = {
url: url, type: type, isHls: isHls(type, url), quality: quality, label: label,
key: key + '/' + labels[key], isDefault: raw.isDefault === true, order: result.sources.length + 1
});
};
if (provider.relayHeaders === true) source.headers = mergedHeaders(envelope.headers, raw.headers);
result.sources.push(source);
}
return result;
}
Expand Down
18 changes: 17 additions & 1 deletion webos/js/lib/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,23 @@
{ id: 'livetvindia', kind: 'live', search: true, viewAll: false, related: false,
hosts: null, ignoreHeaders: ['user-agent'], hlsjs: true },
{ id: 'sportstv', kind: 'live', search: true, viewAll: false, related: false,
hosts: null, ignoreHeaders: ['user-agent'], hlsjs: true }
hosts: null, ignoreHeaders: ['user-agent'], hlsjs: true },
// relayHeaders: their hosts refuse requests without the API's Referer/Origin/User-Agent, so webOS plays them via the relay.
{ id: 'anikage', kind: 'vod', search: true, viewAll: true, related: true,
hosts: null, ignoreHeaders: [], hlsjs: false, relabel: true, relayHeaders: true },
{ id: 'rareanimes', kind: 'vod', search: true, viewAll: true, related: true,
hosts: null, ignoreHeaders: [], hlsjs: false, relabel: true, relayHeaders: true },
{ id: 'tioanime', kind: 'vod', search: true, viewAll: true, related: true,
hosts: null, ignoreHeaders: [], hlsjs: false, relabel: true, relayHeaders: true },
{ id: 'animeav1', kind: 'vod', search: true, viewAll: true, related: true,
hosts: null, ignoreHeaders: [], hlsjs: false, relabel: true, relayHeaders: true },
{ id: 'yummyanime', kind: 'vod', search: true, viewAll: true, related: true,
hosts: null, ignoreHeaders: [], hlsjs: false, relabel: true, relayHeaders: true },
// mkv: direct Matroska files (h264/HEVC + EAC3) that only the TV's own media pipeline can play.
{ id: 'uhdmovies', kind: 'vod', search: true, viewAll: true, related: true,
hosts: null, ignoreHeaders: [], hlsjs: false, relabel: true, relayHeaders: true, mkv: true },
{ id: 'cinestream', kind: 'vod', search: true, viewAll: true, related: true,
hosts: null, ignoreHeaders: [], hlsjs: false, relabel: true, relayHeaders: true, mkv: true }
];

var DEFAULT_ID = 'uzbeklar';
Expand Down
13 changes: 12 additions & 1 deletion webos/js/lib/relabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@
return {
start: start,
ready: function () { return base !== null; },
wrap: function (u) { return base === null ? u : base + encodeURIComponent(u); }
// URL of the relay's track list for a Matroska file, or null when the relay is not up.
tracksUrl: function (u, headers) {
if (base === null) return null;
var h = headers && typeof headers === 'object' && Object.keys(headers).length ? '&h=' + encodeURIComponent(JSON.stringify(headers)) : '';
return base.replace(/\/p\?u=$/, '/t?u=') + encodeURIComponent(u) + h;
},
// headers: optional {name: value} the relay sends upstream; it keeps only names it allows.
wrap: function (u, headers) {
if (base === null) return u;
var h = headers && typeof headers === 'object' && Object.keys(headers).length ? '&h=' + encodeURIComponent(JSON.stringify(headers)) : '';
return base + encodeURIComponent(u) + h;
}
};
}

Expand Down
Loading
Loading