mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-03-11 22:15:35 +00:00
feat: improve anilist search result accuracy
This commit is contained in:
parent
41ae69a057
commit
03bceb7ef2
5 changed files with 41 additions and 16 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Miru",
|
||||
"version": "3.1.4",
|
||||
"version": "3.1.5",
|
||||
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
|
||||
"description": "Stream anime torrents, real-time with no waiting for downloads.",
|
||||
"main": "src/index.js",
|
||||
|
|
@ -109,6 +109,7 @@
|
|||
"electron-log": "^4.4.6",
|
||||
"electron-updater": "^4.6.5",
|
||||
"jassub": "^1.1.8",
|
||||
"js-levenshtein": "^1.1.6",
|
||||
"matroska-subtitles": "github:ThaUnknown/matroska-subtitles#patch",
|
||||
"mime": "^3.0.0",
|
||||
"p2pcf": "github:ThaUnknown/p2pcf#no-remove",
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ specifiers:
|
|||
electron-notarize: ^1.1.1
|
||||
electron-updater: ^4.6.5
|
||||
jassub: ^1.1.8
|
||||
js-levenshtein: ^1.1.6
|
||||
matroska-subtitles: github:ThaUnknown/matroska-subtitles#patch
|
||||
mime: ^3.0.0
|
||||
p2pcf: github:ThaUnknown/p2pcf#no-remove
|
||||
|
|
@ -34,9 +35,10 @@ dependencies:
|
|||
electron-log: 4.4.8
|
||||
electron-updater: 4.6.5
|
||||
jassub: 1.1.8
|
||||
js-levenshtein: 1.1.6
|
||||
matroska-subtitles: github.com/ThaUnknown/matroska-subtitles/70bee097ad540e07d9e31b8f91f1dd865f7f2b45
|
||||
mime: 3.0.0
|
||||
p2pcf: github.com/ThaUnknown/p2pcf/3aa32102cea803dc9c4595d5ad0b68a5beba184c
|
||||
p2pcf: github.com/ThaUnknown/p2pcf/faefe2854c817315530636a58d07726de7050561
|
||||
pump: 3.0.0
|
||||
quartermoon: 1.2.1
|
||||
range-parser: 1.2.1
|
||||
|
|
@ -353,10 +355,10 @@ packages:
|
|||
resolution: {integrity: sha512-m0+M53+HYMzqKxwNQZT143K7WwXEGUy9LY31l8dJphXx2P/FQod615mVbxHyqbDCG4J5bHdWm21qZ0e2DVY6CQ==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
dependencies:
|
||||
7zip-bin: 5.1.1
|
||||
'@develar/schema-utils': 2.6.5
|
||||
'@electron/universal': 1.2.1
|
||||
'@malept/flatpak-bundler': 0.4.0
|
||||
7zip-bin: 5.1.1
|
||||
async-exit-hook: 2.0.1
|
||||
bluebird-lst: 1.0.9
|
||||
builder-util: 23.3.3
|
||||
|
|
@ -701,9 +703,9 @@ packages:
|
|||
/builder-util/23.3.3:
|
||||
resolution: {integrity: sha512-MJZlUiq2PY5hjYv9+XNaoYdsITqvLgRDoHSFg/4nzpInbNxNjLQOolL04Zsyp+hgfcbFvMC4h0KkR1CMPHLWbA==}
|
||||
dependencies:
|
||||
7zip-bin: 5.1.1
|
||||
'@types/debug': 4.1.7
|
||||
'@types/fs-extra': 9.0.13
|
||||
7zip-bin: 5.1.1
|
||||
app-builder-bin: 4.0.0
|
||||
bluebird-lst: 1.0.9
|
||||
builder-util-runtime: 9.0.3
|
||||
|
|
@ -2030,6 +2032,11 @@ packages:
|
|||
rvfc-polyfill: 1.0.4
|
||||
dev: false
|
||||
|
||||
/js-levenshtein/1.1.6:
|
||||
resolution: {integrity: sha512-X2BB11YZtrRqY4EnQcLX5Rh373zbK4alC1FW7D7MBhL2gtcC17cTnr6DmfHZeS0s2rTHjUTMMHfG7gO8SSdw+g==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
|
||||
/js-yaml/4.1.0:
|
||||
resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}
|
||||
hasBin: true
|
||||
|
|
@ -3538,8 +3545,8 @@ packages:
|
|||
readable-stream: 3.6.0
|
||||
dev: false
|
||||
|
||||
github.com/ThaUnknown/p2pcf/3aa32102cea803dc9c4595d5ad0b68a5beba184c:
|
||||
resolution: {tarball: https://codeload.github.com/ThaUnknown/p2pcf/tar.gz/3aa32102cea803dc9c4595d5ad0b68a5beba184c}
|
||||
github.com/ThaUnknown/p2pcf/faefe2854c817315530636a58d07726de7050561:
|
||||
resolution: {tarball: https://codeload.github.com/ThaUnknown/p2pcf/tar.gz/faefe2854c817315530636a58d07726de7050561}
|
||||
name: p2pcf
|
||||
version: 1.3.6
|
||||
dependencies:
|
||||
|
|
|
|||
|
|
@ -301,7 +301,6 @@
|
|||
currentTime = currentTime += time
|
||||
}
|
||||
targetTime = currentTime
|
||||
console.log(targetTime, currentTime)
|
||||
video.currentTime = targetTime
|
||||
}
|
||||
function forward () {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { alToken } from '@/lib/Settings.svelte'
|
||||
import { addToast } from '@/lib/Toasts.svelte'
|
||||
import lavenshtein from 'js-levenshtein'
|
||||
|
||||
import Bottleneck from 'bottleneck'
|
||||
|
||||
|
|
@ -143,6 +144,23 @@ export function alEntry (filemedia) {
|
|||
}
|
||||
}
|
||||
|
||||
function getDistanceFromTitle (media, name) {
|
||||
if (media) {
|
||||
const distances = [...Object.values(media.title), ...media.synonyms].filter(v => v).map(title => lavenshtein(title, name))
|
||||
const min = distances.reduce((prev, curr) => prev < curr ? prev : curr)
|
||||
media.lavenshtein = min
|
||||
return media
|
||||
}
|
||||
}
|
||||
|
||||
export async function alSearch (method) {
|
||||
const res = await alRequest(method)
|
||||
const media = res.data.Page.media.map(media => getDistanceFromTitle(media, method.name))
|
||||
if (!media.length) return res
|
||||
const lowest = media.reduce((prev, curr) => prev.lavenshtein < curr.lavenshtein ? prev : curr)
|
||||
return { data: { Page: { media: [lowest] } } }
|
||||
}
|
||||
|
||||
export async function alRequest (opts) {
|
||||
let query
|
||||
const variables = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { add } from './torrent.js'
|
||||
import { DOMPARSER, PromiseBatch } from './util.js'
|
||||
import { alRequest } from './anilist.js'
|
||||
import { alRequest, alSearch } from './anilist.js'
|
||||
import anitomyscript from 'anitomyscript'
|
||||
import 'anitomyscript/build/anitomyscript.wasm?url'
|
||||
import { addToast } from '@/lib/Toasts.svelte'
|
||||
|
|
@ -91,7 +91,7 @@ const postfix = {
|
|||
}
|
||||
|
||||
async function resolveTitle (name) {
|
||||
const method = { name, method: 'SearchName', perPage: 1, status: ['RELEASING', 'FINISHED'], sort: 'SEARCH_MATCH' }
|
||||
const method = { name, method: 'SearchName', perPage: 10, status: ['RELEASING', 'FINISHED'], sort: 'SEARCH_MATCH' }
|
||||
|
||||
// inefficient but readable
|
||||
|
||||
|
|
@ -103,17 +103,17 @@ async function resolveTitle (name) {
|
|||
if (match) {
|
||||
if (Number(match[1]) === 1) { // if this is S1, remove the " S1" or " S01"
|
||||
method.name = method.name.replace(/ S(\d+)/, '')
|
||||
media = (await alRequest(method)).data.Page.media[0]
|
||||
media = (await alSearch(method)).data.Page.media[0]
|
||||
} else {
|
||||
method.name = method.name.replace(/ S(\d+)/, ` ${Number(match[1])}${postfix[Number(match[1])] || 'th'} Season`)
|
||||
media = (await alRequest(method)).data.Page.media[0]
|
||||
media = (await alSearch(method)).data.Page.media[0]
|
||||
if (!media) {
|
||||
method.name = oldname.replace(/ S(\d+)/, ` Season ${Number(match[1])}`)
|
||||
media = (await alRequest(method)).data.Page.media[0]
|
||||
media = (await alSearch(method)).data.Page.media[0]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
media = (await alRequest(method)).data.Page.media[0]
|
||||
media = (await alSearch(method)).data.Page.media[0]
|
||||
}
|
||||
|
||||
// remove (TV)
|
||||
|
|
@ -121,7 +121,7 @@ async function resolveTitle (name) {
|
|||
const match = method.name.match(/\(TV\)/)
|
||||
if (match) {
|
||||
method.name = method.name.replace('(TV)', '')
|
||||
media = (await alRequest(method)).data.Page.media[0]
|
||||
media = (await alSearch(method)).data.Page.media[0]
|
||||
}
|
||||
}
|
||||
// remove - :
|
||||
|
|
@ -129,7 +129,7 @@ async function resolveTitle (name) {
|
|||
const match = method.name.match(/[-:]/g)
|
||||
if (match) {
|
||||
method.name = method.name.replace(/[-:]/g, '')
|
||||
media = (await alRequest(method)).data.Page.media[0]
|
||||
media = (await alSearch(method)).data.Page.media[0]
|
||||
}
|
||||
}
|
||||
// remove 2020
|
||||
|
|
@ -137,7 +137,7 @@ async function resolveTitle (name) {
|
|||
const match = method.name.match(/ (19[5-9]\d|20\d{2})/)
|
||||
if (match) {
|
||||
method.name = method.name.replace(/ (19[5-9]\d|20\d{2})/, '')
|
||||
media = (await alRequest(method)).data.Page.media[0]
|
||||
media = (await alSearch(method)).data.Page.media[0]
|
||||
}
|
||||
}
|
||||
} catch (e) { }
|
||||
|
|
|
|||
Loading…
Reference in a new issue