UNPKG

instamancer

Version:

Scrape the Instagram API with Puppeteer

70 lines (69 loc) 2.63 kB
import { Type } from "io-ts"; import { Browser } from "puppeteer"; import * as winston from "winston"; import { DType, IPlugin } from "../../plugins"; import { Instagram } from "./instagram"; import { ISearchOptions, ISearchOptionsPlugins, Search, TSearchResult } from "./search"; import { TFullApiPost, TPost, TSinglePost } from "./types"; /** * Optional arguments for the API */ export interface IOptionsCommon { total?: number; headless?: boolean; logger?: winston.Logger; silent?: boolean; sleepTime?: number; strict?: boolean; hibernationTime?: number; enableGrafting?: boolean; sameBrowser?: boolean; fullAPI?: boolean; proxyURL?: string; executablePath?: string; validator?: Type<unknown>; browserInstance?: Browser; } export interface IOptionsFullApi extends IOptionsCommon { fullAPI: true; } export interface IOptionsRegular extends IOptionsCommon { fullAPI?: false; } export interface IOptionsFullApiPlugins<PostType> extends IOptionsFullApi { plugins?: IPlugin<PostType>[]; } export interface IOptionsRegularPlugins<PostType> extends IOptionsRegular { plugins?: IPlugin<PostType>[]; } export declare type IOptions = IOptionsFullApi | IOptionsRegular | IOptionsFullApiPlugins<DType> | IOptionsRegularPlugins<DType>; /** * An Instagram post API wrapper */ export declare class Post extends Instagram<TSinglePost> { private readonly ids; constructor(ids: string[], options?: IOptions); /** * Get the post metadata */ protected getNext(): Promise<void>; } export declare type InstagramPostClass = Hashtag<TPost> | User<TPost>; export declare type InstagramFullPostClass = Hashtag<TFullApiPost> | User<TFullApiPost>; export declare function createApi(type: "search", query: string, options?: ISearchOptions | ISearchOptionsPlugins<TSearchResult>): Search; export declare function createApi(type: "post", id: string[], options?: IOptions): Post; export declare function createApi(type: "hashtag" | "user", id: string, options?: IOptionsRegular | IOptionsRegularPlugins<InstagramPostClass>): InstagramPostClass; export declare function createApi(type: "hashtag" | "user", id: string, options?: IOptionsFullApi | IOptionsFullApiPlugins<InstagramFullPostClass>): InstagramFullPostClass; /** * An Instagram hashtag API wrapper */ export declare class Hashtag<T> extends Instagram<T> { constructor(id: string, options?: IOptions); } /** * An Instagram user API wrapper */ export declare class User<T> extends Instagram<T> { defaultPageFunctions: (() => void)[]; constructor(id: string, options?: IOptions); }