Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Getting video height and width via Node.js

I'm looking for a way to get video width and height by Node.js (all I have is the video URL).

For that matter, I'm also using Puppeteer for getting video URLs from the web, so any manipulation needed that requires DOM is pretty much optionally doable - on the data crawling process I have access to the element.

Any suggestions for that issue?

CODE:

export async function _getSourcesLinks(targetUrl: string): Promise < string[] > {
  return await puppeteer.launch({
    args: ['--no-sandbox', '--disable-setuid-sandbox'],
    headless: true,
  }).then(async browser => {
    try {
      const page = await browser.newPage()
      page.setJavaScriptEnabled(true)

      await page.goto(targetUrl, {
        waitUntil: 'load'
      })


      try {
        // waiting for video to appear
        await page.waitForTimeout(1500)
        // await page.waitForSelector('video', { timeout: 2500 }) // die after 2.5 seconds
      } catch (error) {
        console.error(error)
      }

      const srcs = await page.$$eval < Element > ('video, .video, [src]', (videos) => {
        // TODO get also width and height
        return videos.map(video => {
          // @ts-ignore
          return video.getAttribute('src')
        })
      }) as never as string[]

      const downloadTargets = srcs.filter(src => {
        console.log(src)
        if (!src) return false
        const fitPattern = new RegExp('.*\.mp4.*')
        return fitPattern.test(src)
      })

      browser.close()
      return downloadTargets

    } catch (error) {
      console.error(error)
    }
  })
}

As for the test video - I don't have one, it's just happened from time to time

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda