mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-18 01:51:24 +00:00
offline store progress, fixes
This commit is contained in:
parent
c2a0547783
commit
17eac7af5c
4 changed files with 85 additions and 38 deletions
|
|
@ -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: `<span class="text-break">${selectedFile.name}</span> 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')) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <span class="text-break">${torrent.infoHash}</span>! 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 <span class="text-break">${torrent.infoHash}</span>!`,
|
||||
content: `Couldn't find peers for <span class="text-break">${torrent.infoHash}</span>! 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 <span class="text-break">${torrent.infoHash}</span>!`,
|
||||
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) {
|
||||
|
|
|
|||
9
app/test.html
Normal file
9
app/test.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<script src="https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js"></script>
|
||||
<script src="js/idbkv-chunk-store.js"></script>
|
||||
<script>
|
||||
let client = new WebTorrent()
|
||||
client.add(
|
||||
"https://webtorrent.io/torrents/tears-of-steel.torrent", {
|
||||
store: IdbkvChunkStore
|
||||
})
|
||||
</script>
|
||||
Loading…
Reference in a new issue