fix(provider): linting eslint rules

This commit is contained in:
hansputera
2021-11-07 19:48:18 +07:00
parent 7127d7685b
commit 96ce6c7e48
2 changed files with 60 additions and 55 deletions

View File

@@ -24,4 +24,4 @@ export const tikmateFetch = got.extend({
export const musicalyFetch = got.extend({
prefixUrl: 'https://musicaldown.com/id',
dnsCache: true,
});
});

View File

@@ -1,74 +1,79 @@
import { musicalyFetch } from '..';
import { handleException } from '../decorators';
import { BaseProvider, ExtractedInfo } from './baseProvider';
import {musicalyFetch} from '..';
import {handleException} from '../decorators';
import {BaseProvider, ExtractedInfo} from './baseProvider';
/**
* @class MusicalyDown
*/
export class MusicalyDown extends BaseProvider {
/**
*
* @returns {string}
/**
*
* @return {string}
*/
public resourceName() {
return 'musicalydown';
}
public resourceName(): string {
return 'musicalydown';
}
/**
* @return {string}
*/
public getURI(): string {
return musicalyFetch.defaults.options.prefixUrl;
}
/**
* @returns {string}
*/
public getURI() {
return musicalyFetch.defaults.options.prefixUrl;
}
/**
*
*
* @param {string} url - Video Tiktok URL
* @returns {string}
* @return {string}
*/
@handleException()
public async fetch(url: string): Promise<ExtractedInfo> {
let headers = {
"Accept": "*/*",
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
};
let res = await musicalyFetch('./', {
headers
});
let form = {} as any;
let tokens = (res.body.match(/input name="([^"]+)/gi) as string[]).map(x => x.split("\"").pop() as string);
let token_value = (res.body.match(/type="hidden" value="(.*?)"/gi) as string[])[0].split(/=/g).pop()?.replace(/\"/g, '');
let value = [url, token_value as string, "1"];
for (let x in tokens) {
form[tokens[x]] = value[x];
}
let cookie = res.headers['set-cookie']?.toString();
const response = await musicalyFetch.post("./download", {
form,
headers: {
cookie,
...headers
},
method: 'POST'
}).text();
return this.extract(response);
public async fetch(url: string): Promise<ExtractedInfo> {
const headers = {
'Accept': '*/*',
};
const res = await musicalyFetch('./', {
headers,
});
const form = {} as Record<string, string>;
const tokens = (res.body.match(/input name="([^"]+)/gi) as string[])
.map((x) => x.split('"').pop() as string);
const token = (
res.body.match(/type="hidden" value="(.*?)"/gi) as string[])[0]
.split(/=/g).pop()?.replace(/\"/g, '');
const value = [url, token as string, '1'];
// eslint-disable-next-line guard-for-in
for (const tok in tokens) {
form[tokens[tok]] = value[tok];
}
const cookie = res.headers['set-cookie']?.toString();
const response = await musicalyFetch.post('./download', {
form,
headers: {
cookie,
...headers,
},
method: 'POST',
}).text();
return this.extract(response);
}
/**
*
*
* @param {string} html - Raw HTML
* @return {ExtractedInfo}
*/
public extract(html: string): ExtractedInfo {
let thumb = /img class="responsive-img" src="(.*?)"/gi.exec(html)?.[1];
let match_urls = (html.match(/<a.*?target="_blank".*?href="(.*?)".*?<\/a>/gi) as string[]);
let urls = match_urls.map(url => /<a.*?target="_blank".*?href="(.*?)".*?<\/a>/gi.exec(url)?.[1] as string);
return {
error: undefined,
result: {
urls,
thumb
}
};
const thumb = /img class="responsive-img" src="(.*?)"/gi.exec(html)?.[1];
const matchUrls = (html
.match(/<a.*?target="_blank".*?href="(.*?)".*?<\/a>/gi) as string[]);
const urls = matchUrls.map((url) =>
/<a.*?target="_blank".*?href="(.*?)".*?<\/a>/gi.exec(url)?.[1] as string);
return {
error: undefined,
result: {
urls,
thumb,
},
};
}
}