Skip to content

Commit

Permalink
Update Instagram video download API to use new URL format (generated…
Browse files Browse the repository at this point in the history
… by blackbox.ai )
  • Loading branch information
saiyamdubey committed Feb 13, 2024
1 parent a190b4c commit 3147cf6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
1 change: 0 additions & 1 deletion app/instagram/video/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function Searchbar({}: Props) {
console.log(data);

if (data === "link is wrong") {
// console.log("hello");
setloading(false);
toast("Check the Provided Link");
}
Expand Down
68 changes: 34 additions & 34 deletions pages/api/download.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@

import { NextApiRequest, NextApiResponse } from 'next';
// import axios from 'axios';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
let { url } = req.query;

if (typeof url === 'string') {
url = url.replace(/\?utm_source=ig_web_copy_link$/, '');
url = url.replace(/\?hl=en$/, '');
url = url.replace(/\?igsh=MWNqM3Jkemx0ZGNpaA==$/, '');
url = url.replace(/\/[^/]*$/, '');
url = url + process.env.SECRET_KEY;
console.log(url)
}

try {
console.log("hello")
const response = await fetch(url as string);

const data = await response.json();
res.status(200).send(data);
} catch (error) {
res.status(500).send('error');
}
}


// import { NextApiRequest, NextApiResponse } from 'next';
// import axios from 'axios';

// export default async function handler(req: NextApiRequest, res: NextApiResponse) {
// let { url } = req.query;
Expand All @@ -9,44 +36,17 @@
// url = url.replace(/\?hl=en$/, '');
// url = url.replace(/\?igsh=MWNqM3Jkemx0ZGNpaA==$/, '');
// url = url.replace(/\/[^/]*$/, '');
// url = url + process.env.SECRET_KEY;
// url = url + "/?__a=1&__d=dis";
// console.log(url)
// }

// try {

// const response = await fetch(url as string);

// const data = await response.json();
// res.status(200).send(data);
// const response = await axios.get(url as string);
// console.log(response.data)
// const data = response.data;
// res.status(200).json(data);
// } catch (error) {
// res.status(500).send('error');
// console.error(error);
// res.status(500).json({ error: 'Internal Server Error' });
// }
// }


import { NextApiRequest, NextApiResponse } from 'next';
import axios from 'axios';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
let { url } = req.query;

if (typeof url === 'string') {
url = url.replace(/\?utm_source=ig_web_copy_link$/, '');
url = url.replace(/\?hl=en$/, '');
url = url.replace(/\?igsh=MWNqM3Jkemx0ZGNpaA==$/, '');
url = url.replace(/\/[^/]*$/, '');
url = url + "/?__a=1&__d=dis";
console.log(url)
}

try {
const response = await axios.get(url as string);
console.log(response.data)
const data = response.data;
res.status(200).json(data);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal Server Error' });
}
}

1 comment on commit 3147cf6

@vercel
Copy link

@vercel vercel bot commented on 3147cf6 Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.