- 
      
 - 
        
Save ueaner/0045653fb0d9663551386274f6448de6 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
Agung Jati Kusumo revised this gist
Sep 14, 2020 . 1 changed file with 0 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,17 +11,6 @@ export default async (req, res) => { return; } const browser = await puppeteer.launch( process.env.NODE_ENV === 'production' ? {  - 
        
Agung Jati Kusumo renamed this gist
Sep 14, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. - 
        
Agung Jati Kusumo renamed this gist
Sep 14, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. - 
        
Agung Jati Kusumo created this gist
Sep 14, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ const puppeteer = require('puppeteer-core'); const cheerio = require('cheerio'); const chrome = require('chrome-aws-lambda'); export default async (req, res) => { const slug = req?.query?.slug; if (!slug) { res.statusCode = 200 res.setHeader('Content-Type', 'application/json') res.end(JSON.stringify({ id: null })) return; } const fs = require("fs"); const dirTmp = '/tmp/.local-chromium'; if (!fs.existsSync(dirTmp)){ fs.mkdirSync(dirTmp); } const dirCache = '/tmp/.chromium-cache'; if (!fs.existsSync(dirCache)){ fs.mkdirSync(dirCache); } const browser = await puppeteer.launch( process.env.NODE_ENV === 'production' ? { args: chrome.args, executablePath: await chrome.executablePath, headless: chrome.headless, } : {} ); const page = await browser.newPage(); page.setUserAgent('Opera/9.80 (J2ME/MIDP; Opera Mini/5.1.21214/28.2725; U; ru) Presto/2.8.119 Version/11.10'); await page.goto(`https://m.youtube.com/${slug}/videos`); let content = await page.content(); var $ = cheerio.load(content); $.prototype.exists = function (selector) { return this.find(selector).length > 0; } let id = null; const isLive = $('body').exists('[data-style="LIVE"]'); if (isLive) { const url = $('ytm-compact-video-renderer .compact-media-item-image').attr('href'); const arr = url.split('?v='); id = arr[1]; } await browser.close(); res.statusCode = 200 res.setHeader('Content-Type', 'application/json') res.end(JSON.stringify({ id })) }