Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/lib/modules/extensions/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,29 +211,38 @@ export const extensions = new class Extensions {

debug(`Checking ${extensions.size} extensions for ${media.id}:${media.title?.userPreferred} ${episode} ${resolution} ${checkMovie ? 'movie' : ''} ${checkBatch ? 'batch' : ''}`)

const extensionPromises: Array<Promise<void>> = []

for (const [id, worker] of extensions.entries()) {
const thisExtOpts = extopts[id]!
if (!thisExtOpts.enabled) continue
if (configs[id]!.type !== 'torrent') continue
try {
const promises: Array<Promise<TorrentResult[]>> = []
promises.push(worker.single(options, thisExtOpts.options))
if (checkMovie) promises.push(worker.movie(options, thisExtOpts.options))
if (checkBatch) promises.push(worker.batch(options, thisExtOpts.options))

for (const result of await Promise.allSettled(promises)) {
if (result.status === 'fulfilled') {
results.push(...result.value.map(v => ({ ...v, extension: new Set([id]), parseObject: {} as unknown as AnitomyResult })))
} else {
console.error(result.reason, id)
errors.push({ error: result.reason as unknown as Error, extension: id })

const extensionPromise = (async () => {
try {
const promises: Array<Promise<TorrentResult[]>> = []
promises.push(worker.single(options, thisExtOpts.options))
if (checkMovie) promises.push(worker.movie(options, thisExtOpts.options))
if (checkBatch) promises.push(worker.batch(options, thisExtOpts.options))

for (const result of await Promise.allSettled(promises)) {
if (result.status === 'fulfilled') {
results.push(...result.value.map(v => ({ ...v, extension: new Set([id]), parseObject: {} as unknown as AnitomyResult })))
} else {
console.error(result.reason, id)
errors.push({ error: result.reason as unknown as Error, extension: id })
}
}
} catch (error) {
errors.push({ error: error as Error, extension: id })
}
} catch (error) {
errors.push({ error: error as Error, extension: id })
}
})()

extensionPromises.push(extensionPromise)
}

await Promise.all(extensionPromises)

try {
const library = await native.library()
const entry = library.find(lib => lib.mediaID === media.id && lib.episode === episode)
Expand Down