OhMyDitzzy commited on
Commit
81ee18d
·
1 Parent(s): 22bf4eb

Add instagram downloader

Browse files
src/server/plugins/downloader/instagram.js ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import axios from "axios";
2
+ import { sendSuccess, ErrorResponses } from "../../lib/response-helper.js";
3
+
4
+ class Instagram {
5
+ constructor() {
6
+ this.API_URL = "https://thesocialcat.com/api/instagram-download";
7
+ this.HEADERS = {
8
+ "accept": "*/*",
9
+ "accept-language": "id-ID",
10
+ "content-type": "application/json",
11
+ "Referer": "https://thesocialcat.com/tools/instagram-video-downloader",
12
+ "Referrer-Policy": "strict-origin-when-cross-origin"
13
+ };
14
+
15
+ this.CREATED_BY = "Ditzzy";
16
+ this.NOTE = "Thank you for using this scrape, I hope you appreciate me for making this scrape by not deleting wm";
17
+ }
18
+
19
+ wrapResponse(data) {
20
+ return {
21
+ created_by: this.CREATED_BY,
22
+ note: this.NOTE,
23
+ results: data
24
+ };
25
+ }
26
+
27
+ async download(url) {
28
+ try {
29
+ const config = {
30
+ url: this.API_URL,
31
+ headers: this.HEADERS,
32
+ method: "POST",
33
+ data: {
34
+ url
35
+ }
36
+ };
37
+
38
+ const { data } = await axios.request(config);
39
+ return this.wrapResponse(data);
40
+ } catch (e) {
41
+ throw new Error("Error: " + e.message);
42
+ }
43
+ }
44
+ }
45
+
46
+ /** @type {import("../../types/plugin").ApiPluginHandler} */
47
+ const handler = {
48
+ name: "Instagram Downloader",
49
+ description: "Download Instagram Media, Support Photo too",
50
+ version: "1.0.0",
51
+ method: "GET",
52
+ category: ["downloader"],
53
+ alias: ["instagram", "ig"],
54
+ tags: ["social-media", "video", "downloader"],
55
+ parameters: {
56
+ query: [
57
+ {
58
+ name: "url",
59
+ type: "string",
60
+ required: true,
61
+ description: "Your Instagram URL",
62
+ example: "https://www.instagram.com/reel/DS1kGwOkU3T/?igsh=MWVyOW50ODhnOXFpYw=="
63
+ }
64
+ ],
65
+ body: [],
66
+ headers: []
67
+ },
68
+ responses: {
69
+ 200: {
70
+ status: 200,
71
+ description: "Successfully retrieved Instagram data",
72
+ example: {
73
+ status: 200,
74
+ author: "Ditzzy",
75
+ note: "Thank you for using this API!",
76
+ results: {}
77
+ }
78
+ },
79
+ 400: {
80
+ status: 400,
81
+ description: "Invalid Instagram URL provided",
82
+ example: {
83
+ status: 400,
84
+ message: "Invalid URL - must be a valid Instagram URL"
85
+ }
86
+ },
87
+ 404: {
88
+ status: 404,
89
+ description: "Missing required parameter",
90
+ example: {
91
+ status: 404,
92
+ message: "Missing required parameter: ..."
93
+ }
94
+ },
95
+ 500: {
96
+ status: 500,
97
+ description: "Server error or Instagram API unavailable",
98
+ example: {
99
+ status: 500,
100
+ message: "An error occurred, please try again later."
101
+ }
102
+ }
103
+ },
104
+ exec: async (req, res) => {
105
+ const { url } = req.query
106
+
107
+ if (!url) return ErrorResponses.missingParameter(res, "url");
108
+
109
+ const regex = /(?:(?:http|https):\/\/)?(?:www.)?(?:instagram.com|instagr.am)\/([A-Za-z0-9-_]+)/im;
110
+
111
+ if (!regex.test(url)) return ErrorResponses.invalidUrl(res, "Invalid URL - must be a valid Instagram URL");
112
+
113
+ const ig = new Instagram();
114
+ try {
115
+ const download = await ig.download(url);
116
+
117
+ return sendSuccess(res, download.results);
118
+ } catch (e) {
119
+ console.error("Instagram download error:", e);
120
+ return ErrorResponses.serverError(res);
121
+ }
122
+ }
123
+ }
124
+
125
+ export default handler;