Created
February 10, 2020 15:23
-
-
Save Xananax/837e0cce3569771eed4b76428091ec28 to your computer and use it in GitHub Desktop.
Scrape Vimeo Video
This file contains 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 characters
const load = url => new Promise((ok, err) => require('https').request({ hostname: 'player.vimeo.com', port: 443, path: `/video/${url}`, method: 'GET'}, res => { | |
let data = '' | |
res.on('data', chunk => data+=chunk.toString()) | |
res.on('end', () => ok(data.replace(/\n/g,''))) | |
}).on('error',err).end()); | |
const extractTitle = html => (/<title>(.+?) on Vimeo<\/title>/gi.exec(html) || [])[1] | |
const extractAuthor = titleStr => ((/(.+?) from (.+)$/.exec(titleStr)) || [titleStr, titleStr, '']).slice(1, 3) | |
load('22685162').then(html => (console.log(html), html)).then(extractTitle).then(extractAuthor).then(console.log).catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment