Skip to content

Commit

Permalink
add: extended _getReels result
Browse files Browse the repository at this point in the history
  • Loading branch information
Gimenz committed Mar 13, 2024
1 parent beb8fdf commit 1f88c0b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ tes.js
media/*
docs
logged_in.json
Cookies.txt
Cookies.txt
tes.ts
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "insta-fetcher",
"version": "1.3.32",
"version": "1.3.33",
"description": "Simplified Instagram metadata scraping",
"main": "./dist/index.js",
"scripts": {
Expand Down
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,16 @@ export class igApi {
/**
* fetch profile by username. including email, phone number
* @param {username} username
* @param {boolean} simplifiedMetadata if set to false, it will return full of json result from api request. default is set to true
* @returns {Promise<IGUserMetadata>}
* @returns
*/
public fetchUser = async (username: username, simplifiedMetadata: boolean = true): Promise<UserGraphQL | IGUserMetadata> => {
public fetchUser = async (username: username): Promise<IGUserMetadata> => {
const userID = await this.getIdByUsername(username);
const res = await this.FetchIGAPI(
config.instagram_api_v1,
`/users/${userID}/info/`
);
const graphql: UserGraphQL = res?.data;
if (!simplifiedMetadata) {
return graphql as UserGraphQL
} else return {
return {
id: graphql.user.pk,
username: graphql.user.username,
fullname: graphql.user.full_name,
Expand All @@ -247,7 +244,8 @@ export class igApi {
contact_phone_number: graphql.user.contact_phone_number,
public_email: graphql.user.public_email,
account_type: graphql.user.account_type,
} as IGUserMetadata;
...graphql
}
}

/**
Expand All @@ -261,7 +259,7 @@ export class igApi {
`/users/web_profile_info/?username=${username}`,
config.iPhone,
);
const graphql : Graphql = res?.data;
const graphql: Graphql = res?.data;
return graphql.data?.user as UserGraphQlV2;
}

Expand All @@ -270,7 +268,7 @@ export class igApi {
* @param username
* @returns true if user is follow me
*/
public isFollowMe = async (username: username): Promise<boolean|undefined> => {
public isFollowMe = async (username: username): Promise<boolean | undefined> => {
const user = await this.fetchUserV2(username);
return user.follows_viewer;
}
Expand Down Expand Up @@ -391,12 +389,14 @@ export class igApi {
)
const graphql: HMedia = res?.data;
let result: ReelsMediaData[] = graphql.data.reels_media[0].items.map((item) => ({
owner: graphql.data.reels_media[0].owner,
media_id: item.id,
mimetype: item.is_video ? 'video/mp4' || 'video/gif' : 'image/jpeg',
taken_at: item.taken_at_timestamp,
type: item.is_video ? 'video' : 'image',
url: item.is_video ? item.video_resources[0].src : item.display_url,
dimensions: item.dimensions
dimensions: item.dimensions,
...graphql
}))

return result;
Expand Down
100 changes: 50 additions & 50 deletions src/types/HighlightMediaMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { Dimensions, DisplayResource, MediaType, MimeType, PageInfo } from ".";

/** Instagram Simplified Highlights reels Metadata */
export interface IHighlightsMetadata {
/** Instagram username */
username: string;
/** stories count */
highlights_count: number;
data: IReelsMetadata[];
/** Instagram username */
username: string;
/** stories count */
highlights_count: number;
data: IReelsMetadata[];
}

export interface IReelsMetadata {
Expand All @@ -24,19 +24,19 @@ export interface IReelsMetadata {
}

export interface ReelsMediaData {
owner: HighlightOwner
media_id: string;
mimetype: string;
taken_at: number;
/** @type MediaType */
type: string;
/** Downloadable media url */
url: string;
dimensions: Dimensions;

}

export interface HMedia {
data: ReelsData;
data: ReelsData;
status: string;
}

Expand All @@ -45,67 +45,67 @@ export interface ReelsData {
}

export interface ReelsMedia {
__typename: string;
id: string;
__typename: string;
id: string;
latest_reel_media: null;
can_reply: boolean;
owner: HighlightOwner;
items: HighlightItem[];
can_reply: boolean;
owner: HighlightOwner;
items: HighlightItem[];
}

export interface HighlightItem {
audience: string;
edge_story_media_viewers: EdgeStoryMediaViewers;
__typename: string;
id: string;
dimensions: Dimensions;
display_resources: DisplayResource[];
display_url: string;
media_preview: null | string;
gating_info: null;
fact_check_overall_rating: null;
fact_check_information: null;
sensitivity_friction_info: null;
taken_at_timestamp: number;
expiring_at_timestamp: number;
story_cta_url: null;
story_view_count: null;
is_video: boolean;
owner: HighlightOwner;
tracking_token: string;
tappable_objects: any[];
story_app_attribution: null;
audience: string;
edge_story_media_viewers: EdgeStoryMediaViewers;
__typename: string;
id: string;
dimensions: Dimensions;
display_resources: DisplayResource[];
display_url: string;
media_preview: null | string;
gating_info: null;
fact_check_overall_rating: null;
fact_check_information: null;
sensitivity_friction_info: null;
taken_at_timestamp: number;
expiring_at_timestamp: number;
story_cta_url: null;
story_view_count: null;
is_video: boolean;
owner: HighlightOwner;
tracking_token: string;
tappable_objects: any[];
story_app_attribution: null;
edge_media_to_sponsor_user: EdgeMediaToSponsorUser;
muting_info: null;
has_audio?: boolean;
overlay_image_resources?: null;
video_duration?: number;
video_resources: VideoResource[];
muting_info: null;
has_audio?: boolean;
overlay_image_resources?: null;
video_duration?: number;
video_resources: VideoResource[];
}

export interface EdgeMediaToSponsorUser {
edges: any[];
}

export interface EdgeStoryMediaViewers {
count: number;
count: number;
page_info: PageInfo;
edges: any[];
edges: any[];
}

export interface HighlightOwner {
id: string;
profile_pic_url: string;
username: string;
followed_by_viewer: boolean;
id: string;
profile_pic_url: string;
username: string;
followed_by_viewer: boolean;
requested_by_viewer: boolean;
__typename?: string;
__typename?: string;
}

export interface VideoResource {
src: string;
config_width: number;
src: string;
config_width: number;
config_height: number;
mime_type: string;
profile: string;
mime_type: string;
profile: string;
}
18 changes: 9 additions & 9 deletions src/types/HighlightMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ export interface ReelsIds {
}

export interface HightlighGraphQL {
data: IHighlightData;
data: IHighlightData;
status: string;
}

export interface IHighlightData {
viewer: null;
user: IHighlightUser;
user: IHighlightUser;
}

export interface IHighlightUser {
has_public_story: boolean;
edge_highlight_reels: Edge;
has_public_story: boolean;
edge_highlight_reels: Edge;
edge_related_profiles: Edge;
}

Expand All @@ -31,12 +31,12 @@ export interface EdgeElement {
}

export interface Node {
__typename: string;
id: string;
cover_media: CoverMedia;
__typename: string;
id: string;
cover_media: CoverMedia;
cover_media_cropped_thumbnail: CoverMediaCroppedThumbnail;
owner: HighlightOwner;
title: string;
owner: HighlightOwner;
title: string;
}

export interface CoverMedia {
Expand Down
2 changes: 1 addition & 1 deletion src/types/StoriesMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface IGStoriesMetadata {

/** an Array of simplified StoriesMetadata */
export interface ItemStories {
type: MediaType;
type: string;
mimetpye: MimeType;
/** Downloadable media url */
url: string;
Expand Down

0 comments on commit 1f88c0b

Please sign in to comment.