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,IAAI,QAI5D,MAAM,EAAuB,4BAA4B,KAAK,GAC9D,GAAI,GAAoD,eAA5B,EAAqB,GAC7C,MAAO,CACH,GAAI,EAAmB,GACvB,KAAM,EAAgB,GACtB,UAAU,EACV,IAAK,UAAU,EAAe,IAAI,QAAQ,QAAS,IACnD,UACA,SAAU,IAGlB,MAAM,IAAI,MAAM,qDAcpB,CACA,eAAe,OAAO,GAClB,OAAO,IAAI,SAAQ,CAAC,EAAS,KACT,QAAQ,QACnB,IAAI,GAAM,IACX,IAAI,EAEJ,EAAK,GAAG,QAAS,IACb,GAAQ,CAAK,IAGjB,EAAK,GAAG,OAAO,IACJ,EAAQ,IACjB,IAED,GAAG,SAAU,GACP,EAAO,KAEV,KAAK,GAErB,CACA,eAAe,IAAI,GACf,aAAa,GACb,MAAM,QAAoB,OAAO,+BAA+B,sBAC1D,EAAW,+DAA+D,KAAK,GACrF,IAAK,EACD,MAAM,IAAI,MAAM,+CACpB,MAAM,EAAiB,KAAK,MAAM,EAAS,IAC3C,OAAO,EAAiB,kBAAkB,GAAkB,eAAe,EAC/E,CACA,QAAQ,aAAe,CACnB","file":"/npm/simple-instagram-api@3.0.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/simple-instagram-api@3.0.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\r\nvar __importDefault = (this && this.__importDefault) || function (mod) {\r\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\r\n};\r\nObject.defineProperty(exports, \"__esModule\", { value: true });\r\nexports.InstagramApi = void 0;\r\nconst https_1 = __importDefault(require(\"https\"));\r\nfunction validateCode(code) {\r\n    if (!code)\r\n        throw new Error('Instagram media code is required');\r\n    if (code.length < 3)\r\n        throw new Error('Instagram media code is too short');\r\n    if (!code.match(/^[a-zA-Z0-9_-]*$/gi))\r\n        throw new Error('Invalid Instagram media code.');\r\n}\r\nfunction mapAdditionalData(data) {\r\n    const media = data.shortcode_media;\r\n    return {\r\n        // type: media.__typename,\r\n        id: media.id,\r\n        code: media.shortcode,\r\n        is_video: media.is_video,\r\n        url: media.video_url || media.display_url,\r\n        caption: media.edge_media_to_caption ? media.edge_media_to_caption.edges[0].node.text : undefined,\r\n        children: media.edge_sidecar_to_children ? mapPostChildren(media.edge_sidecar_to_children.edges) : [],\r\n    };\r\n}\r\nfunction mapPostChildren(children) {\r\n    return children.map((edge) => {\r\n        return {\r\n            // type: edge.node.__typename,\r\n            id: edge.node.id,\r\n            code: edge.node.shortcode,\r\n            is_video: edge.node.is_video,\r\n            url: edge.node.video_url || edge.node.display_url,\r\n        };\r\n    });\r\n}\r\nasync function mapHTMLContent(html) {\r\n    /**\r\n     * Extract id\r\n     */\r\n    const regexMediaIdResult = /data-media-id=\"(.*?)\"/gs.exec(html);\r\n    if (!regexMediaIdResult)\r\n        throw new Error('Could not extract post media id');\r\n    /**\r\n     * Extract code\r\n     */\r\n    const regexCodeResult = /instagram\\.com\\/p\\/(.*?)\\//gs.exec(html);\r\n    if (!regexCodeResult)\r\n        throw new Error('Could not extract post code');\r\n    /**\r\n     * Extract url\r\n     */\r\n    const regexUrlResult = /class=\"Content(.*?)src=\"(.*?)\"/gs.exec(html);\r\n    if (!regexUrlResult)\r\n        throw new Error('Could not extract post url');\r\n    /**\r\n     * Extract caption\r\n     */\r\n    let caption;\r\n    const regexCaptionResult = /class=\"Caption\"(.*?)class=\"CaptionUsername\"(.*?)<\\/a>(.*?)<div/gs.exec(html);\r\n    /**\r\n     * Replace all html tags and trim the result\r\n     */\r\n    if (regexCaptionResult)\r\n        caption = regexCaptionResult[3].replace(/<[^>]*>/g, '').trim();\r\n    /**\r\n     * If the media type is not reel video, return the photo\r\n     */\r\n    const regexMediaTypeResult = /data-media-type=\"(.*?)\"/gs.exec(html);\r\n    if (regexMediaTypeResult && regexMediaTypeResult[1] !== 'GraphVideo') {\r\n        return {\r\n            id: regexMediaIdResult[1],\r\n            code: regexCodeResult[1],\r\n            is_video: false,\r\n            url: decodeURI(regexUrlResult[2]).replace(/amp;/g, ''),\r\n            caption,\r\n            children: [],\r\n        };\r\n    }\r\n    throw new Error(`Failed to extract webpage's Instagram media detail`);\r\n    /*\r\n    const reelResponse = await sendHttpRequest(getReelUrl(regexCodeResult[1]));\r\n    const reel = JSON.parse(reelResponse.replace('undefined', ''));\r\n  \r\n    return {\r\n      id: reel.graphql.shortcode_media.id,\r\n      code: reel.graphql.shortcode_media.shortcode,\r\n      is_video: true,\r\n      url: reel.graphql.shortcode_media.video_url,\r\n      caption,\r\n      children: [],\r\n    };\r\n    */\r\n}\r\nasync function getURL(url) {\r\n    return new Promise((resolve, reject) => {\r\n        const request = https_1.default\r\n            .get(url, (resp) => {\r\n            let data;\r\n            // A chunk of data has been received.\r\n            resp.on('data', (chunk) => {\r\n                data += chunk;\r\n            });\r\n            // The whole response has been received.\r\n            resp.on('end', () => {\r\n                return resolve(data);\r\n            });\r\n        })\r\n            .on('error', (err) => {\r\n            return reject(err);\r\n        });\r\n        request.end();\r\n    });\r\n}\r\nasync function get(code) {\r\n    validateCode(code);\r\n    const htmlContent = await getURL(`https://www.instagram.com/p/${code}/embed/captioned/`);\r\n    const regexRes = /window\\.__additionalDataLoaded\\('extra',(.*?)\\);<\\/script>/gs.exec(htmlContent);\r\n    if (!regexRes)\r\n        throw new Error('Regex failed! Could not get additional data');\r\n    const additionalData = JSON.parse(regexRes[1]);\r\n    return additionalData ? mapAdditionalData(additionalData) : mapHTMLContent(htmlContent);\r\n}\r\nexports.InstagramApi = {\r\n    get,\r\n};\r\n"]}