diff --git a/app/js/playerHandler.js b/app/js/playerHandler.js index dad7fb3..ff00173 100644 --- a/app/js/playerHandler.js +++ b/app/js/playerHandler.js @@ -17,7 +17,7 @@ video.onloadedmetadata = () => { } video.onended = () => { updateBar(video.currentTime / video.duration * 100) - if (settings.player6 && parseInt(playerData.nowPlaying[1]) <= playerData.nowPlaying[0].episodes) btnnext() + if (settings.player6 && parseInt(playerData.nowPlaying[1]) < playerData.nowPlaying[0].episodes) btnnext() } video.addEventListener("waiting", isBuffering); video.ontimeupdate = () => { @@ -76,19 +76,28 @@ async function buildVideo(torrent, opts) { // sets video source and creates a bu video.src = `${scope}webtorrent/${torrent.infoHash}/${encodeURI(selectedFile.path)}` video.load(); playVideo(); - playerData.onDone = selectedFile.on("done", () => { + function processFile() { halfmoon.initStickyAlert({ content: `${selectedFile.name} has finished downloading. Now seeding.`, title: "Download Complete", alertType: "alert-success", fillType: "" }); - if (settings.player8) { - if (!settings.torrent5) finishThumbnails(selectedFile); - postDownload(selectedFile) + if (!torrent.store.store._idbkvStore) { + if (settings.player8) { + finishThumbnails(selectedFile); + postDownload(selectedFile) + } + downloadFile(selectedFile) } - if (!settings.torrent5) downloadFile(selectedFile) - }) + } + if (selectedFile.done) { + processFile() + } else { + playerData.onDone = selectedFile.on("done", () => { + processFile() + }) + } playerData.onProgress = () => { if (document.location.hash == "#player") { if (!player.classList.contains('immersed')) { diff --git a/app/js/subtitleOctopus.js b/app/js/subtitleOctopus.js index df7c1ce..c59d6dd 100644 --- a/app/js/subtitleOctopus.js +++ b/app/js/subtitleOctopus.js @@ -88,26 +88,48 @@ function convertSub(subtitle) { // converts vtt subtitles to ssa ones subtitle.text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/ /g, "\\h") } function postDownload(file) { // parse subtitles fully after a download is finished - if (playerData.subtitleStream) { + if (file.name.endsWith(".mkv") || file.name.endsWith(".webm")) {\ let parser = new SubtitleParser(), - subtitles = [] + subtitles = [], + headers = [] parser.once('tracks', pTracks => { pTracks.forEach(track => { + if (track.type != "ass") { // overwrite webvtt header with custom one + track.header = `[Script Info] +Title: English +ScriptType: v4.00+ +Collisions: Normal +PlayDepth: 0 +WrapStyle: 0 +ScaledBorderAndShadow: yes +PlayResX: 640 +PlayResY: 360 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: Default,${Object.values(subtitle1list.options).filter(item => item.value == settings.subtitle1)[0].innerText} + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text + +` + } + headers[track.number] = track subtitles[track.number] = new Set() }) }) parser.on('subtitle', (subtitle, trackNumber) => { - if (playerData.headers) { - if (playerData.headers[trackNumber].type == "webvtt") convertSub(subtitle) - subtitles[trackNumber].add("Dialogue: " + (subtitle.layer || 0) + "," + new Date(subtitle.time).toISOString().slice(12, -1).slice(0, -1) + "," + new Date(subtitle.time + subtitle.duration).toISOString().slice(12, -1).slice(0, -1) + "," + (subtitle.style || "Default") + "," + (subtitle.name || "") + "," + (subtitle.marginL || "0") + "," + (subtitle.marginR || "0") + "," + (subtitle.marginV || "0") + "," + (subtitle.effect || "") + "," + subtitle.text) - } + if (headers[trackNumber].type == "webvtt") convertSub(subtitle) + subtitles[trackNumber].add("Dialogue: " + (subtitle.layer || 0) + "," + new Date(subtitle.time).toISOString().slice(12, -1).slice(0, -1) + "," + new Date(subtitle.time + subtitle.duration).toISOString().slice(12, -1).slice(0, -1) + "," + (subtitle.style || "Default") + "," + (subtitle.name || "") + "," + (subtitle.marginL || "0") + "," + (subtitle.marginR || "0") + "," + (subtitle.marginV || "0") + "," + (subtitle.effect || "") + "," + subtitle.text) }) parser.on('finish', () => { playerData.subtitles = subtitles + playerData.headers = headers playerData.parsed = 1 playerData.subtitleStream = undefined renderSubs.call(null, playerData.selectedHeader) }); + console.log("creating stream") file.createReadStream().pipe(parser) } } \ No newline at end of file diff --git a/app/js/torrentHandler.js b/app/js/torrentHandler.js index b32ece2..6c47fb4 100644 --- a/app/js/torrentHandler.js +++ b/app/js/torrentHandler.js @@ -82,8 +82,7 @@ function offlineDownload(torrent) { div.onclick = () => { cleanupVideo() cleanupTorrents() - videoFiles = torrent.files.filter(file => videoExtensions.some(ext => file.name.endsWith(ext))) - buildVideo(torrent, {}) + playTorrent(torrent, {}) } onProgress = () => { div.innerHTML = `${torrent.name} %: ${torrent.progress}` @@ -108,36 +107,44 @@ function cleanupTorrents() { WEBTORRENT_ANNOUNCE = announceList.map(arr => { return arr[0] }).filter(url => { return url.indexOf('wss://') === 0 }) let videoFiles -async function addTorrent(magnet, opts) { - halfmoon.hideModal("tsearch") - document.location.hash = "#player" - cleanupVideo() - cleanupTorrents() - await sw - client.add(magnet, settings.torrent5 ? { store: indexedDBStore } : {}, function (torrent) { - torrent.on('noPeers', () => { - if (torrent.progress != 1) { - halfmoon.initStickyAlert({ - content: `Couldn't find peers for ${torrent.infoHash}! Try a torrent with more seeders.`, - title: "Search Failed", - alertType: "alert-danger", - fillType: "" - }); - } - }) - videoFiles = torrent.files.filter(file => videoExtensions.some(ext => file.name.endsWith(ext))) - if (videoFiles) { - buildVideo(torrent, opts) - } else { +async function playTorrent(torrent, opts) { + torrent.on('noPeers', () => { + if (torrent.progress != 1) { halfmoon.initStickyAlert({ - content: `Couldn't find video file for ${torrent.infoHash}!`, + content: `Couldn't find peers for ${torrent.infoHash}! Try a torrent with more seeders.`, title: "Search Failed", alertType: "alert-danger", fillType: "" }); - cleanupTorrents() } }) + await sw + videoFiles = torrent.files.filter(file => videoExtensions.some(ext => file.name.endsWith(ext))) + if (videoFiles) { + buildVideo(torrent, opts) + } else { + halfmoon.initStickyAlert({ + content: `Couldn't find video file for ${torrent.infoHash}!`, + title: "Search Failed", + alertType: "alert-danger", + fillType: "" + }); + cleanupTorrents() + } +} + +function addTorrent(torrentID, opts) { + halfmoon.hideModal("tsearch") + document.location.hash = "#player" + cleanupVideo() + cleanupTorrents() + if (client.get(torrentID)) { + playTorrent(client.get(torrentID), {}) + } else { + client.add(torrentID, settings.torrent5 ? { store: indexedDBStore } : {}, function (torrent) { + playTorrent(torrent, opts) + }) + } } function serveFile(file, req) { diff --git a/app/test.html b/app/test.html new file mode 100644 index 0000000..af95a5b --- /dev/null +++ b/app/test.html @@ -0,0 +1,9 @@ + + + \ No newline at end of file