Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda