Upload index.html
Browse files- index.html +360 -17
index.html
CHANGED
|
@@ -1881,6 +1881,13 @@ const I18N = {
|
|
| 1881 |
off_sub_remove_confirm: 'Ondoa manukuu "{label}"?',
|
| 1882 |
off_sub_reset: 'Rudisha',
|
| 1883 |
off_sub_delay: 'Manukuu: {s}',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1884 |
off_failed: 'Imeshindikana: {msg}',
|
| 1885 |
off_confirm_delete: 'Futa "{title}"?',
|
| 1886 |
dl_pin_prompt: 'Weka PIN kupakua {title}',
|
|
@@ -2011,6 +2018,13 @@ const I18N = {
|
|
| 2011 |
off_sub_remove_confirm: 'Remove subtitles "{label}"?',
|
| 2012 |
off_sub_reset: 'Reset',
|
| 2013 |
off_sub_delay: 'Subtitles: {s}',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2014 |
off_failed: 'Failed: {msg}',
|
| 2015 |
off_confirm_delete: 'Delete "{title}"?',
|
| 2016 |
dl_pin_prompt: 'Enter PIN to download {title}',
|
|
@@ -2143,6 +2157,13 @@ const I18N = {
|
|
| 2143 |
off_sub_remove_confirm: 'إزالة الترجمة "{label}"؟',
|
| 2144 |
off_sub_reset: 'إعادة ضبط',
|
| 2145 |
off_sub_delay: 'الترجمة: {s}',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2146 |
off_failed: 'فشل: {msg}',
|
| 2147 |
off_confirm_delete: 'حذف "{title}"؟',
|
| 2148 |
dl_pin_prompt: 'أدخل الرمز السري لتنزيل {title}',
|
|
@@ -2275,6 +2296,13 @@ const I18N = {
|
|
| 2275 |
off_sub_remove_confirm: 'Retirer les sous-titres « {label} » ?',
|
| 2276 |
off_sub_reset: 'Réinitialiser',
|
| 2277 |
off_sub_delay: 'Sous-titres : {s}',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2278 |
off_failed: 'Échec : {msg}',
|
| 2279 |
off_confirm_delete: 'Supprimer « {title} » ?',
|
| 2280 |
dl_pin_prompt: 'Saisissez le code PIN pour télécharger {title}',
|
|
@@ -4373,6 +4401,8 @@ let hls = null;
|
|
| 4373 |
let shakaPlayer = null;
|
| 4374 |
let currentBlobUrls = [];
|
| 4375 |
let offSubDelay = 0, offSubSaveT = null; // sync ya manukuu ya offline (sekunde)
|
|
|
|
|
|
|
| 4376 |
let currentPr = null;
|
| 4377 |
let currentResumeMeta = null; // {id, se, ep, title, poster} — kwa ajili ya 'Endelea Kutazama'
|
| 4378 |
|
|
@@ -4432,7 +4462,7 @@ const PC_I = {
|
|
| 4432 |
back: SEEK_ICON_BACK, fwd: SEEK_ICON_FWD,
|
| 4433 |
};
|
| 4434 |
function pcFmt(t){ if (!isFinite(t) || t < 0) t = 0; t = Math.floor(t); const h = Math.floor(t / 3600), m = Math.floor(t % 3600 / 60), s = String(t % 60).padStart(2, '0'); return h ? h + ':' + String(m).padStart(2, '0') + ':' + s : m + ':' + s; }
|
| 4435 |
-
const PC_SECS = { quality: ['qualityRow', 'Ubora (Quality)'], sub: ['subRow', 'Manukuu (Subtitles)'], sync: ['subSyncRow', '
|
| 4436 |
function pcRowChips(k){ const r = document.getElementById(PC_SECS[k][0]); return r ? [...r.querySelectorAll('.tab-chip')] : []; }
|
| 4437 |
function pcOpenSheet(wrap, keys){
|
| 4438 |
const old = wrap.querySelector('.pc-sheet'); if (old) old.remove();
|
|
@@ -4500,7 +4530,7 @@ function attachCustomControls(v){
|
|
| 4500 |
const refresh = () => {
|
| 4501 |
const qc = pcRowChips('quality'); bq.style.display = qc.length ? '' : 'none';
|
| 4502 |
if (qc.length) { const a = qc.find(c => c.classList.contains('active')); bq.textContent = a ? a.textContent : 'Auto'; }
|
| 4503 |
-
bcc.style.display = pcRowChips('sub').length ? '' : 'none';
|
| 4504 |
bg.style.display = (pcRowChips('lang').length || pcRowChips('speed').length) ? '' : 'none';
|
| 4505 |
};
|
| 4506 |
let timer = null, drag = false;
|
|
@@ -4628,7 +4658,7 @@ function stopPlayer(){
|
|
| 4628 |
langRow.style.display = 'none'; langRow.innerHTML = '';
|
| 4629 |
subRow.style.display = 'none'; subRow.innerHTML = ''; subRow.onclick = null;
|
| 4630 |
const ssr = document.getElementById('subSyncRow'); if (ssr) { ssr.style.display = 'none'; ssr.innerHTML = ''; }
|
| 4631 |
-
clearTimeout(offSubSaveT); offSubDelay = 0;
|
| 4632 |
speedRow.style.display = 'none'; speedRow.innerHTML = '';
|
| 4633 |
currentPr = null;
|
| 4634 |
currentResumeMeta = null;
|
|
@@ -6361,6 +6391,7 @@ async function saveItemOffline(item, url, filename){
|
|
| 6361 |
list.push({ id, title: item.title, sub: item.sub || '', poster: item.poster || '', thumbLabel: item.thumbLabel || '',
|
| 6362 |
filename, size, mime: 'video/mp4', addedAt: Date.now(), source: 'download' });
|
| 6363 |
setOfflineMeta(list);
|
|
|
|
| 6364 |
return { id, size };
|
| 6365 |
}
|
| 6366 |
|
|
@@ -6411,7 +6442,11 @@ async function bgMergeDone(oid, m){
|
|
| 6411 |
list.push({ id: oid, title: m.title, sub: m.sub || '', poster: m.poster || '', thumbLabel: m.thumbLabel || '',
|
| 6412 |
filename: m.filename, size: m.size, mime: 'video/mp4', addedAt: m.addedAt || Date.now(), source: 'download' });
|
| 6413 |
setOfflineMeta(list);
|
|
|
|
|
|
|
|
|
|
| 6414 |
}
|
|
|
|
| 6415 |
await bgMetaDelete(oid);
|
| 6416 |
return { id: oid, size: m.size, viaBg: true };
|
| 6417 |
}
|
|
@@ -6472,6 +6507,11 @@ async function saveItemViaBackgroundFetch(item, url, filename){
|
|
| 6472 |
const oid = offlineNewId();
|
| 6473 |
await bgMetaWrite(oid, { id: oid, state: 'pending', title: item.title, sub: item.sub || '', poster: item.poster || '',
|
| 6474 |
thumbLabel: item.thumbLabel || '', filename, addedAt: Date.now() });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6475 |
item.bgId = 'jm-' + oid; item.cancelled = false;
|
| 6476 |
item.phase = 'download'; item.dlBytes = 0; item.dlTotal = total || item.sizeBytes || 0; item.dlSpeed = 0;
|
| 6477 |
item.progressText = t('dq_saving');
|
|
@@ -6600,8 +6640,8 @@ function subGuessLang(name){
|
|
| 6600 |
return '';
|
| 6601 |
}
|
| 6602 |
// Soma faili la manukuu kama maandishi — UTF-8 kwanza, kisha UTF-16 (BOM), kisha Windows-1252
|
| 6603 |
-
async function offlineReadSubText(file){
|
| 6604 |
-
|
| 6605 |
if (u8[0] === 0xFF && u8[1] === 0xFE) return new TextDecoder('utf-16le').decode(u8);
|
| 6606 |
if (u8[0] === 0xFE && u8[1] === 0xFF) return new TextDecoder('utf-16be').decode(u8);
|
| 6607 |
try { return new TextDecoder('utf-8', { fatal: true }).decode(u8).replace(/^\uFEFF/, ''); }
|
|
@@ -6701,6 +6741,44 @@ async function offlineRemoveSub(id, k){
|
|
| 6701 |
const list = getOfflineMeta(); const m = list.find(x => x.id === id);
|
| 6702 |
if (m) { m.subs = (m.subs || []).filter(x => x.k !== k); if (m.subPick != null && m.subPick >= m.subs.length) m.subPick = null; setOfflineMeta(list); }
|
| 6703 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6704 |
// Oanisha manukuu na video kwa jina: "Movie.mp4" ↔ "Movie.en.srt". Video moja tu = manukuu yote ni yake.
|
| 6705 |
function pairSubsToVideos(videos, subs){
|
| 6706 |
const base = f => f.name.replace(/\.[^.]+$/, '').toLowerCase();
|
|
@@ -6723,7 +6801,7 @@ async function importLocalFile(file, onProgress, subFiles){
|
|
| 6723 |
if (!offlineCanSave()) { // kivinjari kisichounga mkono OPFS (mf. iOS): cheza tu kwa kikao hiki
|
| 6724 |
const subs = [];
|
| 6725 |
for (const sf of (subFiles || [])) { try { subs.push(await subFileToEntry(sf)); } catch (_) {} }
|
| 6726 |
-
playLocalVideo(URL.createObjectURL(file), title, subs);
|
| 6727 |
return 'session';
|
| 6728 |
}
|
| 6729 |
await offlineCheckQuota(file.size);
|
|
@@ -6742,6 +6820,204 @@ async function importLocalFile(file, onProgress, subFiles){
|
|
| 6742 |
return 'saved';
|
| 6743 |
}
|
| 6744 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6745 |
// ── Sync ya manukuu: sogeza muda wa cues zote (+ = yachelewe, − = yawahi) ──
|
| 6746 |
function applySubDelay(v){
|
| 6747 |
try {
|
|
@@ -6755,15 +7031,66 @@ function applySubDelay(v){
|
|
| 6755 |
}
|
| 6756 |
} catch (_) {}
|
| 6757 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6758 |
function renderSubSyncChips(v, id){
|
| 6759 |
const row = document.getElementById('subSyncRow'); if (!row) return;
|
| 6760 |
const fmt = () => (offSubDelay > 0 ? '+' : '') + offSubDelay.toFixed(1) + 's';
|
| 6761 |
-
const steps = [[-5, '−5s'], [-0.5, '−0.5s'], [0,
|
| 6762 |
const draw = () => {
|
| 6763 |
row.style.display = 'flex';
|
| 6764 |
-
row.innerHTML = steps.map(([d, lb]) => `<div class="tab-chip" data-
|
| 6765 |
-
row.querySelectorAll('.tab-chip').forEach(c => c.onclick = () => {
|
| 6766 |
-
const d =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6767 |
offSubDelay = d === 0 ? 0 : Math.round((offSubDelay + d) * 10) / 10;
|
| 6768 |
applySubDelay(v);
|
| 6769 |
if (id) { clearTimeout(offSubSaveT); offSubSaveT = setTimeout(() => offlineSetMetaField(id, { subDelay: offSubDelay }), 400); }
|
|
@@ -6773,11 +7100,27 @@ function renderSubSyncChips(v, id){
|
|
| 6773 |
};
|
| 6774 |
draw();
|
| 6775 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6776 |
|
| 6777 |
// subs: [{label, language, vtt}] — opts: { id, pick, delay } (id = movie ya maktaba ya offline)
|
| 6778 |
function playLocalVideo(url, title, subs, opts){
|
| 6779 |
opts = opts || {};
|
| 6780 |
openPlayerShell(title);
|
|
|
|
|
|
|
|
|
|
| 6781 |
currentBlobUrls.push(url); // stopMediaOnly() inaifuta URL ikifungwa
|
| 6782 |
stage.innerHTML = '<video id="vid" controls autoplay playsinline></video>';
|
| 6783 |
const v = document.getElementById('vid');
|
|
@@ -6787,7 +7130,6 @@ function playLocalVideo(url, title, subs, opts){
|
|
| 6787 |
const list = (subs || []).filter(x => x && x.vtt);
|
| 6788 |
if (list.length) {
|
| 6789 |
currentPr = { subtitles: list.map(x => ({ label: x.label, language: x.language })) };
|
| 6790 |
-
offSubDelay = Number(opts.delay) || 0;
|
| 6791 |
list.forEach((x, i) => {
|
| 6792 |
const bu = URL.createObjectURL(new Blob([x.vtt], { type: 'text/vtt' }));
|
| 6793 |
currentBlobUrls.push(bu);
|
|
@@ -6800,9 +7142,9 @@ function playLocalVideo(url, title, subs, opts){
|
|
| 6800 |
});
|
| 6801 |
}
|
| 6802 |
v.src = url;
|
|
|
|
| 6803 |
if (list.length) {
|
| 6804 |
renderSubtitleChips(v, currentPr);
|
| 6805 |
-
renderSubSyncChips(v, opts.id);
|
| 6806 |
const pick = opts.pick; // undefined/null = mara ya kwanza → washa ya kwanza; -1 = zimezimwa
|
| 6807 |
if (pick === -1) { const off = subRow.querySelector('.tab-chip[data-type="off"]'); if (off) off.click(); }
|
| 6808 |
else {
|
|
@@ -6810,11 +7152,9 @@ function playLocalVideo(url, title, subs, opts){
|
|
| 6810 |
const act = subRow.querySelector('.tab-chip.active');
|
| 6811 |
if (want && (pick != null || (act && act.dataset.type === 'off'))) want.click();
|
| 6812 |
}
|
| 6813 |
-
|
| 6814 |
-
const chip = e.target.closest('.tab-chip'); if (!chip || !opts.id) return;
|
| 6815 |
-
offlineSetMetaField(opts.id, { subPick: chip.dataset.type === 'native' ? +chip.dataset.i : -1 });
|
| 6816 |
-
};
|
| 6817 |
}
|
|
|
|
| 6818 |
v.play().catch(() => {});
|
| 6819 |
}
|
| 6820 |
async function playOfflineItem(meta){
|
|
@@ -6828,7 +7168,8 @@ async function playOfflineItem(meta){
|
|
| 6828 |
try { const sf = await (await dir.getFileHandle(cur.id + '.s' + sb.k + '.vtt')).getFile(); subs.push({ label: sb.label, language: sb.language, vtt: await sf.text() }); } catch (_) {}
|
| 6829 |
}
|
| 6830 |
playLocalVideo(URL.createObjectURL(f.slice(0, f.size, cur.mime || 'video/mp4')), cur.title, subs,
|
| 6831 |
-
{ id: cur.id, pick: cur.subPick == null ? null : cur.subPick, delay: cur.subDelay || 0
|
|
|
|
| 6832 |
} catch (e) {
|
| 6833 |
showToast(t('dq_err_missing'));
|
| 6834 |
}
|
|
@@ -7154,6 +7495,7 @@ async function processQueueItem(item){
|
|
| 7154 |
filename = `${item.subjectTitle} ${item.resolution}p.mp4`;
|
| 7155 |
}
|
| 7156 |
if (!videoUrl) throw new Error(t('dq_err_no_video'));
|
|
|
|
| 7157 |
// HATUA 1: muunganisho (mux) wa video + manukuu — hii SIO download yenyewe
|
| 7158 |
const finalUrl = await muxAndDownload(videoUrl, subtitles, filename, (msg) => {
|
| 7159 |
item.phase = 'mux';
|
|
@@ -7189,6 +7531,7 @@ async function processQueueItem(item){
|
|
| 7189 |
proxyBrowserDownload(finalUrl, filename);
|
| 7190 |
}
|
| 7191 |
item.status = 'done'; // 'done' inawekwa tu baada ya download halisi kumalizika
|
|
|
|
| 7192 |
if (!(saved && saved.viaBg)) notifyDownloadDone(item, true);
|
| 7193 |
} catch (e) {
|
| 7194 |
const isPermanent = !!(e && e.permanent) || /DRM/i.test(e.message || '');
|
|
|
|
| 1881 |
off_sub_remove_confirm: 'Ondoa manukuu "{label}"?',
|
| 1882 |
off_sub_reset: 'Rudisha',
|
| 1883 |
off_sub_delay: 'Manukuu: {s}',
|
| 1884 |
+
off_sub_embedded: '(ndani ya faili)',
|
| 1885 |
+
off_sub_load: '➕ Pakia faili',
|
| 1886 |
+
off_sub_size: 'Ukubwa wa manukuu: {p}%',
|
| 1887 |
+
off_scan_start: 'Inatafuta manukuu ndani ya faili…',
|
| 1888 |
+
off_scan_progress: 'Inatafuta manukuu ndani ya faili… {p}%',
|
| 1889 |
+
off_scan_found: 'Manukuu yamepatikana ndani ya faili: {n} — bonyeza CC',
|
| 1890 |
+
off_scan_bitmap: 'Manukuu ya ndani ni ya picha (PGS/VobSub) — hayasomeki. Pakia .srt kupitia CC.',
|
| 1891 |
off_failed: 'Imeshindikana: {msg}',
|
| 1892 |
off_confirm_delete: 'Futa "{title}"?',
|
| 1893 |
dl_pin_prompt: 'Weka PIN kupakua {title}',
|
|
|
|
| 2018 |
off_sub_remove_confirm: 'Remove subtitles "{label}"?',
|
| 2019 |
off_sub_reset: 'Reset',
|
| 2020 |
off_sub_delay: 'Subtitles: {s}',
|
| 2021 |
+
off_sub_embedded: '(inside the file)',
|
| 2022 |
+
off_sub_load: '➕ Load file',
|
| 2023 |
+
off_sub_size: 'Subtitle size: {p}%',
|
| 2024 |
+
off_scan_start: 'Looking for subtitles inside the file…',
|
| 2025 |
+
off_scan_progress: 'Looking for subtitles inside the file… {p}%',
|
| 2026 |
+
off_scan_found: 'Subtitles found inside the file: {n} — tap CC',
|
| 2027 |
+
off_scan_bitmap: 'The built-in subtitles are image-based (PGS/VobSub) and can\'t be read. Load an .srt via CC.',
|
| 2028 |
off_failed: 'Failed: {msg}',
|
| 2029 |
off_confirm_delete: 'Delete "{title}"?',
|
| 2030 |
dl_pin_prompt: 'Enter PIN to download {title}',
|
|
|
|
| 2157 |
off_sub_remove_confirm: 'إزالة الترجمة "{label}"؟',
|
| 2158 |
off_sub_reset: 'إعادة ضبط',
|
| 2159 |
off_sub_delay: 'الترجمة: {s}',
|
| 2160 |
+
off_sub_embedded: '(داخل الملف)',
|
| 2161 |
+
off_sub_load: '➕ تحميل ملف',
|
| 2162 |
+
off_sub_size: 'حجم الترجمة: {p}%',
|
| 2163 |
+
off_scan_start: 'جارٍ البحث عن ترجمة داخل الملف…',
|
| 2164 |
+
off_scan_progress: 'جارٍ البحث عن ترجمة داخل الملف… {p}%',
|
| 2165 |
+
off_scan_found: 'تم العثور على ترجمة داخل الملف: {n} — اضغط CC',
|
| 2166 |
+
off_scan_bitmap: 'الترجمة المدمجة صورية (PGS/VobSub) ولا يمكن قراءتها. حمّل ملف .srt عبر CC.',
|
| 2167 |
off_failed: 'فشل: {msg}',
|
| 2168 |
off_confirm_delete: 'حذف "{title}"؟',
|
| 2169 |
dl_pin_prompt: 'أدخل الرمز السري لتنزيل {title}',
|
|
|
|
| 2296 |
off_sub_remove_confirm: 'Retirer les sous-titres « {label} » ?',
|
| 2297 |
off_sub_reset: 'Réinitialiser',
|
| 2298 |
off_sub_delay: 'Sous-titres : {s}',
|
| 2299 |
+
off_sub_embedded: '(dans le fichier)',
|
| 2300 |
+
off_sub_load: '➕ Charger un fichier',
|
| 2301 |
+
off_sub_size: 'Taille des sous-titres : {p}%',
|
| 2302 |
+
off_scan_start: 'Recherche de sous-titres dans le fichier…',
|
| 2303 |
+
off_scan_progress: 'Recherche de sous-titres dans le fichier… {p}%',
|
| 2304 |
+
off_scan_found: 'Sous-titres trouvés dans le fichier : {n} — touchez CC',
|
| 2305 |
+
off_scan_bitmap: 'Les sous-titres intégrés sont en image (PGS/VobSub) et illisibles. Chargez un .srt via CC.',
|
| 2306 |
off_failed: 'Échec : {msg}',
|
| 2307 |
off_confirm_delete: 'Supprimer « {title} » ?',
|
| 2308 |
dl_pin_prompt: 'Saisissez le code PIN pour télécharger {title}',
|
|
|
|
| 4401 |
let shakaPlayer = null;
|
| 4402 |
let currentBlobUrls = [];
|
| 4403 |
let offSubDelay = 0, offSubSaveT = null; // sync ya manukuu ya offline (sekunde)
|
| 4404 |
+
let offCurId = null; // movie ya maktaba inayochezwa sasa (kwa kuhifadhi manukuu/chaguo)
|
| 4405 |
+
let offSubScale = (() => { try { return parseFloat(localStorage.getItem('jm_sub_scale')) || 1; } catch (_) { return 1; } })();
|
| 4406 |
let currentPr = null;
|
| 4407 |
let currentResumeMeta = null; // {id, se, ep, title, poster} — kwa ajili ya 'Endelea Kutazama'
|
| 4408 |
|
|
|
|
| 4462 |
back: SEEK_ICON_BACK, fwd: SEEK_ICON_FWD,
|
| 4463 |
};
|
| 4464 |
function pcFmt(t){ if (!isFinite(t) || t < 0) t = 0; t = Math.floor(t); const h = Math.floor(t / 3600), m = Math.floor(t % 3600 / 60), s = String(t % 60).padStart(2, '0'); return h ? h + ':' + String(m).padStart(2, '0') + ':' + s : m + ':' + s; }
|
| 4465 |
+
const PC_SECS = { quality: ['qualityRow', 'Ubora (Quality)'], sub: ['subRow', 'Manukuu (Subtitles)'], sync: ['subSyncRow', 'Zana za manukuu (pakia, sync, ukubwa)'], lang: ['langRow', 'Lugha (Language)'], speed: ['speedRow', 'Kasi (Speed)'] };
|
| 4466 |
function pcRowChips(k){ const r = document.getElementById(PC_SECS[k][0]); return r ? [...r.querySelectorAll('.tab-chip')] : []; }
|
| 4467 |
function pcOpenSheet(wrap, keys){
|
| 4468 |
const old = wrap.querySelector('.pc-sheet'); if (old) old.remove();
|
|
|
|
| 4530 |
const refresh = () => {
|
| 4531 |
const qc = pcRowChips('quality'); bq.style.display = qc.length ? '' : 'none';
|
| 4532 |
if (qc.length) { const a = qc.find(c => c.classList.contains('active')); bq.textContent = a ? a.textContent : 'Auto'; }
|
| 4533 |
+
bcc.style.display = (pcRowChips('sub').length || pcRowChips('sync').length) ? '' : 'none';
|
| 4534 |
bg.style.display = (pcRowChips('lang').length || pcRowChips('speed').length) ? '' : 'none';
|
| 4535 |
};
|
| 4536 |
let timer = null, drag = false;
|
|
|
|
| 4658 |
langRow.style.display = 'none'; langRow.innerHTML = '';
|
| 4659 |
subRow.style.display = 'none'; subRow.innerHTML = ''; subRow.onclick = null;
|
| 4660 |
const ssr = document.getElementById('subSyncRow'); if (ssr) { ssr.style.display = 'none'; ssr.innerHTML = ''; }
|
| 4661 |
+
clearTimeout(offSubSaveT); offSubDelay = 0; offCurId = null;
|
| 4662 |
speedRow.style.display = 'none'; speedRow.innerHTML = '';
|
| 4663 |
currentPr = null;
|
| 4664 |
currentResumeMeta = null;
|
|
|
|
| 6391 |
list.push({ id, title: item.title, sub: item.sub || '', poster: item.poster || '', thumbLabel: item.thumbLabel || '',
|
| 6392 |
filename, size, mime: 'video/mp4', addedAt: Date.now(), source: 'download' });
|
| 6393 |
setOfflineMeta(list);
|
| 6394 |
+
await offlineStoreSubEntries(id, dlSubCache.get(item.id));
|
| 6395 |
return { id, size };
|
| 6396 |
}
|
| 6397 |
|
|
|
|
| 6442 |
list.push({ id: oid, title: m.title, sub: m.sub || '', poster: m.poster || '', thumbLabel: m.thumbLabel || '',
|
| 6443 |
filename: m.filename, size: m.size, mime: 'video/mp4', addedAt: m.addedAt || Date.now(), source: 'download' });
|
| 6444 |
setOfflineMeta(list);
|
| 6445 |
+
let sv = m.subVtt;
|
| 6446 |
+
if (!sv || !sv.length) { try { const d = await offlineDirHandle(); sv = JSON.parse(await (await (await d.getFileHandle(oid + '.subs.json')).getFile()).text()); } catch (_) { sv = []; } }
|
| 6447 |
+
await offlineStoreSubEntries(oid, sv);
|
| 6448 |
}
|
| 6449 |
+
try { const d = await offlineDirHandle(); await d.removeEntry(oid + '.subs.json'); } catch (_) {}
|
| 6450 |
await bgMetaDelete(oid);
|
| 6451 |
return { id: oid, size: m.size, viaBg: true };
|
| 6452 |
}
|
|
|
|
| 6507 |
const oid = offlineNewId();
|
| 6508 |
await bgMetaWrite(oid, { id: oid, state: 'pending', title: item.title, sub: item.sub || '', poster: item.poster || '',
|
| 6509 |
thumbLabel: item.thumbLabel || '', filename, addedAt: Date.now() });
|
| 6510 |
+
try { // faili la kando la manukuu — service worker ikiandika upya JSON ya meta, manukuu hayapotei
|
| 6511 |
+
const sv = dlSubCache.get(item.id) || [];
|
| 6512 |
+
if (sv.length) { const d = await offlineDirHandle(); const fh = await d.getFileHandle(oid + '.subs.json', { create: true });
|
| 6513 |
+
const w = await fh.createWritable(); await w.write(JSON.stringify(sv)); await w.close(); }
|
| 6514 |
+
} catch (_) {}
|
| 6515 |
item.bgId = 'jm-' + oid; item.cancelled = false;
|
| 6516 |
item.phase = 'download'; item.dlBytes = 0; item.dlTotal = total || item.sizeBytes || 0; item.dlSpeed = 0;
|
| 6517 |
item.progressText = t('dq_saving');
|
|
|
|
| 6640 |
return '';
|
| 6641 |
}
|
| 6642 |
// Soma faili la manukuu kama maandishi — UTF-8 kwanza, kisha UTF-16 (BOM), kisha Windows-1252
|
| 6643 |
+
async function offlineReadSubText(file){ return decodeSubBytes(new Uint8Array(await file.arrayBuffer())); }
|
| 6644 |
+
function decodeSubBytes(u8){
|
| 6645 |
if (u8[0] === 0xFF && u8[1] === 0xFE) return new TextDecoder('utf-16le').decode(u8);
|
| 6646 |
if (u8[0] === 0xFE && u8[1] === 0xFF) return new TextDecoder('utf-16be').decode(u8);
|
| 6647 |
try { return new TextDecoder('utf-8', { fatal: true }).decode(u8).replace(/^\uFEFF/, ''); }
|
|
|
|
| 6741 |
const list = getOfflineMeta(); const m = list.find(x => x.id === id);
|
| 6742 |
if (m) { m.subs = (m.subs || []).filter(x => x.k !== k); if (m.subPick != null && m.subPick >= m.subs.length) m.subPick = null; setOfflineMeta(list); }
|
| 6743 |
}
|
| 6744 |
+
// Manukuu ya download (soft subs za mux): pakua nakala ya .vtt kando ili kicheza kiziorodheshe kwenye CC
|
| 6745 |
+
// (kivinjari hakisomi subtitle track iliyo ndani ya MP4/MKV). Imeshikiliwa kwenye kumbukumbu, si localStorage.
|
| 6746 |
+
const dlSubCache = new Map(); // item.id -> [{vtt, language, label, filename}]
|
| 6747 |
+
async function fetchSubSidecars(subs){
|
| 6748 |
+
const out = [];
|
| 6749 |
+
for (let i = 0; i < (subs || []).length; i++) {
|
| 6750 |
+
const s = subs[i]; if (!s || !s.url) continue;
|
| 6751 |
+
try {
|
| 6752 |
+
const r = await fetch(s.url); if (!r.ok) continue;
|
| 6753 |
+
const vtt = subToVtt(decodeSubBytes(new Uint8Array(await r.arrayBuffer())), String(s.url).split('?')[0]);
|
| 6754 |
+
if (!/-->/.test(vtt)) continue;
|
| 6755 |
+
const lang = s.language && s.language !== 'und' ? s.language : '';
|
| 6756 |
+
out.push({ vtt, language: lang, label: s.label || (lang && langName(lang)) || t('sub_track', { n: i + 1 }), filename: '' });
|
| 6757 |
+
} catch (e) { console.warn('subtitle sidecar imeshindwa', e); }
|
| 6758 |
+
}
|
| 6759 |
+
return out;
|
| 6760 |
+
}
|
| 6761 |
+
async function offlineStoreSubEntries(id, entries){
|
| 6762 |
+
if (!entries || !entries.length) return 0;
|
| 6763 |
+
let n = 0;
|
| 6764 |
+
try {
|
| 6765 |
+
const dir = await offlineDirHandle();
|
| 6766 |
+
for (const e of entries) {
|
| 6767 |
+
try {
|
| 6768 |
+
const list = getOfflineMeta(); const m = list.find(x => x.id === id); if (!m) break;
|
| 6769 |
+
m.subs = m.subs || [];
|
| 6770 |
+
const k = (m.subSeq || m.subs.reduce((a, x) => Math.max(a, x.k || 0), 0)) + 1; m.subSeq = k;
|
| 6771 |
+
const fh = await dir.getFileHandle(id + '.s' + k + '.vtt', { create: true });
|
| 6772 |
+
const w = await fh.createWritable(); await w.write(e.vtt); await w.close();
|
| 6773 |
+
const same = m.subs.filter(x => x.label === e.label || x.label.startsWith(e.label + ' (')).length;
|
| 6774 |
+
m.subs.push({ k, label: same ? e.label + ' (' + (same + 1) + ')' : e.label, language: e.language || '', filename: e.filename || '' });
|
| 6775 |
+
setOfflineMeta(list); n++;
|
| 6776 |
+
} catch (err) { console.warn('sub store failed', err); }
|
| 6777 |
+
}
|
| 6778 |
+
} catch (_) {}
|
| 6779 |
+
return n;
|
| 6780 |
+
}
|
| 6781 |
+
|
| 6782 |
// Oanisha manukuu na video kwa jina: "Movie.mp4" ↔ "Movie.en.srt". Video moja tu = manukuu yote ni yake.
|
| 6783 |
function pairSubsToVideos(videos, subs){
|
| 6784 |
const base = f => f.name.replace(/\.[^.]+$/, '').toLowerCase();
|
|
|
|
| 6801 |
if (!offlineCanSave()) { // kivinjari kisichounga mkono OPFS (mf. iOS): cheza tu kwa kikao hiki
|
| 6802 |
const subs = [];
|
| 6803 |
for (const sf of (subFiles || [])) { try { subs.push(await subFileToEntry(sf)); } catch (_) {} }
|
| 6804 |
+
playLocalVideo(URL.createObjectURL(file), title, subs, { scanFile: file });
|
| 6805 |
return 'session';
|
| 6806 |
}
|
| 6807 |
await offlineCheckQuota(file.size);
|
|
|
|
| 6820 |
return 'saved';
|
| 6821 |
}
|
| 6822 |
|
| 6823 |
+
// ══════════════════════════════════════════════════════════════
|
| 6824 |
+
// MANUKUU ZILIZO NDANI YA FAILI (kama VLC): soma subtitle track za maandishi
|
| 6825 |
+
// ndani ya MKV/WebM (SRT, ASS/SSA, WebVTT) na MP4/MOV (tx3g/mov_text).
|
| 6826 |
+
// Zinabadilishwa kuwa WebVTT na kuhifadhiwa kama manukuu ya kawaida ya movie.
|
| 6827 |
+
// Manukuu ya picha (PGS / VobSub) hayasomeki bila kuyatambua kwa OCR.
|
| 6828 |
+
// ══════════════════════════════════════════════════════════════
|
| 6829 |
+
class SubFileRd {
|
| 6830 |
+
constructor(file){ this.f = file; this.size = file.size; this.b = null; this.s = 0; this.CH = 1 << 20; }
|
| 6831 |
+
async at(pos, len){
|
| 6832 |
+
len = Math.min(len, this.size - pos);
|
| 6833 |
+
if (len <= 0) return new Uint8Array(0);
|
| 6834 |
+
if (!this.b || pos < this.s || pos + len > this.s + this.b.length) {
|
| 6835 |
+
const n = Math.min(Math.max(len, this.CH), this.size - pos);
|
| 6836 |
+
this.b = new Uint8Array(await this.f.slice(pos, pos + n).arrayBuffer()); this.s = pos;
|
| 6837 |
+
}
|
| 6838 |
+
return this.b.subarray(pos - this.s, pos - this.s + len);
|
| 6839 |
+
}
|
| 6840 |
+
}
|
| 6841 |
+
function msTs(ms){
|
| 6842 |
+
ms = Math.max(0, Math.round(ms));
|
| 6843 |
+
return subTs(Math.floor(ms / 3600000), Math.floor(ms % 3600000 / 60000), Math.floor(ms % 60000 / 1000), String(ms % 1000).padStart(3, '0'));
|
| 6844 |
+
}
|
| 6845 |
+
function cuesToVtt(cues){
|
| 6846 |
+
cues.sort((a, b) => a.s - b.s);
|
| 6847 |
+
return 'WEBVTT\n\n' + cues.map(c => msTs(c.s) + ' --> ' + msTs(c.e) + '\n' + c.text + '\n').join('\n');
|
| 6848 |
+
}
|
| 6849 |
+
function embLang(raw){
|
| 6850 |
+
const l = String(raw || '').toLowerCase().trim();
|
| 6851 |
+
if (!l || l === 'und') return '';
|
| 6852 |
+
return SUB_LANGS[l] || l.split('-')[0];
|
| 6853 |
+
}
|
| 6854 |
+
function embEntry(vtt, lang, name, idx){
|
| 6855 |
+
const code = embLang(lang);
|
| 6856 |
+
return { vtt, language: code, label: (name && String(name).trim()) || (code && langName(code)) || t('sub_track', { n: idx + 1 }), filename: t('off_sub_embedded') };
|
| 6857 |
+
}
|
| 6858 |
+
async function inflateZ(u8){
|
| 6859 |
+
const ds = new DecompressionStream('deflate'); const w = ds.writable.getWriter(); w.write(u8); w.close();
|
| 6860 |
+
return new Uint8Array(await new Response(ds.readable).arrayBuffer());
|
| 6861 |
+
}
|
| 6862 |
+
const EMB_TEXT_CODEC = /^S_(TEXT\/(UTF8|ASCII|SSA|ASS|WEBVTT)|SSA|ASS)$/i;
|
| 6863 |
+
function mkvVint(b, i, keep){
|
| 6864 |
+
const first = b[i]; if (first === undefined || first === 0) return null;
|
| 6865 |
+
let n = 1, mask = 0x80; while (!(first & mask)) { n++; mask >>= 1; }
|
| 6866 |
+
if (i + n > b.length) return null;
|
| 6867 |
+
let v = keep ? first : (first & (mask - 1)), ones = (first & (mask - 1)) === mask - 1;
|
| 6868 |
+
for (let k = 1; k < n; k++) { v = v * 256 + b[i + k]; if (b[i + k] !== 255) ones = false; }
|
| 6869 |
+
return { v: (!keep && ones) ? -1 : v, n };
|
| 6870 |
+
}
|
| 6871 |
+
async function mkvExtract(file, onProg){
|
| 6872 |
+
const rd = new SubFileRd(file), end = file.size;
|
| 6873 |
+
const DESC = new Set([0x18538067, 0x1654AE6B, 0x1F43B675, 0xA0, 0x1549A966, 0x6D80, 0x6240, 0x5034]);
|
| 6874 |
+
const LEAF = new Set([0xD7, 0x83, 0x86, 0x22B59C, 0x22B59D, 0x536E, 0x4254, 0x2AD7B1, 0xE7, 0x9B]);
|
| 6875 |
+
const tracks = [], byNum = new Map();
|
| 6876 |
+
let cur = null, scale = 1000000, clT = 0, last = null, pos = 0, loops = 0, sawCluster = false;
|
| 6877 |
+
const uint = b => { let v = 0; for (let i = 0; i < b.length; i++) v = v * 256 + b[i]; return v; };
|
| 6878 |
+
const str = b => new TextDecoder().decode(b).replace(/\0+$/, '');
|
| 6879 |
+
while (pos < end) {
|
| 6880 |
+
if ((++loops & 255) === 0 && onProg && onProg(pos / end) === false) return { entries: [], bitmap: false, aborted: true };
|
| 6881 |
+
const h = await rd.at(pos, 16);
|
| 6882 |
+
const id = mkvVint(h, 0, true); if (!id) break;
|
| 6883 |
+
const sz = mkvVint(h, id.n, false); if (!sz) break;
|
| 6884 |
+
const dp = pos + id.n + sz.n, size = sz.v;
|
| 6885 |
+
if (id.v === 0x1F43B675 && !sawCluster) {
|
| 6886 |
+
sawCluster = true;
|
| 6887 |
+
tracks.forEach(tr => { if (tr.type === 17 && EMB_TEXT_CODEC.test(tr.codec)) byNum.set(tr.n, tr); });
|
| 6888 |
+
if (!byNum.size) break; // hakuna manukuu ya maandishi — usitembee faili zima
|
| 6889 |
+
}
|
| 6890 |
+
if (id.v === 0xAE) { cur = { n: 0, type: 0, codec: '', lang: '', lang2: '', name: '', comp: null, cues: [] }; tracks.push(cur); pos = dp; continue; }
|
| 6891 |
+
if (id.v === 0xA0) last = null;
|
| 6892 |
+
if (DESC.has(id.v) || size < 0) { pos = dp; continue; }
|
| 6893 |
+
if (id.v === 0xA1 || id.v === 0xA3) {
|
| 6894 |
+
const h2 = await rd.at(dp, 12), tn = mkvVint(h2, 0, false);
|
| 6895 |
+
if (tn && byNum.has(tn.v)) {
|
| 6896 |
+
const rel = ((h2[tn.n] << 8) | h2[tn.n + 1]) << 16 >> 16;
|
| 6897 |
+
const pl = await rd.at(dp + tn.n + 3, size - tn.n - 3);
|
| 6898 |
+
last = { t: (clT + rel) * scale / 1e6, dur: 0, data: pl.slice() };
|
| 6899 |
+
byNum.get(tn.v).cues.push(last);
|
| 6900 |
+
} else last = null;
|
| 6901 |
+
pos = dp + size; continue;
|
| 6902 |
+
}
|
| 6903 |
+
if (LEAF.has(id.v) && size <= 4096) {
|
| 6904 |
+
const b = await rd.at(dp, size);
|
| 6905 |
+
switch (id.v) {
|
| 6906 |
+
case 0x2AD7B1: scale = uint(b) || 1000000; break;
|
| 6907 |
+
case 0xE7: clT = uint(b); break;
|
| 6908 |
+
case 0x9B: if (last) last.dur = uint(b) * scale / 1e6; break;
|
| 6909 |
+
default: if (cur && !sawCluster) {
|
| 6910 |
+
if (id.v === 0xD7) cur.n = uint(b); else if (id.v === 0x83) cur.type = uint(b);
|
| 6911 |
+
else if (id.v === 0x86) cur.codec = str(b); else if (id.v === 0x22B59C) cur.lang = str(b);
|
| 6912 |
+
else if (id.v === 0x22B59D) cur.lang2 = str(b); else if (id.v === 0x536E) cur.name = str(b);
|
| 6913 |
+
else if (id.v === 0x4254) cur.comp = uint(b);
|
| 6914 |
+
}
|
| 6915 |
+
}
|
| 6916 |
+
}
|
| 6917 |
+
pos = dp + size;
|
| 6918 |
+
}
|
| 6919 |
+
const entries = [];
|
| 6920 |
+
const bitmap = tracks.some(tr => tr.type === 17 && !EMB_TEXT_CODEC.test(tr.codec));
|
| 6921 |
+
let idx = 0;
|
| 6922 |
+
for (const tr of tracks) {
|
| 6923 |
+
if (!byNum.has(tr.n) || !tr.cues.length) continue;
|
| 6924 |
+
const isAss = /ASS|SSA/i.test(tr.codec), cues = [];
|
| 6925 |
+
tr.cues.sort((a, b) => a.t - b.t);
|
| 6926 |
+
for (let i = 0; i < tr.cues.length; i++) {
|
| 6927 |
+
const c = tr.cues[i]; let data = c.data;
|
| 6928 |
+
try { if (tr.comp === 0) data = await inflateZ(data); } catch (_) { continue; }
|
| 6929 |
+
let text = new TextDecoder().decode(data).replace(/\r\n?/g, '\n');
|
| 6930 |
+
if (isAss) text = text.split(',').slice(8).join(',').replace(/\\N/g, '\n').replace(/\\n/g, '\n').replace(/\\h/g, ' ');
|
| 6931 |
+
text = subCleanText(text).trim();
|
| 6932 |
+
if (!text) continue;
|
| 6933 |
+
const nxt = tr.cues[i + 1];
|
| 6934 |
+
cues.push({ s: c.t, e: c.dur > 0 ? c.t + c.dur : (nxt ? Math.min(nxt.t, c.t + 5000) : c.t + 3000), text });
|
| 6935 |
+
}
|
| 6936 |
+
if (cues.length) entries.push(embEntry(cuesToVtt(cues), tr.lang2 || tr.lang || 'eng', tr.name, idx++));
|
| 6937 |
+
}
|
| 6938 |
+
return { entries, bitmap };
|
| 6939 |
+
}
|
| 6940 |
+
function* mp4Boxes(b, s, e){
|
| 6941 |
+
const dv = new DataView(b.buffer, b.byteOffset, b.byteLength);
|
| 6942 |
+
while (s + 8 <= e) {
|
| 6943 |
+
let size = dv.getUint32(s), hl = 8; const type = String.fromCharCode(b[s + 4], b[s + 5], b[s + 6], b[s + 7]);
|
| 6944 |
+
if (size === 1) { size = dv.getUint32(s + 8) * 4294967296 + dv.getUint32(s + 12); hl = 16; } else if (size === 0) size = e - s;
|
| 6945 |
+
if (size < hl || s + size > e) break;
|
| 6946 |
+
yield { type, s: s + hl, e: s + size };
|
| 6947 |
+
s += size;
|
| 6948 |
+
}
|
| 6949 |
+
}
|
| 6950 |
+
async function mp4Extract(file, onProg){
|
| 6951 |
+
const rd = new SubFileRd(file); let pos = 0, moov = null;
|
| 6952 |
+
while (pos < file.size) {
|
| 6953 |
+
const h = await rd.at(pos, 16); if (h.length < 8) break;
|
| 6954 |
+
const dv = new DataView(h.buffer, h.byteOffset, h.byteLength);
|
| 6955 |
+
let size = dv.getUint32(0), hl = 8; const type = String.fromCharCode(h[4], h[5], h[6], h[7]);
|
| 6956 |
+
if (size === 1 && h.length >= 16) { size = dv.getUint32(8) * 4294967296 + dv.getUint32(12); hl = 16; } else if (size === 0) size = file.size - pos;
|
| 6957 |
+
if (size < hl) break;
|
| 6958 |
+
if (type === 'moov') { moov = new Uint8Array(await file.slice(pos + hl, pos + size).arrayBuffer()); break; }
|
| 6959 |
+
pos += size;
|
| 6960 |
+
}
|
| 6961 |
+
if (!moov) return { entries: [], bitmap: false };
|
| 6962 |
+
const dv = new DataView(moov.buffer, moov.byteOffset, moov.byteLength);
|
| 6963 |
+
const find = (s, e, type) => { for (const bx of mp4Boxes(moov, s, e)) if (bx.type === type) return bx; return null; };
|
| 6964 |
+
const entries = []; let idx = 0, unsupported = false;
|
| 6965 |
+
for (const trak of mp4Boxes(moov, 0, moov.length)) {
|
| 6966 |
+
if (trak.type !== 'trak') continue;
|
| 6967 |
+
const mdia = find(trak.s, trak.e, 'mdia'); if (!mdia) continue;
|
| 6968 |
+
const hdlr = find(mdia.s, mdia.e, 'hdlr'), mdhd = find(mdia.s, mdia.e, 'mdhd'), minf = find(mdia.s, mdia.e, 'minf');
|
| 6969 |
+
if (!hdlr || !mdhd || !minf) continue;
|
| 6970 |
+
const ht = String.fromCharCode(moov[hdlr.s + 8], moov[hdlr.s + 9], moov[hdlr.s + 10], moov[hdlr.s + 11]);
|
| 6971 |
+
if (!/^(sbtl|text|subt)$/.test(ht)) continue;
|
| 6972 |
+
const stbl = find(minf.s, minf.e, 'stbl'); if (!stbl) continue;
|
| 6973 |
+
const stsd = find(stbl.s, stbl.e, 'stsd'), stts = find(stbl.s, stbl.e, 'stts'), stsc = find(stbl.s, stbl.e, 'stsc');
|
| 6974 |
+
const stsz = find(stbl.s, stbl.e, 'stsz'), stco = find(stbl.s, stbl.e, 'stco') || find(stbl.s, stbl.e, 'co64');
|
| 6975 |
+
if (!stsd || !stts || !stsc || !stsz || !stco) continue;
|
| 6976 |
+
const fmt = String.fromCharCode(moov[stsd.s + 12], moov[stsd.s + 13], moov[stsd.s + 14], moov[stsd.s + 15]);
|
| 6977 |
+
if (!/^(tx3g|text)$/.test(fmt)) { unsupported = true; continue; }
|
| 6978 |
+
const v1 = moov[mdhd.s] === 1;
|
| 6979 |
+
const timescale = dv.getUint32(mdhd.s + (v1 ? 20 : 12)) || 1000;
|
| 6980 |
+
const lc = dv.getUint16(mdhd.s + (v1 ? 32 : 20));
|
| 6981 |
+
const lang = lc ? String.fromCharCode(((lc >> 10) & 31) + 0x60, ((lc >> 5) & 31) + 0x60, (lc & 31) + 0x60) : '';
|
| 6982 |
+
// jedwali la sampuli
|
| 6983 |
+
const sizes = []; const ssz = dv.getUint32(stsz.s + 4), sn = dv.getUint32(stsz.s + 8);
|
| 6984 |
+
for (let i = 0; i < sn; i++) sizes.push(ssz || dv.getUint32(stsz.s + 12 + i * 4));
|
| 6985 |
+
const cn = dv.getUint32(stco.s + 4), is64 = stco.type === 'co64', coffs = [];
|
| 6986 |
+
for (let i = 0; i < cn; i++) coffs.push(is64 ? dv.getUint32(stco.s + 8 + i * 8) * 4294967296 + dv.getUint32(stco.s + 12 + i * 8) : dv.getUint32(stco.s + 8 + i * 4));
|
| 6987 |
+
const scn = dv.getUint32(stsc.s + 4), sc = [];
|
| 6988 |
+
for (let i = 0; i < scn; i++) sc.push([dv.getUint32(stsc.s + 8 + i * 12), dv.getUint32(stsc.s + 12 + i * 12)]);
|
| 6989 |
+
const offs = []; let si = 0, k = 0;
|
| 6990 |
+
for (let c = 1; c <= cn && si < sn; c++) {
|
| 6991 |
+
while (k + 1 < sc.length && sc[k + 1][0] <= c) k++;
|
| 6992 |
+
let o = coffs[c - 1];
|
| 6993 |
+
for (let j = 0; j < (sc[k] ? sc[k][1] : 0) && si < sn; j++) { offs.push(o); o += sizes[si++]; }
|
| 6994 |
+
}
|
| 6995 |
+
const tn = dv.getUint32(stts.s + 4), starts = [], durs = []; let tt = 0;
|
| 6996 |
+
for (let i = 0; i < tn; i++) { const cnt = dv.getUint32(stts.s + 8 + i * 8), dl = dv.getUint32(stts.s + 12 + i * 8); for (let j = 0; j < cnt; j++) { starts.push(tt); durs.push(dl); tt += dl; } }
|
| 6997 |
+
const n = Math.min(offs.length, starts.length), cues = [];
|
| 6998 |
+
for (let b0 = 0; b0 < n; b0 += 32) {
|
| 6999 |
+
if (onProg && onProg(b0 / n) === false) return { entries: [], bitmap: false, aborted: true };
|
| 7000 |
+
const batch = [];
|
| 7001 |
+
for (let i = b0; i < Math.min(n, b0 + 32); i++) batch.push(sizes[i] > 2 ? file.slice(offs[i], offs[i] + sizes[i]).arrayBuffer() : Promise.resolve(null));
|
| 7002 |
+
const res = await Promise.all(batch);
|
| 7003 |
+
res.forEach((buf, j) => {
|
| 7004 |
+
if (!buf) return; const u = new Uint8Array(buf), len = (u[0] << 8) | u[1];
|
| 7005 |
+
const text = subCleanText(new TextDecoder().decode(u.subarray(2, 2 + len))).trim();
|
| 7006 |
+
const i = b0 + j; if (text) cues.push({ s: starts[i] * 1000 / timescale, e: (starts[i] + durs[i]) * 1000 / timescale, text });
|
| 7007 |
+
});
|
| 7008 |
+
}
|
| 7009 |
+
if (cues.length) entries.push(embEntry(cuesToVtt(cues), lang, '', idx++));
|
| 7010 |
+
}
|
| 7011 |
+
return { entries, bitmap: unsupported };
|
| 7012 |
+
}
|
| 7013 |
+
async function extractEmbeddedSubs(file, onProg){
|
| 7014 |
+
const h = new Uint8Array(await file.slice(0, 16).arrayBuffer());
|
| 7015 |
+
if (h[0] === 0x1A && h[1] === 0x45 && h[2] === 0xDF && h[3] === 0xA3) return mkvExtract(file, onProg);
|
| 7016 |
+
const ty = String.fromCharCode(h[4], h[5], h[6], h[7]);
|
| 7017 |
+
if (/^(ftyp|moov|mdat|free|wide|skip)$/.test(ty)) return mp4Extract(file, onProg);
|
| 7018 |
+
return { entries: [], bitmap: false };
|
| 7019 |
+
}
|
| 7020 |
+
|
| 7021 |
// ── Sync ya manukuu: sogeza muda wa cues zote (+ = yachelewe, − = yawahi) ──
|
| 7022 |
function applySubDelay(v){
|
| 7023 |
try {
|
|
|
|
| 7031 |
}
|
| 7032 |
} catch (_) {}
|
| 7033 |
}
|
| 7034 |
+
function applySubScale(){
|
| 7035 |
+
let st = document.getElementById('cueStyle');
|
| 7036 |
+
if (!st) { st = document.createElement('style'); st.id = 'cueStyle'; document.head.appendChild(st); }
|
| 7037 |
+
st.textContent = 'video::cue{font-size:clamp(12px,' + (4.5 * offSubScale).toFixed(2) + 'vmin,72px)}';
|
| 7038 |
+
}
|
| 7039 |
+
function wireSubPersist(id){
|
| 7040 |
+
subRow.onclick = (e) => { // kumbuka chaguo la mtumiaji kwa movie hii
|
| 7041 |
+
const chip = e.target.closest('.tab-chip'); if (!chip || !id) return;
|
| 7042 |
+
offlineSetMetaField(id, { subPick: chip.dataset.type === 'native' ? +chip.dataset.i : -1 });
|
| 7043 |
+
};
|
| 7044 |
+
}
|
| 7045 |
+
// Ongeza track mpya kwenye video inayochezwa (kutoka faili la simu au scan ya ndani ya faili)
|
| 7046 |
+
function addLocalSubTracks(v, entries, selectLast){
|
| 7047 |
+
if (!entries || !entries.length) return;
|
| 7048 |
+
if (!currentPr) currentPr = { subtitles: [] };
|
| 7049 |
+
const base = currentPr.subtitles.length;
|
| 7050 |
+
entries.forEach((x, j) => {
|
| 7051 |
+
const i = base + j;
|
| 7052 |
+
currentPr.subtitles.push({ label: x.label, language: x.language });
|
| 7053 |
+
const bu = URL.createObjectURL(new Blob([x.vtt], { type: 'text/vtt' }));
|
| 7054 |
+
currentBlobUrls.push(bu);
|
| 7055 |
+
const tr = document.createElement('track');
|
| 7056 |
+
tr.kind = 'subtitles'; tr.dataset.si = String(i);
|
| 7057 |
+
tr.label = x.label || ('Sub ' + (i + 1)); tr.srclang = x.language || 'sw';
|
| 7058 |
+
tr.src = bu;
|
| 7059 |
+
tr.addEventListener('load', () => applySubDelay(v));
|
| 7060 |
+
v.appendChild(tr);
|
| 7061 |
+
});
|
| 7062 |
+
renderSubtitleChips(v, currentPr, true); // silent: chaguo la sasa linabaki
|
| 7063 |
+
wireSubPersist(offCurId);
|
| 7064 |
+
if (selectLast) { const c = subRow.querySelector('.tab-chip[data-type="native"][data-i="' + (currentPr.subtitles.length - 1) + '"]'); if (c) c.click(); }
|
| 7065 |
+
}
|
| 7066 |
+
// Zana za manukuu (kama VLC): pakia faili, sync, ukubwa
|
| 7067 |
function renderSubSyncChips(v, id){
|
| 7068 |
const row = document.getElementById('subSyncRow'); if (!row) return;
|
| 7069 |
const fmt = () => (offSubDelay > 0 ? '+' : '') + offSubDelay.toFixed(1) + 's';
|
| 7070 |
+
const steps = [['load', null, t('off_sub_load')], ['d', -5, '−5s'], ['d', -0.5, '−0.5s'], ['d', 0, t('off_sub_reset') + ' (' + fmt() + ')'], ['d', 0.5, '+0.5s'], ['d', 5, '+5s'], ['sz', -0.1, 'A−'], ['sz', 0.1, 'A+']];
|
| 7071 |
const draw = () => {
|
| 7072 |
row.style.display = 'flex';
|
| 7073 |
+
row.innerHTML = steps.map(([k, d, lb], i) => `<div class="tab-chip" data-i="${i}">${esc(k === 'd' && d === 0 ? t('off_sub_reset') + ' (' + fmt() + ')' : lb)}</div>`).join('');
|
| 7074 |
+
row.querySelectorAll('.tab-chip').forEach(c => c.onclick = async () => {
|
| 7075 |
+
const [k, d] = steps[+c.dataset.i];
|
| 7076 |
+
if (k === 'load') {
|
| 7077 |
+
const inp = document.createElement('input'); inp.type = 'file'; inp.multiple = true;
|
| 7078 |
+
inp.accept = '.srt,.vtt,.ass,.ssa,text/*,application/x-subrip';
|
| 7079 |
+
inp.onchange = async () => {
|
| 7080 |
+
const ents = [];
|
| 7081 |
+
for (const f of [...inp.files]) { try { ents.push(await subFileToEntry(f)); } catch (_) { showToast(t('off_sub_failed', { name: f.name })); } }
|
| 7082 |
+
if (!ents.length) return;
|
| 7083 |
+
if (offCurId) await offlineStoreSubEntries(offCurId, ents);
|
| 7084 |
+
addLocalSubTracks(v, ents, true);
|
| 7085 |
+
showToast(t('off_sub_added', { n: ents.length }));
|
| 7086 |
+
};
|
| 7087 |
+
inp.click(); return;
|
| 7088 |
+
}
|
| 7089 |
+
if (k === 'sz') {
|
| 7090 |
+
offSubScale = Math.min(2.4, Math.max(0.6, Math.round((offSubScale + d) * 10) / 10));
|
| 7091 |
+
try { localStorage.setItem('jm_sub_scale', String(offSubScale)); } catch (_) {}
|
| 7092 |
+
applySubScale(); toastMsg(esc(t('off_sub_size', { p: Math.round(offSubScale * 100) }))); return;
|
| 7093 |
+
}
|
| 7094 |
offSubDelay = d === 0 ? 0 : Math.round((offSubDelay + d) * 10) / 10;
|
| 7095 |
applySubDelay(v);
|
| 7096 |
if (id) { clearTimeout(offSubSaveT); offSubSaveT = setTimeout(() => offlineSetMetaField(id, { subDelay: offSubDelay }), 400); }
|
|
|
|
| 7100 |
};
|
| 7101 |
draw();
|
| 7102 |
}
|
| 7103 |
+
// Tafuta manukuu yaliyo ndani ya faili (mara moja kwa movie) na yaongeze kwenye CC
|
| 7104 |
+
async function scanEmbeddedSubs(v, file, id){
|
| 7105 |
+
try {
|
| 7106 |
+
toastMsg(esc(t('off_scan_start')));
|
| 7107 |
+
const r = await extractEmbeddedSubs(file, p => { if (!v.isConnected) return false; toastMsg(esc(t('off_scan_progress', { p: Math.round(p * 100) }))); return true; });
|
| 7108 |
+
if (r.aborted) return;
|
| 7109 |
+
if (id) offlineSetMetaField(id, { embScan: true });
|
| 7110 |
+
if (r.entries.length) {
|
| 7111 |
+
if (id) await offlineStoreSubEntries(id, r.entries);
|
| 7112 |
+
if (v.isConnected) { addLocalSubTracks(v, r.entries, false); toastMsg(esc(t('off_scan_found', { n: r.entries.length }))); }
|
| 7113 |
+
} else if (v.isConnected) toastMsg(r.bitmap ? esc(t('off_scan_bitmap')) : '');
|
| 7114 |
+
} catch (e) { console.warn('scan ya manukuu imeshindwa', e); if (v.isConnected) toastMsg(''); }
|
| 7115 |
+
}
|
| 7116 |
|
| 7117 |
// subs: [{label, language, vtt}] — opts: { id, pick, delay } (id = movie ya maktaba ya offline)
|
| 7118 |
function playLocalVideo(url, title, subs, opts){
|
| 7119 |
opts = opts || {};
|
| 7120 |
openPlayerShell(title);
|
| 7121 |
+
offCurId = opts.id || null;
|
| 7122 |
+
offSubDelay = Number(opts.delay) || 0;
|
| 7123 |
+
if (offSubScale !== 1) applySubScale();
|
| 7124 |
currentBlobUrls.push(url); // stopMediaOnly() inaifuta URL ikifungwa
|
| 7125 |
stage.innerHTML = '<video id="vid" controls autoplay playsinline></video>';
|
| 7126 |
const v = document.getElementById('vid');
|
|
|
|
| 7130 |
const list = (subs || []).filter(x => x && x.vtt);
|
| 7131 |
if (list.length) {
|
| 7132 |
currentPr = { subtitles: list.map(x => ({ label: x.label, language: x.language })) };
|
|
|
|
| 7133 |
list.forEach((x, i) => {
|
| 7134 |
const bu = URL.createObjectURL(new Blob([x.vtt], { type: 'text/vtt' }));
|
| 7135 |
currentBlobUrls.push(bu);
|
|
|
|
| 7142 |
});
|
| 7143 |
}
|
| 7144 |
v.src = url;
|
| 7145 |
+
renderSubSyncChips(v, opts.id); // zana za manukuu zipo hata kama hakuna manukuu bado
|
| 7146 |
if (list.length) {
|
| 7147 |
renderSubtitleChips(v, currentPr);
|
|
|
|
| 7148 |
const pick = opts.pick; // undefined/null = mara ya kwanza → washa ya kwanza; -1 = zimezimwa
|
| 7149 |
if (pick === -1) { const off = subRow.querySelector('.tab-chip[data-type="off"]'); if (off) off.click(); }
|
| 7150 |
else {
|
|
|
|
| 7152 |
const act = subRow.querySelector('.tab-chip.active');
|
| 7153 |
if (want && (pick != null || (act && act.dataset.type === 'off'))) want.click();
|
| 7154 |
}
|
| 7155 |
+
wireSubPersist(opts.id);
|
|
|
|
|
|
|
|
|
|
| 7156 |
}
|
| 7157 |
+
if (opts.scanFile) scanEmbeddedSubs(v, opts.scanFile, opts.id);
|
| 7158 |
v.play().catch(() => {});
|
| 7159 |
}
|
| 7160 |
async function playOfflineItem(meta){
|
|
|
|
| 7168 |
try { const sf = await (await dir.getFileHandle(cur.id + '.s' + sb.k + '.vtt')).getFile(); subs.push({ label: sb.label, language: sb.language, vtt: await sf.text() }); } catch (_) {}
|
| 7169 |
}
|
| 7170 |
playLocalVideo(URL.createObjectURL(f.slice(0, f.size, cur.mime || 'video/mp4')), cur.title, subs,
|
| 7171 |
+
{ id: cur.id, pick: cur.subPick == null ? null : cur.subPick, delay: cur.subDelay || 0,
|
| 7172 |
+
scanFile: (!cur.embScan && !(cur.source === 'download' && (cur.subs || []).length)) ? f : null });
|
| 7173 |
} catch (e) {
|
| 7174 |
showToast(t('dq_err_missing'));
|
| 7175 |
}
|
|
|
|
| 7495 |
filename = `${item.subjectTitle} ${item.resolution}p.mp4`;
|
| 7496 |
}
|
| 7497 |
if (!videoUrl) throw new Error(t('dq_err_no_video'));
|
| 7498 |
+
dlSubCache.set(item.id, await fetchSubSidecars(subtitles)); // nakala za .vtt kwa ajili ya CC ya kicheza
|
| 7499 |
// HATUA 1: muunganisho (mux) wa video + manukuu — hii SIO download yenyewe
|
| 7500 |
const finalUrl = await muxAndDownload(videoUrl, subtitles, filename, (msg) => {
|
| 7501 |
item.phase = 'mux';
|
|
|
|
| 7531 |
proxyBrowserDownload(finalUrl, filename);
|
| 7532 |
}
|
| 7533 |
item.status = 'done'; // 'done' inawekwa tu baada ya download halisi kumalizika
|
| 7534 |
+
dlSubCache.delete(item.id);
|
| 7535 |
if (!(saved && saved.viaBg)) notifyDownloadDone(item, true);
|
| 7536 |
} catch (e) {
|
| 7537 |
const isPermanent = !!(e && e.permanent) || /DRM/i.test(e.message || '');
|