Skip to content

Commit

Permalink
Fix dl
Browse files Browse the repository at this point in the history
  • Loading branch information
BochilGaming committed Feb 21, 2022
1 parent da8229b commit be3274b
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "./lib/@types/index.d.ts",
"scripts": {
"test": "npm run build:test && mocha --timeout 50000 ./lib/**/**/test.js",
"build": "npm i --ignore-script && npm run build:all && npm run build:types",
"build": "npm run build:all && npm run build:types",
"build:all": "tsc",
"build:types": "tsc --p ./tsconfig.types.json",
"build:test": "tsc --p tsconfig.test.json",
Expand Down
31 changes: 31 additions & 0 deletions src/others/idff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import got from 'got'
import { ScraperError } from '../utils'
import type { NameFreeFire } from './types'

export default async function nameFreeFire(id: string | number): Promise<NameFreeFire> {
id = id.toString()
const json: any = await got('https://api.duniagames.co.id/api/transaction/v1/top-up/inquiry/store', {
headers: {
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
origin: 'https://duniagames.co.id',
referer: 'https://duniagames.co.id/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
},
body: JSON.stringify({
catalogId: 66,
gameId: id,
itemId: 11,
paymentId: 750,
productId: 3,
product_ref: "AE",
product_ref_denom: "AE"
}),
method: 'POST'
}).json()
if (json.status.message !== 'success') throw new ScraperError(`Can't get nameFreeFire for id ${id}\n${JSON.stringify(json, null, 2)}`)
return {
id: json.data.gameId,
username: json.data.userNameGame
}
}
4 changes: 3 additions & 1 deletion src/others/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import wikipedia from "./wikipedia";
import jadwalTV, { jadwalTVNow, listJadwalTV } from "./jadwal-tv";
import kbbi from "./KBBI";
import nameFreeFire from "./idff";

export * from "./minecraft";
export * from "./mediafire"
Expand All @@ -12,5 +13,6 @@ export * from "./minecraft"
export {
wikipedia,
jadwalTV, jadwalTVNow, listJadwalTV,
kbbi
kbbi,
nameFreeFire
};
23 changes: 19 additions & 4 deletions src/others/mediafire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@ export async function mediafiredl(url: string): Promise<Mediafire> {
const $ = cheerio.load(data)
const Url = $('#downloadButton').attr('href').trim()
const url2 = $('#download_link > a.retry').attr('href').trim()
const filename = $('div.dl-info > div.intro > div.filename').text().trim()
const aploud = $('div.dl-info > ul.details > li').eq(1).find('span').text().trim()
const filesizeH = $('div.dl-info > ul.details > li').eq(0).find('span').text().trim()
const filesize = parseFloat(filesizeH) * (/GB/i.test(filesizeH) ? 1000000 : /MB/i.test(filesizeH) ? 1000 : /KB/i.test(filesizeH) ? 1 : /B/i.test(filesizeH) ? 0.1 : 0)
const $intro = $('div.dl-info > div.intro')
const filename = $intro.find('div.filename').text().trim()
const filetype = $intro.find('div.filetype > span').eq(0).text().trim()
const ext = /\(\.(.*?)\)/.exec($intro.find('div.filetype > span').eq(1).text())?.[1]?.trim()
const $li = $('div.dl-info > ul.details > li')
const aploud = $li.eq(1).find('span').text().trim()
const filesizeH = $li.eq(0).find('span').text().trim()
const filesize = parseFloat(filesizeH) * (
/GB/i.test(filesizeH) ?
1000000 :
/MB/i.test(filesizeH) ?
1000 :
/KB/i.test(filesizeH) ?
1 :
/B/i.test(filesizeH) ?
0.1 : 0
)
return {
url: Url,
url2,
filename,
filetype,
ext,
aploud,
filesizeH,
filesize,
Expand Down
13 changes: 13 additions & 0 deletions src/others/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
lyricsv2,
kbbi,
statusJava,
nameFreeFire
} from './index'

describe('Others', () => {
Expand Down Expand Up @@ -82,6 +83,8 @@ describe('Others', () => {
expect(res.url).to.be.a('string')
expect(res.url2).to.be.a('string')
expect(res.filename).to.be.a('string')
expect(res.filetype).to.be.a('string')
expect(res.ext).to.be.a('string')
expect(res.aploud).to.be.a('string')
expect(res.filesizeH).to.be.a('string')
expect(res.filesize).to.be.a('number')
Expand Down Expand Up @@ -206,4 +209,14 @@ describe('Others', () => {
return done()
}).catch(done)
})

it('ID Free Fire', done => {
nameFreeFire('821587717').then(res => {
expect(res).to.be.an('object')
expect(res.username).to.be.a('string')
expect(res.id).to.be.a('string')

return done()
}).catch(done)
})
})
32 changes: 29 additions & 3 deletions src/others/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export interface Mediafire {
url: string;
url2: string;
filename: string;
filetype: string;
ext: string;
aploud: string;
filesizeH: string;
filesize: number

filesize: number;
}

export interface Gempa {
Expand Down Expand Up @@ -90,7 +91,7 @@ interface Iresponse {
}

export interface MinecraftJava {
// generate types from return function minecraftJava in minecraft.ts

ip: string;
port: number;
description: string;
Expand All @@ -107,4 +108,29 @@ export interface MinecraftJava {
favicon?: string;
ping: number;
originalResponse: Iresponse;
}

export interface NameFreeFire {
id: string;
username: string;
}

export interface BioskopNow {
title: string;
img: string;
url: string;
genre: string;
duration: string;
playingAt: string;
}

export interface Bioskop {
title: string;
img: string;
url: string;
genre: string;
duration: string;
release: string;
director: string;
cast: string;
}
47 changes: 27 additions & 20 deletions src/social-media/facebook.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import cheerio from "cheerio";
import got from "got";
import { randomBytes } from "../encryptions/crypto";
import { ScraperError } from "../utils";
import {
ScraperError,
decodeSnapApp
} from "../utils";
import {
FacebookDownloader,
FacebookDownloaderV2,
Expand Down Expand Up @@ -41,7 +44,7 @@ export async function facebookdl(url: string): Promise<FacebookDownloader> {
rand: randomBytes(13),
},
}).json();
const result: FacebookDownloader["result"] = a
const result: FacebookDownloader['result'] = (a || [])
.concat(av)
.concat(v)
.map(({ size, ext, url, quality, vcodec, fid }) => {
Expand All @@ -58,7 +61,7 @@ export async function facebookdl(url: string): Promise<FacebookDownloader> {
isAudio: /audio/i.test(quality) || (isVideo && !isWebm),
};
// ext webm video without audio
});
})
if (!result.length) throw new ScraperError(`Can't download!\n${JSON.stringify({ id, thumbnail, duration, a, av, v }, null, 2)}`)
return {
id,
Expand All @@ -70,36 +73,38 @@ export async function facebookdl(url: string): Promise<FacebookDownloader> {

export async function facebookdlv2(url: string): Promise<FacebookDownloaderV2> {
const params: { url: string } = {
url: url,
url: encodeURI(url),
};
const res: { data: string; error: boolean } = await got
const res = await got
.post("https://snapsave.app/action.php", {
headers: {
accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"content-type": "application/x-www-form-urlencoded",
cookie:
"PHPSESSID=8bp3pmf9b22vm9ihvuv6pn1h3d; current_language=id; _ga=GA1.2.5314845.1641630867; _gid=GA1.2.1966536698.1641630867; _gat=1; __gads=ID=66279abc1ad9d914-226d4524bccf00f8:T=1641630868:RT=1641630868:S=ALNI_MbL7LSCkGI6VwO33W7V6VkOozebNg; __atuvc=1%7C1; __atuvs=61d94c9354d617a5000; __atssc=google%3B1",
origin: "https://snapsave.app",
referer: "https://snapsave.app/id",
referer: "https://snapsave.app/",
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/96.0.4664.110 Safari/537.36",
},
form: params,
searchParams: {
lang: "id",
},
})
.json();

if (res.error) throw new ScraperError(JSON.stringify(res));
form: params
}).text();
const decodeParams = res.split('))</script>')[0]
.split('decodeURIComponent(escape(r))}(')[1]
?.split(',')?.map(v => v.replace(/^"/, '')
.replace(/"$/, '').trim());
const decode = decodeSnapApp(...decodeParams);
const html = decode?.split('("download-section").innerHTML = "')[1]
?.split('; parent.document.getElementById("inputData").remove();')[0]
?.split('</style><section class=')[1].split('"> ')
?.slice(1)?.map(v => (v + '">').trim()).join()
?.split('</section><div class=')[0]?.replace(/\\(\\)?/g, '');
let result: FacebookDownloaderV2["result"] = [];
const $ = cheerio.load(res.data);
const $ = cheerio.load(html);
$("table.table > tbody > tr").each(function () {
const el = $(this).find("td");
if (/tidak/i.test(el.eq(1).text())) {
if (/tidak|no/i.test(el.eq(1).text())) {
const quality = el.eq(0).text().split("(")?.[0]?.trim();
const url = el.eq(2).find("a[href]").attr("href");
result.push({ quality, url });
Expand All @@ -110,7 +115,9 @@ export async function facebookdlv2(url: string): Promise<FacebookDownloaderV2> {
id: $("div.media-content > div.content > p > strong")
.text()
.split("#")?.[1]
?.trim(),
?.trim() || '',
title: $('div.media-content > div.content > p > strong').text(),
description: $('div.media-content > div.content > p > span.video-des').text(),
thumbnail: $("figure > p.image > img[src]").attr("src"),
result,
};
Expand Down Expand Up @@ -159,4 +166,4 @@ export async function facebookdlv3(url: string): Promise<FacebookDownloaderV3> {
thumbnail,
result
}
}
}
39 changes: 23 additions & 16 deletions src/social-media/instagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
InstagramStoryv2,
InstagramStalk
} from "./types";
import { ScraperError } from "../utils";
import { ScraperError, decodeSnapApp } from "../utils";

export async function instagramdl(url: string): Promise<InstagramDownloader[]> {
if (!/https?:\/\/www\.instagram\.com\/(reel|tv|p)\//i.test(url))
Expand All @@ -17,33 +17,40 @@ export async function instagramdl(url: string): Promise<InstagramDownloader[]> {
const data = await got
.post("https://snapinsta.app/action.php", {
form: {
url,
url: encodeURI(url),
action: "post",
},
headers: {
'content-type': 'application/x-www-form-urlencoded',
origin: "https://snapinsta.app",
referer: "https://snapinsta.app/",
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36",
},
})
.text();
const $ = cheerio.load(data);
const params = data.split('))</script>')[0]
.split('decodeURIComponent(escape(r))}(')[1]
?.split(',').map(v => v.replace(/^"/, '')
.replace(/"$/, '').trim());
const decode = decodeSnapApp(...params)
const html = decode?.split('("div_download").innerHTML = "')?.[1]
.split('"; parent.document.getElementById("hero-section").remove();')[0]
.split('</style> <section class=')[1].split('"> ')[1]
?.split(' </section> ')[0].replace(/\\(\\)?/g, '');
const $ = cheerio.load(html);
let results: InstagramDownloader[] = [];
$(".row.download-box > div").each(function () {
const thumbnail = Buffer.from(
$(this)
.find(".download-items__thumb > img[src]")
.attr("src")
?.split(";base64,")[1],
"base64"
);
$(".row.download-box > div.col-md-4").each(function () {
let thumbnail = $(this)
.find(".download-items__thumb > img[src]")
.attr("src")
if (!/https?:\/\//i.test(thumbnail)) thumbnail = "https://snapinsta.app" + thumbnail
let url = $(this).find(".download-items__btn > a[href]").attr("href");
if (!/https?:\/\//i.test(url))
url = encodeURI("https://snapinsta.app" + url);
results.push({ thumbnail, url });
});
if (!results.length) throw new ScraperError(`Can't download!\n${$.html()}`)
if (!results.length) throw new ScraperError(`Can't download!\n${decode}`)
return results;
}

Expand Down Expand Up @@ -120,7 +127,6 @@ export async function instagramdlv3(url: string): Promise<InstagramDownloaderV2[
submit: ""
}, headers: Headers = {
"content-type": "application/x-www-form-urlencoded",
// cookie: "",
origin: "https://instasave.website",
referer: "https://instasave.website/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
Expand Down Expand Up @@ -193,13 +199,14 @@ export async function instagramdlv4(url: string): Promise<InstagramDownloaderV4[
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
},
searchParams: new URLSearchParams(
Object.entries(payload) as string[][]
Object.entries(payload) as [string, string][]
),
}).json()
const json: {
images_links: InstagramDownloaderV4[];
videos_links: InstagramDownloaderV4[]
} = JSON.parse(data)
if (!(json.images_links.length || json.videos_links.length)) throw new ScraperError(`Can't download!\n${JSON.stringify(json, null, 2)}`)
return [
...json.images_links,
...json.videos_links
Expand All @@ -217,7 +224,7 @@ export async function instagramStory(name: string): Promise<InstagramStory> {
params.b = i
data = await got('https://www.insta-stories.net/data.php', {
searchParams: new URLSearchParams(
Object.entries(params) as string[][]
Object.entries(params) as [string, string][]
),
headers: {
Cookie: '__gads=ID=a0129f64c017a213-2229f80500d0003f:T=1642402102:RT=1642402102:S=ALNI_MYpfNSDYSzzQdpadtBXJczU1ZrfKQ; FCNEC=[["AKsRol8c44yP5_EyHSe8zIa4WwUMzK96oz8pPcTILK6NBeERGaGQTAoVdmG95d2DWhkj71HeAJEKMBmudTLabT_7FubgP2ES5eiqmI3458TB2AL6HSJtR0c7ZUiC3c8K-Da1kNJD5dKtON5UulOJWOsEO3tS1zERdA=="],null,[]]',
Expand Down Expand Up @@ -362,4 +369,4 @@ export async function instagramStalk(username: string): Promise<InstagramStalk>
followingH,
following,
}
}
}
Loading

0 comments on commit be3274b

Please sign in to comment.