mirror of
https://github.com/NoCrypt/migu.git
synced 2026-04-21 00:22:08 +00:00
fix: null debug
This commit is contained in:
parent
196ba8be55
commit
8e969f1352
9 changed files with 35 additions and 35 deletions
|
|
@ -178,7 +178,7 @@ class AnilistClient {
|
|||
lastNotificationDate = Date.now() / 1000
|
||||
|
||||
constructor () {
|
||||
debug('Initializing Anilist Client for ID ' + this.userID?.viewer?.data?.Viewer.id)
|
||||
debug('Initializing Anilist Client for ID ' + this.userID?.viewer?.data?.Viewer?.id)
|
||||
this.limiter.on('failed', async (error, jobInfo) => {
|
||||
printError(error)
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ class AnilistClient {
|
|||
const notifications = res.data.Page.notifications
|
||||
const newNotifications = notifications.filter(({ createdAt }) => createdAt > this.lastNotificationDate)
|
||||
this.lastNotificationDate = Date.now() / 1000
|
||||
debug(`Found ${newNotifications.length} new notifications`)
|
||||
debug(`Found ${newNotifications?.length} new notifications`)
|
||||
for (const { media, episode, type } of newNotifications) {
|
||||
const options = {
|
||||
title: media.title.userPreferred,
|
||||
|
|
@ -290,7 +290,7 @@ class AnilistClient {
|
|||
* @param {{key: string, title: string, year?: string, isAdult: boolean}[]} flattenedTitles
|
||||
**/
|
||||
async alSearchCompound (flattenedTitles) {
|
||||
debug(`Searching for ${flattenedTitles.length} titles via compound search`)
|
||||
debug(`Searching for ${flattenedTitles?.length} titles via compound search`)
|
||||
if (!flattenedTitles.length) return []
|
||||
// isAdult doesn't need an extra variable, as the title is the same regardless of type, so we re-use the same variable for adult and non-adult requests
|
||||
/** @type {Record<`v${number}`, string>} */
|
||||
|
|
@ -355,7 +355,7 @@ class AnilistClient {
|
|||
}
|
||||
|
||||
async searchName (variables = {}) {
|
||||
debug(`Searching name for ${variables.name}`)
|
||||
debug(`Searching name for ${variables?.name}`)
|
||||
const query = /* js */`
|
||||
query($page: Int, $perPage: Int, $sort: [MediaSort], $name: String, $status: [MediaStatus], $year: Int, $isAdult: Boolean) {
|
||||
Page(page: $page, perPage: $perPage) {
|
||||
|
|
@ -378,7 +378,7 @@ class AnilistClient {
|
|||
}
|
||||
|
||||
async searchIDSingle (variables) {
|
||||
debug(`Searching for ID: ${variables.id}`)
|
||||
debug(`Searching for ID: ${variables?.id}`)
|
||||
const query = /* js */`
|
||||
query($id: Int) {
|
||||
Media(id: $id, type: ANIME) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class MALDubs {
|
|||
}
|
||||
|
||||
async getMALDubs() {
|
||||
debug('Getting myanimelist dubs')
|
||||
debug('Getting MyAnimeList Dubs IDs')
|
||||
let res = {}
|
||||
try {
|
||||
res = await fetch('https://raw.githubusercontent.com/MAL-Dubs/MAL-Dubs/main/data/dubInfo.json')
|
||||
|
|
|
|||
|
|
@ -76,12 +76,12 @@ export default new class AnimeResolver {
|
|||
return titleObjects
|
||||
}).flat()
|
||||
|
||||
debug(`Finding ${titleObjects.length} titles: ${titleObjects.map(obj => obj.title).join(', ')}`)
|
||||
debug(`Finding ${titleObjects?.length} titles: ${titleObjects?.map(obj => obj.title).join(', ')}`)
|
||||
|
||||
for (const chunk of chunks(titleObjects, 60)) {
|
||||
// single title has a complexity of 8.1, al limits complexity to 500, so this can be at most 62, undercut it to 60, al pagination is 50, but at most we'll do 30 titles since isAduld duplicates each title
|
||||
for (const [key, media] of await anilistClient.alSearchCompound(chunk)) {
|
||||
debug(`Found ${key} as ${media.id}: ${media.title.userPreferred}`)
|
||||
debug(`Found ${key} as ${media?.id}: ${media?.title?.userPreferred}`)
|
||||
this.animeNameCache[key] = media
|
||||
}
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ export default new class AnimeResolver {
|
|||
let media = this.animeNameCache[this.getCacheKeyForTitle(parseObj)]
|
||||
// resolve episode, if movie, dont.
|
||||
const maxep = media?.nextAiringEpisode?.episode || media?.episodes
|
||||
debug(`Resolving ${parseObj.anime_title} ${parseObj.episode_number} ${maxep} ${media?.title.userPreferred} ${media?.format}`)
|
||||
debug(`Resolving ${parseObj?.anime_title} ${parseObj?.episode_number} ${maxep} ${media?.title?.userPreferred} ${media?.format}`)
|
||||
if ((media?.format !== 'MOVIE' || maxep) && parseObj.episode_number) {
|
||||
if (Array.isArray(parseObj.episode_number)) {
|
||||
// is an episode range
|
||||
|
|
@ -141,9 +141,9 @@ export default new class AnimeResolver {
|
|||
// parent check is to break out of those incorrectly resolved OVA's
|
||||
// if we used anime season to resolve anime name, then there's no need to march into prequel!
|
||||
const prequel = !parseObj.anime_season && (this.findEdge(media, 'PREQUEL')?.node || ((media.format === 'OVA' || media.format === 'ONA') && this.findEdge(media, 'PARENT')?.node))
|
||||
debug(`Prequel ${prequel && prequel.id}:${prequel && prequel.title.userPreferred}`)
|
||||
debug(`Prequel ${prequel?.id}:${prequel?.title?.userPreferred}`)
|
||||
const root = prequel && (await this.resolveSeason({ media: await this.getAnimeById(prequel.id), force: true })).media
|
||||
debug(`Root ${root && root.id}:${root && root.title.userPreferred}`)
|
||||
debug(`Root ${root?.id}:${root?.title?.userPreferred}`)
|
||||
|
||||
// if highest value is bigger than episode count or latest streamed episode +1 for safety, parseint to math.floor a number like 12.5 - specials - in 1 go
|
||||
let result = await this.resolveSeason({ media: root || media, episode: parseObj.episode_number[1], increment: !parseObj.anime_season ? null : true })
|
||||
|
|
@ -153,12 +153,12 @@ export default new class AnimeResolver {
|
|||
result = await this.resolveSeason({ media: root || media, episode: parseObj.episode_number[1] })
|
||||
}
|
||||
|
||||
debug(`Found rootMedia for ${parseObj.anime_title}: ${result.rootMedia.id}:${result.rootMedia.title.userPreferred} from ${media.id}:${media.title.userPreferred}`)
|
||||
debug(`Found rootMedia for ${parseObj?.anime_title}: ${result?.rootMedia?.id}:${result?.rootMedia?.title?.userPreferred} from ${media?.id}:${media?.title?.userPreferred}`)
|
||||
media = result.rootMedia
|
||||
const diff = parseObj.episode_number[1] - result.episode
|
||||
episode = `${parseObj.episode_number[0] - diff} ~ ${result.episode}`
|
||||
failed = result.failed
|
||||
if (failed) debug(`Failed to resolve ${parseObj.anime_title} ${parseObj.episode_number} ${media?.title.userPreferred}`)
|
||||
if (failed) debug(`Failed to resolve ${parseObj?.anime_title} ${parseObj?.episode_number} ${media?.title?.userPreferred}`)
|
||||
} else {
|
||||
// cant find ep count or range seems fine
|
||||
episode = `${Number(parseObj.episode_number[0])} ~ ${Number(parseObj.episode_number[1])}`
|
||||
|
|
@ -168,9 +168,9 @@ export default new class AnimeResolver {
|
|||
if (maxep && parseInt(parseObj.episode_number) > maxep) {
|
||||
// see big comment above
|
||||
const prequel = !parseObj.anime_season && (this.findEdge(media, 'PREQUEL')?.node || ((media.format === 'OVA' || media.format === 'ONA') && this.findEdge(media, 'PARENT')?.node))
|
||||
debug(`Prequel ${prequel && prequel.id}:${prequel && prequel.title.userPreferred}`)
|
||||
debug(`Prequel ${prequel?.id}:${prequel?.title?.userPreferred}`)
|
||||
const root = prequel && (await this.resolveSeason({ media: await this.getAnimeById(prequel.id), force: true })).media
|
||||
debug(`Root ${root && root.id}:${root && root.title.userPreferred}`)
|
||||
debug(`Root ${root?.id}:${root?.title?.userPreferred}`)
|
||||
|
||||
// value bigger than episode count
|
||||
let result = await this.resolveSeason({ media: root || media, episode: parseInt(parseObj.episode_number), increment: !parseObj.anime_season ? null : true })
|
||||
|
|
@ -180,18 +180,18 @@ export default new class AnimeResolver {
|
|||
result = await this.resolveSeason({ media: root || media, episode: parseInt(parseObj.episode_number) })
|
||||
}
|
||||
|
||||
debug(`Found rootMedia for ${parseObj.anime_title}: ${result.rootMedia.id}:${result.rootMedia.title.userPreferred} from ${media.id}:${media.title.userPreferred}`)
|
||||
debug(`Found rootMedia for ${parseObj.anime_title}: ${result.rootMedia?.id}:${result.rootMedia?.title?.userPreferred} from ${media.id}:${media.title?.userPreferred}`)
|
||||
media = result.rootMedia
|
||||
episode = result.episode
|
||||
failed = result.failed
|
||||
if (failed) debug(`Failed to resolve ${parseObj.anime_title} ${parseObj.episode_number} ${media?.title.userPreferred}`)
|
||||
if (failed) debug(`Failed to resolve ${parseObj.anime_title} ${parseObj.episode_number} ${media?.title?.userPreferred}`)
|
||||
} else {
|
||||
// cant find ep count or episode seems fine
|
||||
episode = Number(parseObj.episode_number)
|
||||
}
|
||||
}
|
||||
}
|
||||
debug(`Resolved ${parseObj.anime_title} ${parseObj.episode_number} ${episode} ${media?.id}:${media?.title.userPreferred}`)
|
||||
debug(`Resolved ${parseObj.anime_title} ${parseObj.episode_number} ${episode} ${media?.id}:${media?.title?.userPreferred}`)
|
||||
fileAnimes.push({
|
||||
episode: episode || parseObj.episode_number,
|
||||
parseObject: parseObj,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ export default async function getResultsFromExtensions ({ media, episode, batch,
|
|||
throw new Error('No torrent sources configured. Add extensions in settings.')
|
||||
}
|
||||
|
||||
debug(`Fetching sources for ${media.id}:${media.title.userPreferred} ${episode} ${batch} ${movie} ${resolution}`)
|
||||
debug(`Fetching sources for ${media?.id}:${media?.title?.userPreferred} ${episode} ${batch} ${movie} ${resolution}`)
|
||||
|
||||
const aniDBMeta = await ALToAniDB(media)
|
||||
const anidbAid = aniDBMeta?.mappings?.anidb_id
|
||||
|
|
@ -60,7 +60,7 @@ export default async function getResultsFromExtensions ({ media, episode, batch,
|
|||
|
||||
const { results, errors } = await worker.query(options, { movie, batch }, settings.value.sources)
|
||||
|
||||
debug(`Found ${results.length} results`)
|
||||
debug(`Found ${results?.length} results`)
|
||||
|
||||
for (const error of errors) {
|
||||
debug(`Source Fetch Failed: ${error}`)
|
||||
|
|
@ -82,7 +82,7 @@ export default async function getResultsFromExtensions ({ media, episode, batch,
|
|||
|
||||
async function updatePeerCounts (entries) {
|
||||
const id = Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER).toString()
|
||||
debug(`Updating peer counts for ${entries.length} entries`)
|
||||
debug(`Updating peer counts for ${entries?.length} entries`)
|
||||
|
||||
const updated = await Promise.race([
|
||||
new Promise(resolve => {
|
||||
|
|
@ -141,14 +141,14 @@ function getRelation (list, type) {
|
|||
* @param {{episodes: any, episodeCount: number, specialCount: number}} param1
|
||||
* */
|
||||
async function ALtoAniDBEpisode ({ media, episode }, { episodes, episodeCount, specialCount }) {
|
||||
debug(`Fetching AniDB episode for ${media.id}:${media.title.userPreferred} ${episode}`)
|
||||
debug(`Fetching AniDB episode for ${media?.id}:${media?.title?.userPreferred} ${episode}`)
|
||||
if (!episode || !Object.values(episodes).length) return
|
||||
// if media has no specials or their episode counts don't match
|
||||
if (!specialCount || (media.episodes && media.episodes === episodeCount && episodes[Number(episode)])) {
|
||||
debug('No specials found, or episode count matches between AL and AniDB')
|
||||
return episodes[Number(episode)]
|
||||
}
|
||||
debug(`Episode count mismatch between AL and AniDB for ${media.id}:${media.title.userPreferred}`)
|
||||
debug(`Episode count mismatch between AL and AniDB for ${media?.id}:${media?.title?.userPreferred}`)
|
||||
const res = await anilistClient.episodeDate({ id: media.id, ep: episode })
|
||||
// TODO: if media only has one episode, and airdate doesn't exist use start/release/end dates
|
||||
const alDate = new Date((res.data.AiringSchedule?.airingAt || 0) * 1000)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export default class Parser {
|
|||
destroyed = false
|
||||
|
||||
constructor (client, file) {
|
||||
debug('Initializing parser for file: ' + file.name)
|
||||
debug('Initializing parser for file: ' + file?.name)
|
||||
this.client = client
|
||||
this.file = file
|
||||
this.metadata = new Metadata(file)
|
||||
|
|
@ -33,18 +33,18 @@ export default class Parser {
|
|||
|
||||
this.metadata.getChapters().then(chapters => {
|
||||
if (this.destroyed) return
|
||||
debug(`Found ${chapters.length} chapters`)
|
||||
debug(`Found ${chapters?.length} chapters`)
|
||||
this.client.dispatch('chapters', chapters)
|
||||
})
|
||||
|
||||
this.metadata.getAttachments().then(files => {
|
||||
if (this.destroyed) return
|
||||
debug(`Found ${files.length} attachments`)
|
||||
debug(`Found ${files?.length} attachments`)
|
||||
for (const file of files) {
|
||||
if (fontRx.test(file.filename) || file.mimetype?.toLowerCase().includes('font')) {
|
||||
const data = hex2bin(arr2hex(file.data))
|
||||
if (SUPPORTS.isAndroid && data.length > 15_000_000) {
|
||||
debug('Skipping large font file on Android: ' + file.filename)
|
||||
debug('Skipping large font file on Android: ' + file?.filename)
|
||||
continue
|
||||
}
|
||||
this.client.dispatch('file', data)
|
||||
|
|
@ -64,7 +64,7 @@ export default class Parser {
|
|||
cb(this.metadata.parseStream(iterator))
|
||||
})
|
||||
} else {
|
||||
debug('Unsupported file format: ' + this.file.name)
|
||||
debug('Unsupported file format: ' + this.file?.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class RSSMediaManager {
|
|||
|
||||
const res = await Promise.all(await results)
|
||||
const newReleases = res.filter(({ date }) => date > oldDate)
|
||||
debug(`Found ${newReleases.length} new releases, notifying...`)
|
||||
debug(`Found ${newReleases?.length} new releases, notifying...`)
|
||||
|
||||
for (const { media, parseObject, episode } of newReleases) {
|
||||
const options = {
|
||||
|
|
@ -132,7 +132,7 @@ class RSSMediaManager {
|
|||
try {
|
||||
res.episodeData = (await getEpisodeMetadataForMedia(res.media))?.[res.episode]
|
||||
} catch (e) {
|
||||
debug(`Warn: failed fetching episode metadata for ${res.media.title.userPreferred} episode ${res.episode}: ${e.stack}`)
|
||||
debug(`Warn: failed fetching episode metadata for ${res.media.title?.userPreferred} episode ${res.episode}: ${e.stack}`)
|
||||
}
|
||||
}
|
||||
res.date = items[i].date
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ export default class TorrentClient extends WebTorrent {
|
|||
}
|
||||
|
||||
async torrentReady (torrent) {
|
||||
debug('Got torrent metadata: ' + torrent.name)
|
||||
debug('Got torrent metadata: ' + torrent?.name)
|
||||
const files = torrent.files.map(file => {
|
||||
return {
|
||||
infoHash: torrent.infoHash,
|
||||
|
|
@ -196,7 +196,7 @@ export default class TorrentClient extends WebTorrent {
|
|||
const subfiles = files.filter(file => {
|
||||
return subRx.test(file.name) && (videoFiles.length === 1 ? true : file.name.includes(videoName))
|
||||
})
|
||||
debug(`Found ${subfiles.length} subtitle files`)
|
||||
debug(`Found ${subfiles?.length} subtitle files`)
|
||||
for (const file of subfiles) {
|
||||
const data = await file.arrayBuffer()
|
||||
if (targetFile !== this.current) return
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@
|
|||
}
|
||||
|
||||
async function handleFiles (files) {
|
||||
debug(`Got ${files.length} files`, fileListToDebug(files))
|
||||
debug(`Got ${files?.length} files`, fileListToDebug(files))
|
||||
if (!files?.length) return processed.set(files)
|
||||
let videoFiles = []
|
||||
const otherFiles = []
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
if (nowPlaying.episode) videoFiles[0].media.episode = nowPlaying.episode
|
||||
}
|
||||
|
||||
debug(`Resolved ${videoFiles.length} video files`, fileListToDebug(videoFiles))
|
||||
debug(`Resolved ${videoFiles?.length} video files`, fileListToDebug(videoFiles))
|
||||
|
||||
if (!nowPlaying) {
|
||||
nowPlaying = findPreferredPlaybackMedia(videoFiles)
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@
|
|||
$: autoPlay(best, $settings.rssAutoplay)
|
||||
|
||||
$: lookup.catch(err => {
|
||||
debug(`Error fetching torrents for ${search.media.title.userPreferred} Episode ${search.episode}, ${err.stack}`)
|
||||
debug(`Error fetching torrents for ${search.media?.title?.userPreferred} Episode ${search.episode}, ${err.stack}`)
|
||||
toast.error(`No torrent found for ${anilistClient.title(search.media)} Episode ${search.episode}!`, { description: err.message })
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue