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AY,EAAI,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,IAC1F,UAAW,EAAI,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,KAC1F,YAAa,gBAAkB,EAAI,GAAG,SAAS,GAAG,WAAW,aAC7D,cArLoB,EAqLa,EAjLrC,GADA,GADA,GADA,EAAS,EAAO,QAAQ,UAAW,MACnB,QAAQ,SAAU,MAClB,WAAW,SAAU,MACrB,WAAW,QAAS,MAkLhC,gBACA,gBACA,QACA,YAEA,GACA,EAAK,KAAK,EAClB,CA7LA,IAA4B,EA+L5B,OADa,KAAK,UAAU,EAAM,KAAM,GAE5C,GACJ","file":"/npm/telegram-scraper@1.0.2/dist/cjs/telegram-scraper.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/telegram-scraper@1.0.2/dist/cjs/telegram-scraper.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\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n    return new (P || (P = Promise))(function (resolve, reject) {\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\n    });\n};\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.telegram_scraper = telegram_scraper;\nconst html_parser_js_1 = __importDefault(require(\"./html-parser.js\"));\nconst https_1 = __importDefault(require(\"https\"));\nfunction telegram_scraper(channel) {\n    return __awaiter(this, void 0, void 0, function* () {\n        function HtmlEntitiesDecode(string) {\n            string = string.replace(/&quot;/g, '\"');\n            string = string.replace(/&amp;/g, '&');\n            string = string.replaceAll('&nbsp;', ' ');\n            string = string.replaceAll(\"&#39;\", \"'\");\n            return string;\n        }\n        function get(targeturl, resolve) {\n            https_1.default.get(targeturl, res => {\n                if ((res.statusCode === 301 || res.statusCode === 302) && (res.headers.location != undefined)) {\n                    return get(res.headers.location, resolve);\n                }\n                let data = [];\n                res.on('data', chunk => { data.push(chunk); });\n                res.on('end', () => {\n                    try {\n                        const raw = Buffer.concat(data).toString();\n                        resolve(raw);\n                    }\n                    catch (err) {\n                        let msg = JSON.stringify({ status: 'error', msg: err, targeturl });\n                        resolve(msg);\n                    }\n                });\n            });\n        }\n        function get_page(targeturl) {\n            return __awaiter(this, void 0, void 0, function* () {\n                return new Promise((resolve) => {\n                    get(targeturl, resolve);\n                });\n            });\n        }\n        const targeturl = 'https://t.me/s/' + channel;\n        const rawdata = yield get_page(targeturl);\n        let temp = rawdata;\n        if (temp.indexOf('<section class=\"tgme_channel_history js-message_history\">') == -1)\n            return 'Unknown telegram channel';\n        temp = temp.split('<section class=\"tgme_channel_history js-message_history\">');\n        temp = temp[1].split('</section>');\n        temp = temp[0].split('<div class=\"tgme_widget_message_wrap js-widget_message_wrap\">');\n        temp.splice(0, 1);\n        let data = [];\n        for (var i = 0; i < temp.length; i++) {\n            let html = '<div class=\"tgme_widget_message_wrap js-widget_message_wrap\">' + temp[i];\n            let arr = (0, html_parser_js_1.default)(html);\n            let message_text = '';\n            let message_photo = [];\n            let message_video = [];\n            let views = '';\n            let datetime = '';\n            let include = true;\n            for (var j = 0; j < arr[0].children[0].children[3].children.length; j++) {\n                let child_class = '';\n                try {\n                    child_class = arr[0].children[0].children[3].children[j].attributes.class;\n                }\n                catch (_a) { }\n                if (child_class == \"tgme_widget_message_text js-message_text\") {\n                    function message_extractor(input) {\n                        let msg = '';\n                        function loop(arr) {\n                            for (let k = 0; k < arr.length; k++) {\n                                if (arr[k].text != null)\n                                    msg += arr[k].text;\n                                try {\n                                    if (arr[k].attributes.class == \"tgme_widget_service_strong_text\")\n                                        include = false;\n                                }\n                                catch (_a) { }\n                                if (arr[k].children != null) {\n                                    if (arr[k].children.length > 0)\n                                        loop(arr[k].children);\n                                }\n                            }\n                        }\n                        loop(input);\n                        return msg.replaceAll('/>', ' ');\n                    }\n                    let message_node = arr[0].children[0].children[3].children[j].children;\n                    message_text = message_extractor(message_node);\n                }\n                let arr_child_class = child_class.split(\" \");\n                if (arr_child_class[0] == \"tgme_widget_message_photo_wrap\") {\n                    message_photo.push(arr[0].children[0].children[3].children[j].attributes.style.split(\"'\")[1]);\n                }\n                if (child_class == \"tgme_widget_message_footer compact js-message_footer\") {\n                    let get_views = arr[0].children[0].children[3].children[j].children[1].children[1].children[0].text;\n                    if (get_views != null)\n                        views = get_views;\n                    try {\n                        datetime = arr[0].children[0].children[3].children[j].children[1].children[3].children[0].children[0].attributes.datetime;\n                    }\n                    catch (_b) { }\n                    try {\n                        datetime = arr[0].children[0].children[3].children[j].children[1].children[3].children[2].children[0].attributes.datetime;\n                    }\n                    catch (_c) { }\n                }\n                if (child_class == \"tgme_widget_message_video_player blured js-message_video_player\") {\n                    message_video.push(arr[0].children[0].children[3].children[j].children[4].children[1].attributes.src);\n                }\n                if (child_class == \"tgme_widget_message_video_player js-message_video_player\") {\n                    message_video.push(arr[0].children[0].children[3].children[j].children[2].children[1].attributes.src);\n                }\n                if (child_class == \"media_supported_cont\") {\n                    try {\n                        let src = arr[0].children[0].children[3].children[j].children[0].children[2].attributes.src;\n                        if (src != null)\n                            message_video.push(src);\n                    }\n                    catch (_d) { }\n                    try {\n                        let src = arr[0].children[0].children[3].children[j].children[0].children[2].children[1].attributes.src;\n                        if (src != null)\n                            message_video.push(src);\n                    }\n                    catch (_e) { }\n                    try {\n                        function message_extractor(input) {\n                            let msg = '';\n                            function loop(arr) {\n                                for (let k = 0; k < arr.length; k++) {\n                                    if (arr[k].text != null)\n                                        msg += arr[k].text;\n                                    try {\n                                        if (arr[k].attributes.class == \"tgme_widget_service_strong_text\")\n                                            include = false;\n                                    }\n                                    catch (_a) { }\n                                    if (arr[k].children != null) {\n                                        if (arr[k].children.length > 0)\n                                            loop(arr[k].children);\n                                    }\n                                }\n                            }\n                            loop(input);\n                            return msg.replaceAll('/>', ' ');\n                        }\n                        let message_node = arr[0].children[0].children[3].children[j].children[1].children;\n                        message_text = message_extractor(message_node);\n                    }\n                    catch (_f) { }\n                }\n                if (child_class == \"tgme_widget_message_grouped_wrap js-message_grouped_wrap\") {\n                    function loop(node) {\n                        for (let k = 0; k < node.length; k++) {\n                            try {\n                                if (node[k].attributes.class != null) {\n                                    if (node[k].attributes.class == \"tgme_widget_message_video js-message_video\")\n                                        message_video.push(node[k].attributes.src);\n                                }\n                            }\n                            catch (_a) { }\n                            try {\n                                if (node[k].attributes.class != null) {\n                                    if (node[k].attributes.class == \"tgme_widget_message_photo_wrap grouped_media_wrap blured js-message_photo\") {\n                                        let photo = node[k].attributes.style.split(\"'\")[1];\n                                        message_photo.push(photo);\n                                    }\n                                }\n                            }\n                            catch (_b) { }\n                            if (node[k].children != null) {\n                                if (node[k].children.length > 0)\n                                    loop(node[k].children);\n                            }\n                        }\n                    }\n                    let node = arr[0].children[0].children[3].children[j].children;\n                    loop(node);\n                }\n            }\n            let item = {\n                //raw:arr[0],\n                data_post: arr[0].children[0].attributes[\"data-post\"],\n                data_view: arr[0].children[0].attributes[\"data-view\"],\n                user_url: arr[0].children[0].children[1].children[0].attributes.href,\n                user_photo: arr[0].children[0].children[1].children[0].children[0].children[0].attributes.src,\n                user_name: arr[0].children[0].children[3].children[3].children[0].children[0].children[0].text,\n                message_url: 'https://t.me/' + arr[0].children[0].attributes[\"data-post\"],\n                message_text: HtmlEntitiesDecode(message_text),\n                message_photo,\n                message_video,\n                views,\n                datetime\n            };\n            if (include)\n                data.push(item);\n        }\n        let result = JSON.stringify(data, null, 30);\n        return result;\n    });\n}\n"]}