Skip to content

Commit

Permalink
add allLinksHub and appDrive resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
mnsrulz committed Aug 18, 2024
1 parent 52e0533 commit 0aa7ed4
Show file tree
Hide file tree
Showing 10 changed files with 807 additions and 46 deletions.
744 changes: 717 additions & 27 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@
"@typescript-eslint/parser": "^6.10.0",
"ava": "^5.2.0",
"eslint": "^8.53.0",
"nodemon": "^3.0.1",
"ts-node": "^10.9.1",
"nodemon": "^3.1.4",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.2.2"
"tsx": "^4.17.0",
"typescript": "^5.5.4"
},
"scripts": {
"lint": "eslint . --ext .ts",
"test": "ava",
"build": "tsc",
"build:watch": "tsc -w",
"prepublishOnly": "tsc",
"start:debug": "nodemon -I --exec DEBUG=nurl* node --experimental-specifier-resolution=node --loader ts-node/esm src/app.debug.ts"
"start:debug": "nodemon -I --exec DEBUG=nurl* node --import=tsx src/app.debug.ts"
},
"ava": {
"typescript": {
Expand Down
4 changes: 3 additions & 1 deletion src/allResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ export * from "./libs/extraPlay.js";
export * from "./libs/streamvid.js";
export * from "./libs/uploadingSite.js";
export * from './libs/hubCloudDriveResolver.js';
export * from './libs/cloudFlareStorage.js';
export * from './libs/cloudFlareStorage.js';
export * from './libs/allLinksHub.js';
export * from './libs/appDrive.js';
21 changes: 21 additions & 0 deletions src/libs/allLinksHub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { BaseUrlResolver, ResolvedMediaItem } from "../BaseResolver.js";



export class AllLinksHubResolver extends BaseUrlResolver {
constructor() {
super({
domains: [/https?:\/\/link\.allinkshub/],
useCookies: true
});
}
async resolveInner(_urlToResolve: string): Promise<ResolvedMediaItem | ResolvedMediaItem[]> {
const responsev1 = await this.gotInstance(_urlToResolve);
const al = this.parseAllLinks(responsev1.body, '.entry-content');
return al.map(m => {
const link = this.nodeatob(new URL(m.link).searchParams.get('id') || '');
const title = m.title;
return { link, title, parent: _urlToResolve } as ResolvedMediaItem;
});
}
}
43 changes: 43 additions & 0 deletions src/libs/appDrive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { BaseUrlResolver, ResolvedMediaItem } from "../BaseResolver.js";

export class AppDriveResolver extends BaseUrlResolver {
constructor() {
super({
domains: [/https?:\/\/appdrive/],
useCookies: true
});
}
async resolveInner(_urlToResolve: string): Promise<ResolvedMediaItem | ResolvedMediaItem[]> {
const initialResponse = await this.gotInstance(_urlToResolve);
const canonicalUrl = initialResponse.url;
const keyRegex = /"key", "([^"]*)"/;
const rxvalue = keyRegex.exec(initialResponse.body);
const key = rxvalue?.[1];

const resp2 = await this.gotInstance.post(canonicalUrl, {
form: {
action: 'direct',
key: key,
action_token: ''
},
headers: {
'x-token': new URL(canonicalUrl).hostname,
'Referer': canonicalUrl
}
}).json<{ url: string; }>();

const resp3 = await this.gotInstance(resp2.url);
const gdlink = this.scrapeLinkHref(resp3.body, '#gdlink');
const urlRegex = /worker_url\s*=\s*'(https:\/\/[^']+)'/;
const rx3respo = urlRegex.exec(resp3.body);
const workersDev = rx3respo?.[1];
const linksToReturn = [];
if (gdlink) {
linksToReturn.push({ link: gdlink, title: 'workers', parent: _urlToResolve } as ResolvedMediaItem);
}
if (workersDev) {
linksToReturn.push({ link: workersDev, title: 'drive', parent: _urlToResolve } as ResolvedMediaItem);
}
return linksToReturn;
}
}
15 changes: 6 additions & 9 deletions src/libs/gdrive.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { BaseUrlResolver, ResolvedMediaItem } from "../BaseResolver.js";
import { CookieJar } from 'tough-cookie';
import { parseGoogleFileId } from "../utils/helper.js";
export class GDriveResolver extends BaseUrlResolver {
private googleDriveId: string;
constructor() {
super({
domains: [/https?:\/\/(drive|docs)\.google\.com/],
domains: [/https?:\/\/(drive|docs|drive\.usercontent)\.google\.com/],
speedRank: 99
});
this.googleDriveId = '';
Expand All @@ -13,14 +14,10 @@ export class GDriveResolver extends BaseUrlResolver {
async resolveInner(_urlToResolve: string): Promise<ResolvedMediaItem[]> {
const links = [];

const rx0 = /(drive|docs)\.google\.com\/open\?id=(.*)/
const rx1 = /(drive|docs)\.google\.com\/file\/d\/(.*?)\//
const rx2 = /(drive|docs)\.google\.com\/uc\?id=(.*?)&/

const regexresult = rx0.exec(_urlToResolve) || rx1.exec(_urlToResolve) || rx2.exec(_urlToResolve)
if (regexresult) {
const normalizeDriveUrl = `https://drive.google.com/uc?id=${regexresult[2]}&export=download`;
this.googleDriveId = regexresult[2];
const googleDriveId = parseGoogleFileId(_urlToResolve)
if (googleDriveId) {
const normalizeDriveUrl = `https://drive.google.com/uc?id=${googleDriveId}&export=download`;
this.googleDriveId = googleDriveId;
const cookieJar = new CookieJar();
const response = await this.gotInstance(normalizeDriveUrl, {
cookieJar,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/gdriveV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class gDriveV2Resolver extends BaseUrlResolver {
private googleDriveId: string | null;
constructor() {
super({
domains: [/https?:\/\/(drive|docs)\.google\.com/],
domains: [/https?:\/\/(drive|docs|drive\.usercontent)\.google\.com/],
speedRank: 99
});
this.googleDriveId = '';
Expand Down
12 changes: 9 additions & 3 deletions src/libs/saveLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ export class SaveLinksResolver extends BaseUrlResolver {
const canonicalUrl = new URL(_urlToResolve);
canonicalUrl.hostname = 'savelinks.me';
const responsev1 = await this.gotInstance(canonicalUrl.href);
const fomruploadresp = await this.postHiddenForm(responsev1.url, responsev1.body);
const obj1: { links: ResolvedMediaItem[]; } = this.scrapeHtml(fomruploadresp, {
let c = '';

if (this.getHiddenForm(responsev1.body)) {
c = await this.postHiddenForm(responsev1.url, responsev1.body);
} else {
c = responsev1.body;
}
const obj1: { links: ResolvedMediaItem[]; } = this.scrapeHtml(c, {
links: {
listItem: '.view-well a',
data: {
Expand All @@ -23,4 +29,4 @@ export class SaveLinksResolver extends BaseUrlResolver {
});
return obj1.links;
}
}
}
1 change: 1 addition & 0 deletions src/tests/helper.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ test('google drive parse links', t => {
t.is(parseGoogleFileId('https://drive.google.com/u/0/uc?id=1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT&export=download'), '1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT');
t.is(parseGoogleFileId('https://drive.google.com/u/0/uc?id=1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT'), '1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT');
t.is(parseGoogleFileId('https://drive.google.com/file/d/1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT/view'), '1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT');
t.is(parseGoogleFileId('https://drive.usercontent.google.com/download?export=download&id=1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT'), '1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT');
t.is(parseGoogleFileId('https://drives.othergoogle.com/file/d/1EBDCCsIy12HwE4II6-KKKsVSL_FFFFFT/view'), null);
});
2 changes: 1 addition & 1 deletion src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface ScrapedAnchorElement {

export const parseGoogleFileId = (_url: string) => {
const u = new URL(_url);
if (/(drive|docs)\.google\.com/.test(u.hostname)) {
if (/(drive|docs|drive\.usercontent)\.google\.com/.test(u.hostname)) {
if (u.pathname.startsWith('/file/d')) {
return u.pathname.split('/')[3] || null;
} else if (u.searchParams.get('id')) {
Expand Down

0 comments on commit 0aa7ed4

Please sign in to comment.