fix: use downr.org to download from instagram source
This commit is contained in:
parent
ce11004de9
commit
a0d87153ea
37
apps/bot/src/utils/client.ts
Normal file
37
apps/bot/src/utils/client.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import { wrapper } from 'axios-cookiejar-support';
|
||||||
|
import * as tough from 'tough-cookie';
|
||||||
|
|
||||||
|
const jar = new tough.CookieJar();
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
accept: '*/*',
|
||||||
|
// 'accept-language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
|
||||||
|
'content-type': 'application/json',
|
||||||
|
dnt: '1',
|
||||||
|
priority: 'u=1, i',
|
||||||
|
'sec-ch-ua': '"Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
|
||||||
|
'sec-ch-ua-mobile': '?0',
|
||||||
|
'sec-ch-ua-platform': '"Windows"',
|
||||||
|
'sec-fetch-dest': 'empty',
|
||||||
|
'sec-fetch-mode': 'cors',
|
||||||
|
'sec-fetch-site': 'same-origin',
|
||||||
|
'sec-gpc': '1',
|
||||||
|
'user-agent':
|
||||||
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getClient = async () => {
|
||||||
|
const client = wrapper(
|
||||||
|
axios.create({
|
||||||
|
headers,
|
||||||
|
jar,
|
||||||
|
withCredentials: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// get session cookie
|
||||||
|
await client.get('https://downr.org/.netlify/functions/analytics');
|
||||||
|
|
||||||
|
return client;
|
||||||
|
};
|
||||||
@ -1,48 +1,76 @@
|
|||||||
import axios from 'axios';
|
import { getClient } from './client';
|
||||||
|
|
||||||
export type AuthorInfo = {
|
export type InfoRoot = {
|
||||||
avatar: string;
|
author: string;
|
||||||
id: number;
|
error: boolean;
|
||||||
nickname: string;
|
like_count: number;
|
||||||
username: string;
|
medias: Media[];
|
||||||
|
music_attribution_info: unknown;
|
||||||
|
owner: Owner;
|
||||||
|
shortcode: string;
|
||||||
|
source: string;
|
||||||
|
thumbnail: string;
|
||||||
|
time_end: number;
|
||||||
|
title: string;
|
||||||
|
type: string;
|
||||||
|
url: string;
|
||||||
|
view_count: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CarouselItem = {
|
export type Media = {
|
||||||
|
bandwidth?: number;
|
||||||
|
codec?: string;
|
||||||
|
extension: string;
|
||||||
|
frameRate: unknown;
|
||||||
|
id: string;
|
||||||
|
is_audio: boolean;
|
||||||
|
mimeType?: string;
|
||||||
|
quality: string;
|
||||||
|
resolution?: string;
|
||||||
|
thumbnail?: string;
|
||||||
type: string;
|
type: string;
|
||||||
url: string;
|
url: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Root = {
|
export type Owner = {
|
||||||
authorInfo: AuthorInfo;
|
__typename: string;
|
||||||
caption: string;
|
ai_agent_owner_username: unknown;
|
||||||
carouselItems: CarouselItem[];
|
friendship_status: unknown;
|
||||||
id: number;
|
id: string;
|
||||||
mediaUrls: string[];
|
is_private: boolean;
|
||||||
type: string;
|
is_unpublished: boolean;
|
||||||
url: string;
|
is_verified: boolean;
|
||||||
|
pk: string;
|
||||||
|
profile_pic_url: string;
|
||||||
|
show_account_transparency_details: boolean;
|
||||||
|
transparency_label: unknown;
|
||||||
|
transparency_product: unknown;
|
||||||
|
transparency_product_enabled: boolean;
|
||||||
username: string;
|
username: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function getInstagramDownloadUrl(url: string) {
|
export async function getInstagramDownloadUrl(url: string) {
|
||||||
const { data } = await axios.post<Root>('https://thesocialcat.com/api/instagram-download', {
|
const client = await getClient();
|
||||||
|
// fetch video info
|
||||||
|
const { data } = await client.post<InfoRoot>('https://downr.org/.netlify/functions/nyt', {
|
||||||
url,
|
url,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!data) throw new Error('err-invalid-instagram-response');
|
if (!data) throw new Error('err-invalid-instagram-response');
|
||||||
|
|
||||||
const isVideo = data.type === 'video' || !data.carouselItems.length;
|
const video = data.medias.find((media) => media.type === 'video');
|
||||||
|
|
||||||
if (isVideo) {
|
if (video) {
|
||||||
return {
|
return {
|
||||||
caption: data.caption,
|
caption: data.title,
|
||||||
images: [],
|
images: [],
|
||||||
play: data.mediaUrls.at(0),
|
play: video.url,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
caption: data.caption,
|
caption: data.title,
|
||||||
images: data.mediaUrls,
|
images: data.medias.map((media) => media.url),
|
||||||
play: undefined,
|
play: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,34 +1,5 @@
|
|||||||
|
import { getClient } from './client';
|
||||||
import { MAX_VIDEO_DURATION_SECONDS } from '@/constants/limits';
|
import { MAX_VIDEO_DURATION_SECONDS } from '@/constants/limits';
|
||||||
import axios from 'axios';
|
|
||||||
import { wrapper } from 'axios-cookiejar-support';
|
|
||||||
import * as tough from 'tough-cookie';
|
|
||||||
|
|
||||||
const jar = new tough.CookieJar();
|
|
||||||
|
|
||||||
const headers = {
|
|
||||||
accept: '*/*',
|
|
||||||
'accept-language': 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
|
|
||||||
'content-type': 'application/json',
|
|
||||||
dnt: '1',
|
|
||||||
priority: 'u=1, i',
|
|
||||||
'sec-ch-ua': '"Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
|
|
||||||
'sec-ch-ua-mobile': '?0',
|
|
||||||
'sec-ch-ua-platform': '"Windows"',
|
|
||||||
'sec-fetch-dest': 'empty',
|
|
||||||
'sec-fetch-mode': 'cors',
|
|
||||||
'sec-fetch-site': 'same-origin',
|
|
||||||
'sec-gpc': '1',
|
|
||||||
'user-agent':
|
|
||||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
|
|
||||||
};
|
|
||||||
|
|
||||||
const client = wrapper(
|
|
||||||
axios.create({
|
|
||||||
headers,
|
|
||||||
jar,
|
|
||||||
withCredentials: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
export type DownloadRoot = {
|
export type DownloadRoot = {
|
||||||
duration: number;
|
duration: number;
|
||||||
@ -54,10 +25,8 @@ export type Media = {
|
|||||||
const qualityOrder = ['144p', '240p', '360p', '480p', '1080p', '720p'].reverse();
|
const qualityOrder = ['144p', '240p', '360p', '480p', '1080p', '720p'].reverse();
|
||||||
|
|
||||||
export async function getYoutubeDownloadUrl(url: string) {
|
export async function getYoutubeDownloadUrl(url: string) {
|
||||||
// get session cookie
|
const client = await getClient();
|
||||||
await client.get('https://downr.org/.netlify/functions/analytics');
|
// fetch info
|
||||||
|
|
||||||
// fetch video info
|
|
||||||
const { data: infoData } = await client.post<InfoRoot>(
|
const { data: infoData } = await client.post<InfoRoot>(
|
||||||
'https://downr.org/.netlify/functions/video-info',
|
'https://downr.org/.netlify/functions/video-info',
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user