diff --git a/package.json b/package.json index 104fb99..b687f07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "insta-fetcher", - "version": "1.3.34", + "version": "1.3.35", "description": "Simplified Instagram metadata scraping", "main": "./dist/index.js", "scripts": { diff --git a/src/helper/query.ts b/src/helper/query.ts index f38b677..0922c8b 100644 --- a/src/helper/query.ts +++ b/src/helper/query.ts @@ -5,12 +5,12 @@ export const highlight_ids_query = (userId: string) => { 'query_hash': 'c9100bf9110dd6361671f113dd02e7d6', 'variables': JSON.stringify({ "user_id": userId, - "include_chaining":false, - "include_reel":true, - "include_suggested_users":false, - "include_logged_out_extras":false, - "include_highlight_reels":true, - "include_live_status":false + "include_chaining": false, + "include_reel": true, + "include_suggested_users": false, + "include_logged_out_extras": false, + "include_highlight_reels": true, + "include_live_status": false }) } } @@ -19,15 +19,24 @@ export const highlight_media_query = (ids: string) => { return { 'query_hash': '0a85e6ea60a4c99edc58ab2f3d17cfdf', 'variables': JSON.stringify({ - "reel_ids":[], - "tag_names":[], - "location_ids":[], - "highlight_reel_ids":[ids], - "precomposed_overlay":false, - "show_story_viewer_list":true, - "story_viewer_fetch_count":50, - "story_viewer_cursor":"", - "stories_video_dash_manifest":false + "reel_ids": [], + "tag_names": [], + "location_ids": [], + "highlight_reel_ids": [ids], + "precomposed_overlay": false, + "show_story_viewer_list": true, + "story_viewer_fetch_count": 50, + "story_viewer_cursor": "", + "stories_video_dash_manifest": false + }) + } +} + +export const post_shortcode_query = (shortcode: string) => { + return { + 'query_hash': '55a3c4bad29e4e20c20ff4cdfd80f5b4', + 'variables': JSON.stringify({ + shortcode }) } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 3d289ed..022fc9d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,10 +7,10 @@ import fs from 'fs' import FormData from 'form-data'; import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; import { bufferToStream, getPostType, parseCookie, randInt, shortcodeFormatter } from './utils/index'; -import { username, userId, seachTerm, url, IgCookie, ProductType, MediaType, IChangedProfilePicture, ISearchFollow, IGPostMetadata } from './types'; +import { username, userId, seachTerm, url, IgCookie, ProductType, MediaType, IChangedProfilePicture, ISearchFollow, IGPostMetadata, PostGraphQL } from './types'; import { IGUserMetadata, UserGraphQL } from './types/UserMetadata'; import { IGStoriesMetadata, ItemStories, StoriesGraphQL } from './types/StoriesMetadata'; -import { highlight_ids_query, highlight_media_query } from './helper/query'; +import { highlight_ids_query, highlight_media_query, post_shortcode_query } from './helper/query'; import { HightlighGraphQL, ReelsIds } from './types/HighlightMetadata'; import { HMedia, IHighlightsMetadata, IReelsMetadata, ReelsMediaData } from './types/HighlightMediaMetadata'; import { IPostModels, IRawBody, MediaUrls } from './types/PostModels'; @@ -161,7 +161,6 @@ export class igApi { public fetchPost = async (url: url): Promise => { const post = shortcodeFormatter(url); - //const req = (await IGFetchDesktop.get(`/${post.type}/${post.shortcode}/?__a=1`)) const metadata = await this.fetchPostByMediaId(post.media_id) const item = metadata.items[0] @@ -194,6 +193,17 @@ export class igApi { } } + public fetchPostByShortcode = async (shortcode: string): Promise => { + const res = await this.FetchIGAPI( + config.instagram_base_url, + '/graphql/query/', + config.iPhone, + { params: post_shortcode_query(shortcode) } + ) + const graphql = res?.data; + return graphql; + } + /** * fetch client account profile */ diff --git a/src/types/PostMetadata.ts b/src/types/PostMetadata.ts index f801477..bfb3e10 100644 --- a/src/types/PostMetadata.ts +++ b/src/types/PostMetadata.ts @@ -1,4 +1,4 @@ -import { MediaType, Typename, User } from '.'; +import { MediaType, Typename, User } from '.'; export interface IGPostMetadata { /** an Instagram Username */ @@ -31,7 +31,13 @@ export interface links { } export interface PostGraphQL { - shortcode_media: ShortcodeMedia; + data?: PostData; + extensions?: Extensions; + status?: string; +} + +export interface PostData { + shortcode_media?: ShortcodeMedia; } export interface ShortcodeMedia extends ViewerInfo { @@ -291,10 +297,14 @@ export interface ShortcodeMediaOwner { } export interface ClipsMusicAttributionInfo { - artist_name: string; - song_name: string; - uses_original_audio: boolean; - should_mute_audio: boolean; - should_mute_audio_reason: string; - audio_id: string; + artist_name: string; + song_name: string; + uses_original_audio: boolean; + should_mute_audio: boolean; + should_mute_audio_reason: string; + audio_id: string; +} + +export interface Extensions { + is_final?: boolean; } \ No newline at end of file diff --git a/src/utils/index.ts b/src/utils/index.ts index 46d0aa6..57a671a 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -42,7 +42,7 @@ export const IGPostRegex = /(?:https?:\/\/)?(?:www\.)?(?:instagram\.com(?:\/.+?) * @returns {formattedShortcode} */ export const shortcodeFormatter = (url: string): formattedShortcode => { - const splitted = IGPostRegex.exec(url) || ''; + const splitted = /(?:https?:\/\/)?(?:www\.)?(?:instagram\.com(?:\/.+?)?\/(p|reel(?:s|)|tv)\/)([\w-]+)(?:\/)?(\?.*)?$/gim.exec(url) || ''; return { type: splitted[1], shortcode: splitted[2], @@ -57,7 +57,7 @@ export const shortcodeFormatter = (url: string): formattedShortcode => { * @returns */ export const isIgPostUrl = (url: string): boolean => { - return IGPostRegex.test(url); + return /(?:https?:\/\/)?(?:www\.)?(?:instagram\.com(?:\/.+?)?\/(p|reel(?:s|)|tv)\/)([\w-]+)(?:\/)?(\?.*)?$/gim.test(url); } /**