-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thumbnail for video metadata and dedicated url
- Loading branch information
Matheus Cesar C. - Matsukii
committed
Oct 8, 2019
1 parent
f79b2cd
commit bffad98
Showing
6 changed files
with
172 additions
and
48 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,54 @@ | ||
module.exports = (params) => { | ||
module.exports = async(params) => { | ||
const parser = require('js-video-url-parser'); | ||
const fetch = require('node-fetch'); | ||
// console.log(parser.parse(params.url)); | ||
return parser.parse(params.url) | ||
|
||
let metadata = parser.parse(params.url); | ||
|
||
let onlyThumb = params.thumb; | ||
|
||
/** | ||
* @descrioption try get thumbnail for youtube videos | ||
* | ||
* ! other platforms may be added later | ||
* | ||
* current avaliable: | ||
* * youtube (url completation based) | ||
* * vimeo (vimeo api based) (replaces largest thumbnail resolution value with '1920') | ||
* | ||
* in progress: | ||
* | ||
*/ | ||
if(metadata.provider == 'youtube'){ | ||
let turl = `https://img.youtube.com/vi/${metadata.id}`; | ||
|
||
await fetch(`${turl}/maxresdefault.jpg`, { | ||
method: 'GET' | ||
}).then(r => { | ||
if(r.status == 200){ | ||
metadata.thumb = `${turl}/maxresdefault.jpg`; | ||
} | ||
else{ | ||
metadata.thumb = `${turl}/0.jpg`; | ||
} | ||
}) | ||
} | ||
else if(metadata.provider == 'vimeo'){ | ||
let apiURL = `https://vimeo.com/api/v2/video/${metadata.id}.json` | ||
await fetch(apiURL, { | ||
method: 'GET' | ||
}).then(r => r.json()).then(r => { | ||
let thum = r[0].thumbnail_large.replace(/_[0-9]{1,4}/gi, '_1920'); | ||
metadata.thumb = thum; | ||
metadata.thumbOriginal = r[0].thumbnail_large; | ||
}); | ||
} | ||
|
||
if(onlyThumb){ | ||
return {thumb: metadata.thumb, originalSize: metadata.thumbOriginal}; | ||
} | ||
else{ | ||
return metadata; | ||
} | ||
|
||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# youtube thumbnail URLS | ||
|
||
* <https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api> | ||
* <https://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo> |