fix: better chapter sanitisation

feat: basic debug logging
fix: NCED/OP being filtered too late
This commit is contained in:
ThaUnknown 2023-05-07 12:36:35 +02:00
parent c2ca168aa3
commit 6beb5b14bd
6 changed files with 41 additions and 30 deletions

View file

@ -1,6 +1,6 @@
{
"name": "Miru",
"version": "3.10.3",
"version": "3.10.4",
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
"description": "Stream anime torrents, real-time with no waiting for downloads.",
"main": "src/index.js",
@ -66,10 +66,12 @@
"singleArchFiles": "node_modules/+(register-scheme|utp-native)/**",
"category": "public.app-category.video",
"icon": "build/icon.icns",
"target": [{
"arch": "universal",
"target": "dmg"
}]
"target": [
{
"arch": "universal",
"target": "dmg"
}
]
},
"win": {
"artifactName": "${os}-${name}-${version}.${ext}",
@ -109,7 +111,7 @@
"discord-rpc": "4.0.1",
"electron-log": "^4.4.8",
"electron-updater": "^4.6.5",
"jassub": "1.6.1",
"jassub": "1.6.2",
"js-levenshtein": "^1.1.6",
"matroska-subtitles": "github:ThaUnknown/matroska-subtitles#redist",
"mime": "^3.0.0",

View file

@ -12,7 +12,7 @@ specifiers:
electron-log: ^4.4.8
electron-notarize: ^1.2.2
electron-updater: ^4.6.5
jassub: 1.6.1
jassub: 1.6.2
js-levenshtein: ^1.1.6
matroska-subtitles: github:ThaUnknown/matroska-subtitles#redist
mime: ^3.0.0
@ -36,7 +36,7 @@ dependencies:
discord-rpc: 4.0.1
electron-log: 4.4.8
electron-updater: 4.6.5
jassub: 1.6.1
jassub: 1.6.2
js-levenshtein: 1.1.6
matroska-subtitles: github.com/ThaUnknown/matroska-subtitles/446d0628ff0bcf13eb95184777615f3a0e6d8ae8
mime: 3.0.0
@ -1873,8 +1873,8 @@ packages:
minimatch: 3.1.2
dev: true
/jassub/1.6.1:
resolution: {integrity: sha512-yCPTr+0Dua7xUPMdgMj32nYdVXDDXJ50/qY6ycQbIC2exiyZY+C1whg8/vHDeKXT/CLBy+lufjfUKbqWa4a80A==}
/jassub/1.6.2:
resolution: {integrity: sha512-xmQlG+Dzs6jHouCFw6VjWAl01PSkCA/1w91zDgCsWXMPFWvsMdcx65UohxL2RsZoEn/mSTSLHnaPHSCJvTaaWg==}
dependencies:
rvfc-polyfill: 1.0.4
dev: false

View file

@ -70,8 +70,9 @@
}
async function handleFiles (files) {
console.info('MediaHandler: got files', files)
if (!files?.length) return processed.set(files)
const videoFiles = []
let videoFiles = []
const otherFiles = []
for (const file of files) {
if (videoRx.test(file.name)) {
@ -87,6 +88,14 @@
return file
})
videoFiles = videoFiles.filter(file => {
if (file.media.parseObject.anime_type?.toLowerCase() === 'nced') return false
if (file.media.parseObject.anime_type?.toLowerCase() === 'ncop') return false
return true
})
console.info('MediaHandler: resolved video files', { videoFiles })
let nowPlaying = get(media)
if (!nowPlaying) {
@ -99,19 +108,20 @@
const filtered = nowPlaying?.media && videoFiles.filter(file => file.media?.media?.id && file.media?.media?.id === nowPlaying.media.id)
console.info('MediaHandler: filtered files based on media', filtered)
let result
if (filtered?.length) {
result = filtered
} else {
const max = highestOccurence(videoFiles, file => file.media.parseObject.anime_title).media.parseObject.anime_title
console.info('MediaHandler: filtering based on highest occurence', max)
result = videoFiles.filter(file => file.media.parseObject.anime_title === max)
}
result = result.filter(file => {
if (file.media.parseObject.anime_type?.toLowerCase() === 'nced') return false
if (file.media.parseObject.anime_type?.toLowerCase() === 'ncop') return false
return true
}).sort((a, b) => a.media.episode - b.media.episode)
result.sort((a, b) => a.media.episode - b.media.episode)
console.info('MediaHandler: final resolve result', { result })
processed.set([...result, ...otherFiles])
await tick()

View file

@ -230,7 +230,7 @@
function playNext () {
if (hasNext) {
const index = videos.indexOf(current)
if (index + 2 < videos.length) {
if (index + 1 < videos.length) {
const target = (index + 1) % videos.length
handleCurrent(videos[target])
w2gEmitter.emit('index', { index: target })
@ -242,7 +242,7 @@
function playLast () {
if (hasLast) {
const index = videos.indexOf(current)
if (index > 1) {
if (index > 0) {
handleCurrent(videos[index - 1])
w2gEmitter.emit('index', { index: index - 1 })
} else if (media?.episode > 1) {
@ -682,25 +682,21 @@
function sanitiseChapters (chapters, safeduration) {
if (!chapters?.length) return []
const sanitised = []
let sum = 0
const first = chapters[0]
if (first.start !== 0) {
sanitised.push({ size: Math.max(first.start, 0) / 10 / safeduration })
}
for (let { start, end, text } of chapters) {
if (start > safeduration * 1000) continue
if (start < 0) start = 0
if (end > safeduration * 1000) end = safeduration * 1000
if (!sanitised.length && start !== 0) {
const size = start / 10 / safeduration
sum += size
sanitised.push({ size })
}
const size = (end / 10 / safeduration) - (start / 10 / safeduration)
sum += size
sanitised.push({
size,
size: (end / 10 / safeduration) - (start / 10 / safeduration),
text
})
}
if (sum !== 100) {
sanitised.push({ size: 100 - sum })
const last = sanitised[sanitised.length - 1]
if (last.end !== safeduration) {
sanitised.push(100 - (last.end / 10 / safeduration))
}
return sanitised
}

View file

@ -22,6 +22,7 @@ class TorrentWorker extends EventTarget {
async send (type, data) {
await this.ready
console.info('Torrent: sending message', { type, data })
this.port.postMessage({ type, data })
}
}
@ -36,6 +37,7 @@ client.on('files', ({ detail }) => {
export async function add (torrentID, hide) {
if (torrentID) {
console.info('Torrent: adding torrent', { torrentID })
files.set([])
if (!hide) page.set('player')
if (typeof torrentID === 'string' && !torrentID.startsWith('magnet:')) {

View file

@ -20,6 +20,7 @@ export default defineConfig(({ mode }) => {
},
base: './',
build: {
sourcemap: true,
rollupOptions: {
output: {
assetFileNames: '[name].[ext]'