instagrapi
Advanced tools
Comparing version 4.1.0 to 4.2.1
export declare type TConfig = { | ||
sessionId: string; | ||
proxy?: string; | ||
}; | ||
@@ -4,0 +5,0 @@ export declare type TProfile = { |
export { TProfile, TLastPosts, TPost, TMedia, TVideo, TTagged, TComment } from './entities/types.js'; | ||
export { InstagramApiService as Instagrapi } from './services/InstagramApi.service'; | ||
export { Instagrapi } from './services/InstagramApi.service'; |
@@ -5,2 +5,2 @@ "use strict"; | ||
var InstagramApi_service_1 = require("./services/InstagramApi.service"); | ||
Object.defineProperty(exports, "Instagrapi", { enumerable: true, get: function () { return InstagramApi_service_1.InstagramApiService; } }); | ||
Object.defineProperty(exports, "Instagrapi", { enumerable: true, get: function () { return InstagramApi_service_1.Instagrapi; } }); |
import { TConfig, TProfile, TLastPosts, TPost } from '../entities/types.js'; | ||
export declare class InstagramApiService { | ||
declare class InstagramApiService { | ||
private request; | ||
private proxy; | ||
constructor(config: TConfig); | ||
@@ -9,1 +10,2 @@ getProfile(username: string): Promise<TProfile>; | ||
} | ||
export { InstagramApiService as Instagrapi }; |
@@ -39,3 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InstagramApiService = void 0; | ||
exports.Instagrapi = void 0; | ||
var Request_service_1 = require("./Request.service"); | ||
@@ -45,2 +45,8 @@ var _UTILS_1 = require("../utils/index.js"); | ||
function InstagramApiService(config) { | ||
try { | ||
this.proxy = config.proxy ? new URL('/', config.proxy).href : ''; | ||
} | ||
catch (error) { | ||
this.proxy = ''; | ||
} | ||
this.request = new Request_service_1.RequestService(config.sessionId); | ||
@@ -61,4 +67,4 @@ } | ||
image: { | ||
standard: user.profile_pic_url, | ||
hd: user.profile_pic_url_hd | ||
standard: this.proxy + user.profile_pic_url, | ||
hd: this.proxy + user.profile_pic_url_hd | ||
}, | ||
@@ -88,2 +94,3 @@ qtyPosts: user.edge_owner_to_timeline_media.count, | ||
var user, edges, lastPosts, error_2; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -101,6 +108,6 @@ switch (_a.label) { | ||
postUrl: _UTILS_1.GeneralUtil.getPostUrl(media.shortcode), | ||
image: media.display_url, | ||
image: _this.proxy + media.display_url, | ||
video: media.is_video | ||
? { | ||
url: media.video_url, | ||
url: _this.proxy + media.video_url, | ||
views: media === null || media === void 0 ? void 0 : media.video_view_count | ||
@@ -118,3 +125,3 @@ } | ||
_UTILS_1.GeneralUtil.logger('GET-LAST-POSTS', error_2); | ||
throw Error('Username not found'); | ||
throw new Error('Username not found'); | ||
case 3: return [2]; | ||
@@ -129,2 +136,3 @@ } | ||
var media_1, children, images, user, commentList, post, error_3; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
@@ -146,8 +154,8 @@ switch (_b.label) { | ||
image: { | ||
standard: images.shift().src, | ||
hd: images.pop().src | ||
standard: this.proxy + images.shift().src, | ||
hd: this.proxy + images.pop().src | ||
}, | ||
video: media_1.is_video | ||
? { | ||
url: media_1.video_url, | ||
url: this.proxy + media_1.video_url, | ||
type: media_1.product_type, | ||
@@ -173,8 +181,8 @@ views: media_1.video_view_count, | ||
image: { | ||
standard: images.shift().src, | ||
hd: images.pop().src | ||
standard: _this.proxy + images.shift().src, | ||
hd: _this.proxy + images.pop().src | ||
}, | ||
video: sidecar.is_video | ||
? { | ||
url: sidecar.video_url, | ||
url: _this.proxy + sidecar.video_url, | ||
type: media_1.product_type, | ||
@@ -189,3 +197,3 @@ views: sidecar.video_view_count, | ||
return ({ | ||
image: tagged.user.profile_pic_url, | ||
image: _this.proxy + tagged.user.profile_pic_url, | ||
name: tagged.user.full_name, | ||
@@ -203,3 +211,3 @@ isVerified: tagged.user.is_verified, | ||
username: user.username, | ||
image: user.profile_pic_url, | ||
image: this.proxy + user.profile_pic_url, | ||
qtyPosts: user.edge_owner_to_timeline_media.count, | ||
@@ -211,3 +219,3 @@ followers: user.edge_followed_by.count, | ||
}, | ||
lastComments: _UTILS_1.InstragramUtil.getComments(commentList), | ||
lastComments: _UTILS_1.InstragramUtil.getComments(commentList, this.proxy), | ||
location: media_1.location ? _UTILS_1.InstragramUtil.getLocation(media_1.location.address_json) : null, | ||
@@ -228,2 +236,2 @@ date: _UTILS_1.GeneralUtil.msToDate(media_1.taken_at_timestamp) | ||
}()); | ||
exports.InstagramApiService = InstagramApiService; | ||
exports.Instagrapi = InstagramApiService; |
@@ -51,3 +51,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var isUrl, url, _a, status_1, data, error_1; | ||
var isUrl, url, endpoint, _a, status_1, data, error_1; | ||
return __generator(this, function (_b) { | ||
@@ -58,6 +58,7 @@ switch (_b.label) { | ||
url = isUrl ? query : "".concat(_UTILS_1.configApi.urlBase, "/").concat(query); | ||
endpoint = url + '/?__a=1'; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
return [4, axios_1.default.get(url + '/?__a=1', { | ||
return [4, axios_1.default.get(endpoint, { | ||
headers: { | ||
@@ -64,0 +65,0 @@ cookie: "sessionid=".concat(this.id) |
import { TComment, TPost } 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): TComment[]; | ||
static getComments(commentList: Array<TEdgeComment> | undefined, proxy: string): TComment[]; | ||
static getLocation(addressJson: string): TPost['location']; | ||
} |
@@ -14,3 +14,3 @@ "use strict"; | ||
}; | ||
InstragramUtil.getComments = function (commentList) { | ||
InstragramUtil.getComments = function (commentList, proxy) { | ||
if (commentList === null || commentList === void 0 ? void 0 : commentList.length) { | ||
@@ -26,7 +26,7 @@ return commentList.map(function (_a) { | ||
username: user.username, | ||
image: user.profile_pic_url, | ||
image: proxy + user.profile_pic_url, | ||
isVerified: user.is_verified | ||
}, | ||
likes: comment.edge_liked_by.count, | ||
responses: InstragramUtil.getComments(commentList), | ||
responses: InstragramUtil.getComments(commentList, proxy), | ||
isSpam: comment.did_report_as_spam, | ||
@@ -33,0 +33,0 @@ date: general_util_1.GeneralUtil.msToDate(comment.created_at) |
{ | ||
"name": "instagrapi", | ||
"version": "4.1.0", | ||
"version": "4.2.1", | ||
"description": "Library to obtain information from an Instagram account in a friendly and intuitive way", | ||
@@ -25,5 +25,6 @@ "keywords": [ | ||
"dev": "nodemon --config", | ||
"pre-publish": "yarn lint-lib && yarn clean && yarn build && yarn try-publish", | ||
"prepublish": "yarn build && yarn test", | ||
"try-publish": "npm publish --dry-run", | ||
"build": "tsc && tsc-alias", | ||
"build-ts": "tsc && tsc-alias", | ||
"build": "yarn lint-lib && yarn clean && yarn build-ts", | ||
"start": "node dist", | ||
@@ -40,3 +41,3 @@ "deploy": "gh-pages -o github -d ./demo", | ||
"verbose": false, | ||
"exec": "yarn build && yarn start", | ||
"exec": "yarn build-ts && yarn start", | ||
"ignore": [ | ||
@@ -43,0 +44,0 @@ "node_modules/", |
# Instagrapi | ||
[![](https://img.shields.io/badge/author-Edixon_Piña-F0DB4E?style=for-the-badge)](https://github.com/EdixonAlberto/) | ||
[![](https://img.shields.io/badge/author-Edixon_Piña-yellow?style=for-the-badge)](https://github.com/EdixonAlberto/) | ||
[![](https://img.shields.io/github/license/edixonalberto/instagrapi?style=for-the-badge)](LICENSE) | ||
[![](https://img.shields.io/npm/v/instagrapi?color=CB0000&style=for-the-badge)](https://npmjs.com/package/@edixon/instagrapi) | ||
[![](https://img.shields.io/npm/dt/instagrapi?color=CB0000&style=for-the-badge)](https://npmjs.com/package/@edixon/instagrapi) | ||
[![](https://img.shields.io/npm/v/instagrapi?color=CB0000&style=for-the-badge)](https://npmjs.com/package/instagrapi) | ||
[![](https://img.shields.io/npm/dt/instagrapi?color=CB0000&style=for-the-badge)](https://npmjs.com/package/instagrapi) | ||
@@ -17,3 +17,3 @@ [![](https://img.shields.io/badge/types-TypeScript-blue?style=for-the-badge)](https://github.com/microsoft/TypeScript) | ||
Created with NodeJS and Typescript, all types are exposed for use. | ||
<img src="https://github.com/EdixonAlberto/instagrapi/blob/main/images/typescript.png" width="17px" alt="Logo typescript" /> + | ||
<img src="https://github.com/EdixonAlberto/instagrapi/blob/main/images/typescript.png" width="18px" alt="Logo typescript" /> + | ||
💗 | ||
@@ -89,2 +89,23 @@ | ||
## Media Files | ||
By default Instagram API return media files via a CDN configured with CORS rules so tha they can only be consumed from | ||
the official page. | ||
To work around this you can build your own proxy server and add it in instance confiuration. In this way the library | ||
will automatically add the proxy as a prefix in all the media files that are found in the response. | ||
```js | ||
const instagrapi = new Instagrapi({ | ||
sessionId: process.env.SESSION_ID, | ||
proxy: 'https://proxy-example.com' | ||
}) | ||
instagrapi.getProfile('USERNAME').then(profile => { | ||
const imgUrl = profile.image.standard | ||
console.log(imgUrl) /* https://proxy-example.com/img-url... */ | ||
}) | ||
``` | ||
## Methods | ||
@@ -91,0 +112,0 @@ |
33908
549
200