-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (53 loc) · 1.82 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const axios = require('axios');
const readline = require('readline');
const fs = require('fs');
const path = require('path');
// Creating readline interface to get user input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Asking for Instagram username using readline
rl.question('Please enter the Instagram username: ', (username) => {
// Instagram API endpoint and user agent
const apiUrl = `https://i.instagram.com/api/v1/users/web_profile_info/?username=${username}`;
const userAgent = "Instagram 337.0.0.0.77 Android (28/9; 420dpi; 1080x1920; samsung; SM-G611F; on7xreflte; samsungexynos7870; en_US; 493419337)";
// Sending request with Axios
axios.get(apiUrl, {
headers: {
'User-Agent': userAgent
}
})
.then(response => {
// If request successful, process the response
const profilePicUrlHD = response.data.data.user.profile_pic_url_hd;
const fileName = `${username}.jpg`;
const folderPath = path.join(__dirname, 'pfp'); // Creating path to pfp folder
// Create pfp folder if it doesn't exist
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
}
// Download and save the profile picture
axios({
url: profilePicUrlHD,
method: 'GET',
responseType: 'stream'
})
.then(response => {
const filePath = path.join(folderPath, fileName);
response.data.pipe(fs.createWriteStream(filePath));
console.log(`Profile picture successfully saved: ${fileName}`);
})
.catch(error => {
console.error('Error while downloading the image:', error.message);
});
})
.catch(error => {
// If user not found or other error, handle it
console.error('User not found or error occurred.');
})
.finally(() => {
// Close readline interface after processing
rl.close();
});
});