instagrapi
Advanced tools
Comparing version 4.2.2 to 5.0.0
@@ -7,2 +7,3 @@ export declare type TConfig = { | ||
username: string; | ||
name: string; | ||
image: { | ||
@@ -15,3 +16,2 @@ standard: string; | ||
following: number; | ||
name: string; | ||
biography: string; | ||
@@ -44,13 +44,6 @@ externalUrl: string; | ||
qtyComments: number; | ||
media: Array<TMedia>; | ||
author: { | ||
username: string; | ||
image: string; | ||
qtyPosts: number; | ||
followers: number; | ||
name: string; | ||
isVerified: boolean; | ||
isPrivate: boolean; | ||
}; | ||
lastComments: Array<TComment>; | ||
gallery: Array<TMedia>; | ||
author: TAuthor; | ||
coauthors: Array<TAuthor>; | ||
previewComments: Array<TComment>; | ||
location: null | { | ||
@@ -61,3 +54,6 @@ country: string | null; | ||
street: string | null; | ||
zipCode: string | null; | ||
coordinates: { | ||
lat: number; | ||
lng: number; | ||
}; | ||
}; | ||
@@ -67,19 +63,20 @@ date: string; | ||
export declare type TVideo = { | ||
url: string; | ||
type: string | 'clips' | 'igtv' | 'feed'; | ||
views: number | null; | ||
url: TQualities; | ||
type: 'feed' | 'clips' | 'carousel_container'; | ||
duration: number; | ||
audio: boolean | { | ||
views?: number | null; | ||
audio?: { | ||
artist: string; | ||
song: string; | ||
}; | ||
song: string | null; | ||
} | null; | ||
}; | ||
export declare type TMedia = { | ||
image: { | ||
standard: string; | ||
hd: string; | ||
}; | ||
image: TQualities; | ||
video: TVideo | null; | ||
taggedUsers: Array<TTagged>; | ||
}; | ||
export declare type TQualities = { | ||
standard: string; | ||
hd: string; | ||
}; | ||
export declare type TTagged = { | ||
@@ -89,18 +86,17 @@ image: string; | ||
isVerified: boolean; | ||
coordinates: { | ||
x: number; | ||
y: number; | ||
}; | ||
position: Array<number>; | ||
}; | ||
export declare type TComment = { | ||
content: string; | ||
author: { | ||
username: string; | ||
image: string; | ||
isVerified: boolean; | ||
}; | ||
author: TAuthor; | ||
likes: number; | ||
responses: Array<TComment>; | ||
isSpam: boolean; | ||
date: string; | ||
}; | ||
export declare type TAuthor = { | ||
username: string; | ||
name: string; | ||
image: string; | ||
isVerified: boolean; | ||
isPrivate: boolean; | ||
}; |
@@ -1,2 +0,2 @@ | ||
export { TProfile, TLastPosts, TPost, TMedia, TVideo, TTagged, TComment } from './entities/types.js'; | ||
export * from './entities/types.js'; | ||
export { Instagrapi } from './services/InstagramApi.service'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Instagrapi = void 0; | ||
__exportStar(require("./entities/types.js"), exports); | ||
var InstagramApi_service_1 = require("./services/InstagramApi.service"); | ||
Object.defineProperty(exports, "Instagrapi", { enumerable: true, get: function () { return InstagramApi_service_1.Instagrapi; } }); |
@@ -61,3 +61,3 @@ "use strict"; | ||
case 1: | ||
user = (_a.sent()).user; | ||
user = (_a.sent()).graphql.user; | ||
profile = { | ||
@@ -99,3 +99,3 @@ username: user.username, | ||
case 1: | ||
user = (_a.sent()).user; | ||
user = (_a.sent()).graphql.user; | ||
edges = user.edge_owner_to_timeline_media.edges; | ||
@@ -129,90 +129,80 @@ lastPosts = edges.map(function (_a) { | ||
InstagramApiService.prototype.getPost = function (postUrl) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var media_1, children, images, user, commentList, post, error_3; | ||
var item_1, carouselMedia, candidates, user, coauthors, commentList, post, error_3; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_b.trys.push([0, 2, , 3]); | ||
_a.trys.push([0, 2, , 3]); | ||
return [4, this.request.api(postUrl)]; | ||
case 1: | ||
media_1 = (_b.sent()).shortcode_media; | ||
children = ((_a = media_1.edge_sidecar_to_children) === null || _a === void 0 ? void 0 : _a.edges) || []; | ||
if (children.length) | ||
children.shift(); | ||
images = media_1.display_resources; | ||
user = media_1.owner; | ||
commentList = media_1.edge_media_to_parent_comment.edges; | ||
item_1 = (_a.sent()).items[0]; | ||
carouselMedia = item_1.carousel_media; | ||
candidates = carouselMedia ? carouselMedia[0].image_versions2.candidates : item_1.image_versions2.candidates; | ||
user = item_1.user; | ||
coauthors = item_1.coauthor_producers; | ||
commentList = item_1.comments; | ||
post = { | ||
postUrl: _UTILS_1.GeneralUtil.getPostUrl(media_1.shortcode), | ||
image: { | ||
standard: this.proxy + images.shift().src, | ||
hd: this.proxy + images.pop().src | ||
}, | ||
video: media_1.is_video | ||
postUrl: _UTILS_1.GeneralUtil.getPostUrl(item_1.code), | ||
image: _UTILS_1.InstragramUtil.getMediaQualities(candidates, this.proxy), | ||
video: item_1.video_versions | ||
? { | ||
url: this.proxy + media_1.video_url, | ||
type: media_1.product_type, | ||
views: media_1.video_view_count, | ||
duration: media_1.video_duration, | ||
audio: media_1.clips_music_attribution_info | ||
? { | ||
artist: media_1.clips_music_attribution_info.artist_name, | ||
song: media_1.clips_music_attribution_info.song_name | ||
} | ||
: media_1.has_audio | ||
url: _UTILS_1.InstragramUtil.getMediaQualities(item_1.video_versions, this.proxy), | ||
type: item_1.product_type, | ||
views: item_1.view_count, | ||
duration: item_1.video_duration, | ||
audio: _UTILS_1.InstragramUtil.getAudioData(item_1) | ||
} | ||
: null, | ||
content: _UTILS_1.InstragramUtil.getCaption(media_1), | ||
likes: media_1.edge_media_preview_like.count, | ||
qtyComments: media_1.edge_media_to_parent_comment.count, | ||
media: children.map(function (_a) { | ||
var sidecar = _a.node; | ||
var images = sidecar.display_resources; | ||
var taggeds = sidecar.edge_media_to_tagged_user.edges; | ||
return { | ||
image: { | ||
standard: _this.proxy + images.shift().src, | ||
hd: _this.proxy + images.pop().src | ||
}, | ||
video: sidecar.is_video | ||
? { | ||
url: _this.proxy + sidecar.video_url, | ||
type: media_1.product_type, | ||
views: sidecar.video_view_count, | ||
duration: media_1.video_duration, | ||
audio: sidecar.has_audio | ||
} | ||
: null, | ||
taggedUsers: taggeds.map(function (_a) { | ||
var tagged = _a.node; | ||
return ({ | ||
image: _this.proxy + tagged.user.profile_pic_url, | ||
name: tagged.user.full_name, | ||
isVerified: tagged.user.is_verified, | ||
coordinates: { | ||
x: tagged.x, | ||
y: tagged.y | ||
content: item_1.caption.text, | ||
likes: item_1.like_count, | ||
qtyComments: item_1.comment_count, | ||
gallery: carouselMedia | ||
? carouselMedia.map(function (media) { | ||
var _a; | ||
var _b = _UTILS_1.InstragramUtil.getMediaQualities(media.image_versions2.candidates, _this.proxy), standard = _b.standard, hd = _b.hd; | ||
var taggeds = (_a = media.usertags) === null || _a === void 0 ? void 0 : _a.in; | ||
return { | ||
image: { standard: standard, hd: hd }, | ||
video: media.video_versions | ||
? { | ||
url: _UTILS_1.InstragramUtil.getMediaQualities(media.video_versions, _this.proxy), | ||
type: item_1.product_type, | ||
duration: media.video_duration | ||
} | ||
}); | ||
}) | ||
}; | ||
}), | ||
: null, | ||
taggedUsers: taggeds | ||
? taggeds.map(function (tag) { return ({ | ||
image: _this.proxy + tag.user.profile_pic_url, | ||
name: tag.user.full_name, | ||
isVerified: tag.user.is_verified, | ||
position: tag.position | ||
}); }) | ||
: [] | ||
}; | ||
}) | ||
: [], | ||
author: { | ||
username: user.username, | ||
name: user.full_name, | ||
image: this.proxy + user.profile_pic_url, | ||
qtyPosts: user.edge_owner_to_timeline_media.count, | ||
followers: user.edge_followed_by.count, | ||
name: user.full_name, | ||
isVerified: user.is_verified, | ||
isPrivate: user.is_private | ||
}, | ||
lastComments: _UTILS_1.InstragramUtil.getComments(commentList, this.proxy), | ||
location: media_1.location ? _UTILS_1.InstragramUtil.getLocation(media_1.location.address_json) : null, | ||
date: _UTILS_1.GeneralUtil.msToDate(media_1.taken_at_timestamp) | ||
coauthors: coauthors | ||
? coauthors.map(function (author) { return ({ | ||
username: author.username, | ||
name: author.full_name, | ||
image: _this.proxy + author.profile_pic_url, | ||
isPrivate: author.is_private, | ||
isVerified: author.is_verified | ||
}); }) | ||
: [], | ||
previewComments: _UTILS_1.InstragramUtil.getComments(commentList, this.proxy), | ||
location: _UTILS_1.InstragramUtil.getLocation(item_1.location), | ||
date: _UTILS_1.GeneralUtil.msToDate(item_1.taken_at) | ||
}; | ||
return [2, post]; | ||
case 2: | ||
error_3 = _b.sent(); | ||
error_3 = _a.sent(); | ||
_UTILS_1.GeneralUtil.logger('GET-POST', error_3); | ||
@@ -219,0 +209,0 @@ throw new Error('Post url not found'); |
export declare class RequestService { | ||
private id; | ||
constructor(id: string); | ||
api(query: string): Promise<TResponseApi['graphql']>; | ||
api<R = TProfileApi | TPostApi>(query: string): Promise<R>; | ||
} |
@@ -51,32 +51,21 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var isUrl, endpoint, headers, _a, status_1, data, error_1; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
var isUrl, endpoint, data, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
isUrl = query.search(/^(https?)/) > -1; | ||
if (isUrl) { | ||
endpoint = query; | ||
headers = {}; | ||
} | ||
else { | ||
endpoint = "".concat(_UTILS_1.configApi.urlBase, "/").concat(query); | ||
headers = { | ||
cookie: "sessionid=".concat(this.id) | ||
}; | ||
} | ||
_b.label = 1; | ||
endpoint = (isUrl ? query : "".concat(_UTILS_1.configApi.urlBase, "/").concat(query)) + '/?__a=1'; | ||
_a.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
return [4, axios_1.default.get("".concat(endpoint, "/?__a=1"), { headers: headers })]; | ||
_a.trys.push([1, 3, , 4]); | ||
return [4, axios_1.default.get(endpoint, { | ||
headers: { | ||
cookie: "sessionid=".concat(this.id) | ||
} | ||
})]; | ||
case 2: | ||
_a = _b.sent(), status_1 = _a.status, data = _a.data; | ||
if (status_1 === 200) | ||
return [2, data.graphql]; | ||
else { | ||
_UTILS_1.GeneralUtil.logger('WARN-REQUEST', data); | ||
throw new Error('Status incorrect in request api'); | ||
} | ||
return [3, 4]; | ||
data = (_a.sent()).data; | ||
return [2, data]; | ||
case 3: | ||
error_1 = _b.sent(); | ||
error_1 = _a.sent(); | ||
_UTILS_1.GeneralUtil.logger('ERROR-REQUEST', error_1); | ||
@@ -83,0 +72,0 @@ throw error_1; |
@@ -18,6 +18,6 @@ "use strict"; | ||
if (_UTILS_1.configApi.devMode) { | ||
if (typeof event === 'string' || 'object') | ||
console.log(title + ':', event); | ||
if (typeof event === 'object') | ||
console.error("".concat(title, ": ").concat((event === null || event === void 0 ? void 0 : event.message) || '')); | ||
else | ||
console.error(title + ':', event.message); | ||
console.log("".concat(title, ": ").concat(event)); | ||
} | ||
@@ -24,0 +24,0 @@ }; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,6 +0,8 @@ | ||
import { TComment, TPost } from '../entities/types.js'; | ||
import { TComment, TPost, TQualities, TVideo } from '../entities/types.js'; | ||
export declare class InstragramUtil { | ||
static getCaption(media: TEdgeMedia['node'] | TPostApi['graphql']['shortcode_media']): string | null; | ||
static getComments(commentList: Array<TEdgeComment> | undefined, proxy: string): TComment[]; | ||
static getLocation(addressJson: string): TPost['location']; | ||
static getCaption(media: TEdgeMedia['node']): string | null; | ||
static getComments(commentList: TCommentsApi, proxy: string): TComment[]; | ||
static getLocation(location?: TLocationApi): TPost['location'] | null; | ||
static getMediaQualities(media: Array<TMediaApi>, proxy: string): TQualities; | ||
static getAudioData(item: TPostApi['items'][0]): TVideo['audio'] | null; | ||
} |
@@ -16,7 +16,4 @@ "use strict"; | ||
if (commentList === null || commentList === void 0 ? void 0 : commentList.length) { | ||
return commentList.map(function (_a) { | ||
var _b; | ||
var comment = _a.node; | ||
var user = comment.owner; | ||
var commentList = (_b = comment.edge_threaded_comments) === null || _b === void 0 ? void 0 : _b.edges; | ||
return commentList.map(function (comment) { | ||
var user = comment.user; | ||
return { | ||
@@ -26,7 +23,8 @@ content: comment.text, | ||
username: user.username, | ||
name: user.full_name, | ||
image: proxy + user.profile_pic_url, | ||
isVerified: user.is_verified | ||
isVerified: user.is_verified, | ||
isPrivate: user.is_private | ||
}, | ||
likes: comment.edge_liked_by.count, | ||
responses: InstragramUtil.getComments(commentList, proxy), | ||
likes: comment.comment_like_count, | ||
isSpam: comment.did_report_as_spam, | ||
@@ -40,15 +38,50 @@ date: general_util_1.GeneralUtil.msToDate(comment.created_at) | ||
}; | ||
InstragramUtil.getLocation = function (addressJson) { | ||
var address = JSON.parse(addressJson); | ||
var location = { | ||
country: address.country_code || null, | ||
region: address.region_name || null, | ||
city: address.city_name || null, | ||
street: address.street_address || null, | ||
zipCode: address.zip_code || null | ||
InstragramUtil.getLocation = function (location) { | ||
if (location) { | ||
var _a = location.name.split(','), region = _a[0], country = _a[1]; | ||
var locationWrapper = { | ||
country: (country === null || country === void 0 ? void 0 : country.trim()) || null, | ||
region: region || null, | ||
city: location.city || null, | ||
street: location.address || null, | ||
coordinates: { | ||
lat: location.lat, | ||
lng: location.lng | ||
} | ||
}; | ||
return locationWrapper; | ||
} | ||
else | ||
return null; | ||
}; | ||
InstragramUtil.getMediaQualities = function (media, proxy) { | ||
var _a; | ||
var imageWidth480 = (_a = media.find(function (img) { return img.width === 480; })) === null || _a === void 0 ? void 0 : _a.url; | ||
return { | ||
standard: proxy + (imageWidth480 || media.pop().url), | ||
hd: proxy + media.shift().url | ||
}; | ||
return location; | ||
}; | ||
InstragramUtil.getAudioData = function (item) { | ||
var _a, _b; | ||
if (item === null || item === void 0 ? void 0 : item.has_audio) { | ||
var audioUser = (_a = item.clips_metadata) === null || _a === void 0 ? void 0 : _a.original_sound_info; | ||
var audioArtist = (_b = item.clips_metadata) === null || _b === void 0 ? void 0 : _b.music_info; | ||
if (audioUser) { | ||
return { | ||
artist: audioUser.ig_artist.full_name, | ||
song: null | ||
}; | ||
} | ||
else if (audioArtist) { | ||
return { | ||
artist: audioArtist.music_consumption_info.ig_artist.full_name, | ||
song: audioArtist.music_asset_info.title | ||
}; | ||
} | ||
} | ||
return null; | ||
}; | ||
return InstragramUtil; | ||
}()); | ||
exports.InstragramUtil = InstragramUtil; |
{ | ||
"name": "instagrapi", | ||
"version": "4.2.2", | ||
"version": "5.0.0", | ||
"description": "Library to obtain information from an Instagram account in a friendly and intuitive way", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
"build": "yarn lint-lib && yarn clean && yarn build-ts", | ||
"start": "node dist", | ||
"start": "node server", | ||
"deploy": "gh-pages -o github -d ./demo", | ||
@@ -54,2 +54,3 @@ "serve": "live-server --host=localhost --port=80 ./demo" | ||
"dotenv": "^10.0.0", | ||
"express": "^4.17.3", | ||
"gh-pages": "^3.1.0", | ||
@@ -56,0 +57,0 @@ "jest": "^27.4.7", |
@@ -24,2 +24,4 @@ # Instagrapi | ||
> 📃 **NOTE:** In version 4.x.x the "getPost" method no longer works due to changes in the Instagram api. | ||
### 🌐 [Demo Web Site](https://edixonalberto.github.io/instagrapi) ➜ | ||
@@ -46,4 +48,2 @@ | ||
4. Get to the `application` section and then to `Cookies` and select on the right hand side `sessionId` | ||
- For chromium browsers: `application` | ||
- For firefox browsers: `storage` | ||
@@ -76,7 +76,6 @@ Now you can use the library by instantiating an object and passing the `sessionId` as an argument | ||
const post: TPost = await instagrapi.getPost('POST_URL') | ||
const comments: string[] = post.previewComments.map((comment: TComment) => comment.content) | ||
const comments: string[] = post.lastComments.map((comment: TComment) => comment.content) | ||
console.log(comments) // Preview comments of the post | ||
console.log(comments) // Last comments of the post | ||
return comments | ||
@@ -124,2 +123,3 @@ } catch (error) { | ||
username: string | ||
name: string | ||
image: { | ||
@@ -132,3 +132,2 @@ standard: string | ||
following: number | ||
name: string | ||
biography: string | ||
@@ -180,13 +179,6 @@ externalUrl: string | ||
qtyComments: number | ||
media: Array<TMedia> | ||
author: { | ||
username: string | ||
image: string | ||
qtyPosts: number | ||
followers: number | ||
name: string | ||
isVerified: boolean | ||
isPrivate: boolean | ||
} | ||
lastComments: Array<TComment> | ||
gallery: Array<TMedia> | ||
author: TAuthor | ||
coauthors: Array<TAuthor> | ||
previewComments: Array<TComment> | ||
location: null | { | ||
@@ -197,3 +189,6 @@ country: string | null | ||
street: string | null | ||
zipCode: string | null | ||
coordinates: { | ||
lat: number | ||
lng: number | ||
} | ||
} | ||
@@ -200,0 +195,0 @@ date: string |
35462
582
13
195