Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!