MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / doM3U

Function doM3U

scripts/backup/m38u_detector.js:509–550  ·  view source on GitHub ↗
({ url, content })

Source from the content-addressed store, hash-verified

507 }
508
509 async function doM3U({ url, content }) {
510 url = new URL(url);
511
512 if (shownUrls.includes(url.href)) return;
513
514 // 解析 m3u
515 content = content || (await (await fetch(url)).text());
516
517 const parser = new m3u8Parser.Parser();
518 parser.push(content);
519 parser.end();
520 const manifest = parser.manifest;
521
522 if (manifest.segments) {
523 let duration = 0;
524 manifest.segments.forEach((segment) => {
525 duration += segment.duration;
526 });
527 manifest.duration = duration;
528 }
529
530 showVideo({
531 type: "m3u8",
532 url,
533 duration: manifest.duration
534 ? `${Math.ceil((manifest.duration * 10) / 60) / 10} mins`
535 : manifest.playlists
536 ? `多(Multi)(${manifest.playlists.length})`
537 : "未知(unknown)",
538 async download() {
539 mgmapi.openInTab(
540 `https://tools.thatwind.com/tool/m3u8downloader#${new URLSearchParams(
541 {
542 m3u8: url.href,
543 referer: location.href,
544 filename: (await getTopTitle()) || "",
545 }
546 )}`
547 );
548 },
549 });
550 }
551
552 async function showVideo({ type, url, duration, download }) {
553 let div = document.createElement("div");

Callers 1

m38u_detector.jsFile · 0.85

Calls 1

showVideoFunction · 0.85

Tested by

no test coverage detected