Skip to content
This repository was archived by the owner on Oct 19, 2019. It is now read-only.

Commit 92fb560

Browse files
committed
linting changes; removed debug
1 parent 902f712 commit 92fb560

File tree

8 files changed

+77
-31
lines changed

8 files changed

+77
-31
lines changed

lib/HosterScrapper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import { Scrapper } from './Scrapper';
55
export type HosterScrapperExec = (args: any) => HosterInfo | Promise<HosterInfo | null> | null;
66

77
export class HosterScrapper extends Scrapper {
8-
constructor({ name, domain, runner, runnerOptions= {}, exec }:
9-
{ name: string, domain?: string[] | string, runner: Runner | string, runnerOptions?: any, exec: HosterScrapperExec }) {
8+
constructor({ name, domain, runner, runnerOptions= {}, exec }: {
9+
name: string,
10+
domain?: string[] | string,
11+
runner: Runner | string,
12+
runnerOptions?: any,
13+
exec: HosterScrapperExec
14+
}) {
1015
super({
1116
name,
1217
type: 'link',

lib/Runner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Info } from './Info';
22
import { ScrapperExec } from './Scrapper';
33

4-
export type RunnerFunction = (o: {url: string, scrapper: ScrapperExec, options: any}) => Info | Promise<Info | null> | null;
4+
export type RunnerFunction =
5+
(o: {url: string, scrapper: ScrapperExec, options: any}) => Info | Promise<Info | null> | null;
56

67
export class Runner {
78
public type: string;

lib/SourceInfo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export class SourceInfo extends Info {
2222
return _private.get(this).poster;
2323
}
2424
set poster(value: string | undefined) {
25-
(_private.get(this) || _private.set(this, {}).get(this)).poster = typeof value === 'undefined' ? value : normalizeUrl(value);
25+
(_private.get(this) || _private.set(this, {}).get(this)).poster =
26+
typeof value === 'undefined' ? value : normalizeUrl(value);
2627
}
2728

2829
public toJSON(): object {

lib/SourceScrapper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import { SourceInfo } from './SourceInfo';
55
export type SourceScrapperExec = (args: any) => SourceInfo | Promise<SourceInfo | null> | null;
66

77
export class SourceScrapper extends Scrapper {
8-
constructor({ name, domain, runner, runnerOptions, exec }:
9-
{ name: string, domain?: string[] | string, runner: Runner | string, runnerOptions?: any, exec: SourceScrapperExec }) {
8+
constructor({ name, domain, runner, runnerOptions, exec }: {
9+
name: string,
10+
domain?: string[] | string,
11+
runner: Runner | string,
12+
runnerOptions?: any,
13+
exec: SourceScrapperExec
14+
}) {
1015
super({
1116
name,
1217
type: 'source',

lib/extensions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ RegExp.prototype.execAll = function(str: string): any[] {
2020
return arr;
2121
};
2222

23-
Array.prototype.flatMap = function<T1, T2>(lambda: (currentValue: T1, index: number, array: T1[]) => T2[], thisArg?: any): T2[] {
23+
Array.prototype.flatMap = function<T1, T2>(
24+
lambda: (currentValue: T1, index: number, array: T1[]) => T2[],
25+
thisArg?: any): T2[] {
2426
return Array.prototype.concat.apply([], this.map(lambda, thisArg));
2527
};

lib/runners.ts

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@ declare interface RunnerArgs<RunnerScrapper> {
1616
scrapper: RunnerScrapper;
1717
options?: any;
1818
}
19-
export type PuppeteerRunnerScrapper =
20-
(args: { url: string, browser: Browser, page: Page, scrapper: PuppeteerRunnerScrapper, runners: RunnerList }) => any;
21-
const puppeteerRunner = new Runner('puppeteer', async ({url, scrapper, options= {}}: RunnerArgs<PuppeteerRunnerScrapper>) => {
19+
20+
export type PuppeteerRunnerScrapper = (args: {
21+
url: string,
22+
browser: Browser,
23+
page: Page,
24+
scrapper: PuppeteerRunnerScrapper,
25+
runners: RunnerList
26+
}) => any;
27+
const puppeteerRunner = new Runner('puppeteer',
28+
async ({url, scrapper, options= {}}: RunnerArgs<PuppeteerRunnerScrapper>) => {
2229
let _options: any = {
2330
config: {
2431
headless: false
2532
},
2633
requestInterception: {
2734
active: true,
28-
block: ({ request }:
29-
{ request: any, resourceType: string, url: string, page: any, browser: any }) => request.resourceType === 'font'
35+
block: ({ request }: { request: any, resourceType: string, url: string, page: any, browser: any }) =>
36+
request.resourceType === 'font'
3037
},
3138
init: null
3239
};
@@ -42,13 +49,16 @@ const puppeteerRunner = new Runner('puppeteer', async ({url, scrapper, options=
4249

4350
await page.setRequestInterception(_options.requestInterception && _options.requestInterception.active);
4451
page.on('request', (request: any) => {
45-
const block = _options.requestInterception && _options.requestInterception.block && _options.requestInterception.block({
46-
request,
47-
resourceType: request.resourceType(),
48-
url: request.url(),
49-
page,
50-
browser
51-
});
52+
const block =
53+
_options.requestInterception &&
54+
_options.requestInterception.block &&
55+
_options.requestInterception.block({
56+
request,
57+
resourceType: request.resourceType(),
58+
url: request.url(),
59+
page,
60+
browser
61+
});
5262

5363
if (typeof block === 'undefined') {
5464
return;
@@ -86,9 +96,15 @@ const puppeteerRunner = new Runner('puppeteer', async ({url, scrapper, options=
8696
await browser.close();
8797
}
8898
});
89-
export type HTMLRunnerScrapper =
90-
(args: { url: string, html: string, response: any, scrapper: HTMLRunnerScrapper, runners: RunnerList }) => any;
91-
const htmlRunner = new Runner('html', async ({url, scrapper, options= {}}: RunnerArgs<HTMLRunnerScrapper>) => {
99+
export type HTMLRunnerScrapper = (args: {
100+
url: string,
101+
html: string,
102+
response: any,
103+
scrapper: HTMLRunnerScrapper,
104+
runners: RunnerList
105+
}) => any;
106+
const htmlRunner = new Runner('html',
107+
async ({url, scrapper, options= {}}: RunnerArgs<HTMLRunnerScrapper>) => {
92108
let _options: any = {
93109
config: {url,
94110
method: 'get',
@@ -111,9 +127,17 @@ const htmlRunner = new Runner('html', async ({url, scrapper, options= {}}: Runne
111127
runners
112128
});
113129
});
114-
export type DOMRunnerScrapper =
115-
(args: { url: string, dom: any, parser: any, html: string, response: any, scrapper: DOMRunnerScrapper, runners: RunnerList }) => any;
116-
const domRunner = new Runner('dom', async ({url, scrapper, options= {}}: RunnerArgs<DOMRunnerScrapper>) => {
130+
export type DOMRunnerScrapper = (args: {
131+
url: string,
132+
dom: any,
133+
parser: any,
134+
html: string,
135+
response: any,
136+
scrapper: DOMRunnerScrapper,
137+
runners: RunnerList
138+
}) => any;
139+
const domRunner = new Runner('dom',
140+
async ({url, scrapper, options= {}}: RunnerArgs<DOMRunnerScrapper>) => {
117141
return htmlRunner.run({
118142
url,
119143
scrapper: async (args) => {
@@ -126,8 +150,13 @@ const domRunner = new Runner('dom', async ({url, scrapper, options= {}}: RunnerA
126150
options
127151
});
128152
});
129-
export type UrlRunnerScrapper = (args: { url: string, scrapper: UrlRunnerScrapper, runners: RunnerList }) => any;
130-
const urlRunner = new Runner('url', async ({url, scrapper, options= {}}: RunnerArgs<UrlRunnerScrapper>) => {
153+
export type UrlRunnerScrapper = (args: {
154+
url: string,
155+
scrapper: UrlRunnerScrapper,
156+
runners: RunnerList
157+
}) => any;
158+
const urlRunner = new Runner('url',
159+
async ({url, scrapper, options= {}}: RunnerArgs<UrlRunnerScrapper>) => {
131160
return scrapper({
132161
url,
133162
scrapper,

lib/scrappers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,12 @@ export const scrappers = {
191191
domain: 'vidstreaming.io',
192192
runner: 'html',
193193
exec: async ({html}) => {
194-
const titleregex = new RegExp(/<title>([^<]+)<\/title>/);
195-
const setupregex = new RegExp(/playerInstance\.setup\(\s*{\s*sources\s*:\s*\[\s*{\s*(.*?)\s*}\s*]\s*,?\s*}\s*\);/, 'gi');
196-
const loadregex = new RegExp(/playerInstance\.load\(\s*{\s*(.*?)\s*,?\s*}\s*\)\s*;/, 'gi');
194+
const titleregex =
195+
new RegExp(/<title>([^<]+)<\/title>/);
196+
const setupregex =
197+
new RegExp(/playerInstance\.setup\({\s*sources\s*:\s*\[\s*{\s*(.*?)\s*}\s*]\s*,?\s*}\);/, 'gi');
198+
const loadregex =
199+
new RegExp(/playerInstance\.load\({\s*(.*?)\s*,?\s*}\)\s*;/, 'gi');
197200

198201
html = removeNewline(html);
199202

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"arrow-parens": false,
1313
"no-conditional-assignment": false,
1414
"variable-name": false,
15-
"max-line-length": [true, 140],
15+
"max-line-length": [true, 120],
1616
"interface-name": false,
1717
"curly": false,
1818
"no-console": false,

0 commit comments

Comments
 (0)