mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
feat: allow built-in addons to bypass title matching when needed
This commit is contained in:
@@ -18,6 +18,10 @@ export const NabAddonConfigSchema = BaseDebridConfigSchema.extend({
|
||||
});
|
||||
export type NabAddonConfig = z.infer<typeof NabAddonConfigSchema>;
|
||||
|
||||
interface SearchResultMetadata {
|
||||
searchType: 'id' | 'query';
|
||||
}
|
||||
|
||||
export abstract class BaseNabAddon<
|
||||
C extends NabAddonConfig,
|
||||
A extends BaseNabApi<'torznab' | 'newznab'>,
|
||||
@@ -27,11 +31,15 @@ export abstract class BaseNabAddon<
|
||||
protected async performSearch(
|
||||
parsedId: ParsedId,
|
||||
metadata: SearchMetadata
|
||||
): Promise<SearchResultItem<A['namespace']>[]> {
|
||||
): Promise<{
|
||||
results: SearchResultItem<A['namespace']>[];
|
||||
meta: SearchResultMetadata;
|
||||
}> {
|
||||
const start = Date.now();
|
||||
const queryParams: Record<string, string> = {};
|
||||
const queryLimit = createQueryLimit();
|
||||
let capabilities: Capabilities;
|
||||
let searchType: SearchResultMetadata['searchType'] = 'id';
|
||||
try {
|
||||
capabilities = await this.api.getCapabilities();
|
||||
} catch (error) {
|
||||
@@ -118,6 +126,7 @@ export abstract class BaseNabAddon<
|
||||
addSeasonEpisode: !queryParams.season && !queryParams.ep,
|
||||
useAllTitles: useAllTitles(this.userData.url),
|
||||
});
|
||||
searchType = 'query';
|
||||
}
|
||||
let results: SearchResultItem<A['namespace']>[] = [];
|
||||
if (queries.length > 0) {
|
||||
@@ -139,7 +148,12 @@ export abstract class BaseNabAddon<
|
||||
results: results.length,
|
||||
}
|
||||
);
|
||||
return results;
|
||||
return {
|
||||
results: results,
|
||||
meta: {
|
||||
searchType,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private getSearchFunction(
|
||||
|
||||
@@ -51,7 +51,7 @@ export class NewznabAddon extends BaseNabAddon<NewznabAddonConfig, NewznabApi> {
|
||||
parsedId: ParsedId,
|
||||
metadata: SearchMetadata
|
||||
): Promise<NZB[]> {
|
||||
const results = await this.performSearch(parsedId, metadata);
|
||||
const { results, meta } = await this.performSearch(parsedId, metadata);
|
||||
const seenNzbs = new Set<string>();
|
||||
|
||||
const nzbs: NZB[] = [];
|
||||
@@ -70,6 +70,7 @@ export class NewznabAddon extends BaseNabAddon<NewznabAddonConfig, NewznabApi> {
|
||||
);
|
||||
|
||||
nzbs.push({
|
||||
confirmed: meta.searchType === 'id',
|
||||
hash: md5,
|
||||
nzb: nzbUrl,
|
||||
age: `${age}d`,
|
||||
|
||||
@@ -330,6 +330,7 @@ export class TorrentSourceHandler extends SourceHandler {
|
||||
const { results, errors } = await processTorrents(
|
||||
fetchResult.torrents.map((torrent) => ({
|
||||
...torrent,
|
||||
confirmed: true,
|
||||
type: 'torrent',
|
||||
})),
|
||||
this.services,
|
||||
@@ -557,6 +558,7 @@ export class UsenetSourceHandler extends SourceHandler {
|
||||
.filter((torrent) => torrent.nzb)
|
||||
.map((torrent) => ({
|
||||
...torrent,
|
||||
confirmed: true,
|
||||
type: 'usenet' as const,
|
||||
nzb: torrent.nzb!,
|
||||
}));
|
||||
|
||||
@@ -44,7 +44,7 @@ export class TorznabAddon extends BaseNabAddon<NabAddonConfig, TorznabApi> {
|
||||
parsedId: ParsedId,
|
||||
metadata: SearchMetadata
|
||||
): Promise<UnprocessedTorrent[]> {
|
||||
const results = await this.performSearch(parsedId, metadata);
|
||||
const { results, meta } = await this.performSearch(parsedId, metadata);
|
||||
const seenTorrents = new Set<string>();
|
||||
|
||||
const torrents: UnprocessedTorrent[] = [];
|
||||
@@ -61,6 +61,7 @@ export class TorznabAddon extends BaseNabAddon<NabAddonConfig, TorznabApi> {
|
||||
seenTorrents.add(infoHash ?? downloadUrl!);
|
||||
|
||||
torrents.push({
|
||||
confirmed: meta.searchType === 'id',
|
||||
hash: infoHash,
|
||||
downloadUrl,
|
||||
sources: result.torznab?.magneturl?.toString()
|
||||
|
||||
@@ -158,7 +158,7 @@ async function processTorrentsForDebridService(
|
||||
|
||||
const parsedTorrent = parsedFiles.get(torrent.title ?? '');
|
||||
if (metadata && parsedTorrent) {
|
||||
if (isTitleWrong(parsedTorrent, metadata)) {
|
||||
if (torrent.confirmed !== true && isTitleWrong(parsedTorrent, metadata)) {
|
||||
continue;
|
||||
}
|
||||
if (isSeasonWrong(parsedTorrent, metadata)) {
|
||||
|
||||
Reference in New Issue
Block a user