diff --git a/readme.md b/readme.md index 69cb07a..e7bffb0 100644 --- a/readme.md +++ b/readme.md @@ -65,6 +65,7 @@ In some of the sharing sites, it's required to send some header information back | timeout | number | timeout in seconds | googleDrive.apiKey | string | optional api key to avoid anonymous access. Defaults to empty to allow anonymous access. | customResolvers | array | custom resolvers you can inject for resolving urls. Refer to [app.tests](src/tests/app.tests.ts) for implementation samples +| ignoreResolvers | array | regex array you can inject to ignore executing specific resolvers. Refer to [app.tests](src/tests/app.tests.ts) for implementation samples ```js diff --git a/src/UrlResolver.ts b/src/UrlResolver.ts index e420322..99b9fa3 100644 --- a/src/UrlResolver.ts +++ b/src/UrlResolver.ts @@ -26,7 +26,9 @@ export class UrlResolver { timeout: 30 }, options); const instance = this; + const _allResolvers = _options.customResolvers ? [...this.allResolvers, ..._options.customResolvers] : this.allResolvers; + const _filteredResolvers = _allResolvers.filter(j=> !_options.ignoreResolvers?.some(r=>r.test(j.name))); let result: ResolvedMediaItem[] = []; const timeoutPromise = new Promise(resolve => setTimeout(resolve, _options.timeout * 1000)); const actualPromise = _(); @@ -36,7 +38,7 @@ export class UrlResolver { const urlsToResolve = typeof urlToResolve === "string" ? [urlToResolve] : urlToResolve; const promises: Promise[] = []; for (const iteratorurl of urlsToResolve) { - for (const resolver of _allResolvers) { + for (const resolver of _filteredResolvers) { const element = new resolver(); const promise = element.resolve(iteratorurl, _options, instance).then(resolvedItems => result = [...result, ...resolvedItems]); promises.push(promise); diff --git a/src/UrlResolverOptions.ts b/src/UrlResolverOptions.ts index 666f178..7ba3082 100644 --- a/src/UrlResolverOptions.ts +++ b/src/UrlResolverOptions.ts @@ -1,10 +1,23 @@ import { BaseUrlResolver } from "./BaseResolver.js"; export type UrlResolverOptions = { + /** + * timeout in seconds + */ timeout: number; + /** + * instruct the resolver to extract contenttype, lastmodifieddate and size of the file. + */ extractMetaInformation: boolean; + /** + * allows you to provide a custom list of resolvers. + */ customResolvers: { new(): BaseUrlResolver; }[]; googleDrive: { apiKey: string - } + }; +/** + * It's useful when you don't want to execute a list of resolvers. You can pass regular expression array. +*/ + ignoreResolvers: RegExp[] }; \ No newline at end of file diff --git a/src/libs/hdMoviesFlix.ts b/src/libs/hdMoviesFlix.ts index dddf84f..f81b635 100644 --- a/src/libs/hdMoviesFlix.ts +++ b/src/libs/hdMoviesFlix.ts @@ -5,7 +5,7 @@ import { URL } from 'url'; export class hdMoviesFlixResolver extends BaseUrlResolver { constructor() { super({ - domains: [/https?:\/\/(hdmoviesflix|moviesflix)/] + domains: [/https?:\/\/(hdmoviesflix|moviesflix|themoviesflix)/] }); } @@ -17,7 +17,7 @@ export class hdMoviesFlixResolver extends BaseUrlResolver { return [{ title: decodeUrl.host, link: decodeUrl.href } as ResolvedMediaItem]; } else { const response = await this.gotInstance(_urlToResolve); - const links = this.scrapeAllLinks(response.body, '.mb-container'); + const links = this.scrapeAllLinks(response.body, '.page-body'); return links; } } diff --git a/src/libs/linkrit.ts b/src/libs/linkrit.ts index 7b2a477..4a6b1d2 100644 --- a/src/libs/linkrit.ts +++ b/src/libs/linkrit.ts @@ -3,7 +3,7 @@ import { BaseUrlResolver, ResolvedMediaItem } from "../BaseResolver.js"; export class LinkritResolver extends BaseUrlResolver { constructor() { super({ - domains: [/https?:\/\/linkrit\.com/, /https?:\/\/extralinks/, /https?:\/\/dlink\.mobilejsr\.com/, /https?:\/\/dlinks\.dailypotrika/], + domains: [/https?:\/\/linkrit\.com/, /https?:\/\/extralinks/, /https?:\/\/(dlink\.)?mobilejsr\.com/, /https?:\/\/dlinks\.dailypotrika/], useCookies: true }); } diff --git a/src/tests/app.tests.ts b/src/tests/app.tests.ts index e6c0f3e..fccd473 100644 --- a/src/tests/app.tests.ts +++ b/src/tests/app.tests.ts @@ -33,3 +33,30 @@ test('custom resolver registration', async t => { t.is(result[0].link, resolvedFile); }); + + +test('resolver deregistration', async t => { + const resolvedFile = 'http://mylink/resolvedfile.mkv'; + class customResolver extends BaseUrlResolver { + constructor() { + super({ + domains: [/https?:\/\/(testdomain)/], + speedRank: 70 + }); + } + + async resolveInner(_urlToResolve: string): Promise { + return { + link: resolvedFile + } as ResolvedMediaItem; + } + } + + const result = await nurl.resolve('http://testdomain.com/file.mkv', { + timeout: 100, + customResolvers: [customResolver], + ignoreResolvers: [/customResolver/] + }); + + t.is(result.length, 0); +});