-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
88 lines (68 loc) · 2.21 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
const got = require('got');
const user = require('./user.js');
const highDefinition = username => {
if (typeof username !== 'string') {
throw new TypeError(`Expected a string, got ${typeof username}`);
}
return user(username).then(userid => {
const url = `https://i.instagram.com/api/v1/users/${userid}/info/`;
return got(url, {json: true}).then(res => {
return res.body.user.hd_profile_pic_url_info.url;
});
});
};
const instaProfileImage = module.exports = username => highDefinition(username);
instaProfileImage.regular = username => {
if (typeof username !== 'string') {
throw new TypeError(`Expected a string, got ${typeof username}`);
}
return user(username).then(userid => {
const url = `https://i.instagram.com/api/v1/users/${userid}/info/`;
return got(url, {json: true}).then(res => {
return res.body.user.hd_profile_pic_versions[1].url;
}).catch(err => {
if (err) {
return {
error: 'The requested size is currently not available'
};
}
});
});
};
instaProfileImage.medium = username => {
if (typeof username !== 'string') {
throw new TypeError(`Expected a string, got ${typeof username}`);
}
const url = `https://www.instagram.com/${username}`;
return got(url).then(res => {
return res.body.split(',"profile_pic_url_hd":"')[1].split('",')[0];
});
};
instaProfileImage.small = username => {
if (typeof username !== 'string') {
throw new TypeError(`Expected a string, got ${typeof username}`);
}
const url = `https://www.instagram.com/${username}`;
return got(url).then(res => {
return res.body.split('"profile_pic_url":"')[1].split('",')[0] || '';
});
};
instaProfileImage.image = source => {
if (typeof source !== 'string') {
throw new TypeError(`Expected a string, got ${typeof source}`);
}
const url = source.split('?')[0];
return got(`${url}?__a=1`, {json: true}).then(res => {
return res.body.graphql.shortcode_media.display_url || '';
});
};
instaProfileImage.video = source => {
if (typeof source !== 'string') {
throw new TypeError(`Epxected a string, got ${typeof source}`);
}
const url = source.split('?')[0];
return got(`${url}?__a=1`, {json: true}).then(res => {
return res.body.graphql.shortcode_media.video_url || '';
});
};