Skip to content

Commit

Permalink
thumbnail for video metadata and dedicated url
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheus Cesar C. - Matsukii committed Oct 8, 2019
1 parent f79b2cd commit bffad98
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 48 deletions.
124 changes: 83 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,86 +1,113 @@
# PolarPod
A set of useful apis

A set of useful apis

## this API uses

# this API uses:
* open-graph-crapper
* word filter [only english support up to now]
* atob and btoa base64
* word filter [only english support up to now]
* atob and btoa base64
* express
* js-video-url-parser

* qrcode-svg

## Inside but not in use:
## Inside but not in use

* metafetch [unused, secondary]
* nano-memoize [unused]
* mysql


# General usage

## Og tag getter

```
``` http
https://polarpod.herokuapp.com/apis/ogtags?u=[URL]
```
```

parameters:

parameters:<br>
* u: url<br>
* u: url

response:

response:<br>
* json

### see samples file or below


## SVG QR Code generator

```
``` http
https://polarpod.herokuapp.com/apis/qr?u=[URL]&d=[true]/[false]&w=[width]&c=[color]&bg=[background]
```
```

parameters:

parameters:<br>
* u: data<br>
* d: dark/light [true/false] (if true generates a lighet qr)<br>
* w: width<br>
* c: HEX color **(without the #)** _default colors: for dark themes=#CCCCCC and light=#222222_<br>
* u: data
* d: dark/light [true/false] (if true generates a lighet qr)
* w: width
* c: HEX color **(without the #)** _default colors: for dark themes=#CCCCCC and light=#222222_
* bg: background color in HEX **(without the #)** _default is transparent_
*if any param was send, a message will be showed*

response:<br>
* SVG document
response:

* SVG document

## Video URL parser

```
http://polarpod.herokuapp.com/apis/vidurl?u=[URL]
```
``` http
http://polarpod.herokuapp.com/apis/video/meta?u=[URL]
```

params:

params:<br>
* u: video url

response:<br>
response:

* json

## Video thumbnail

**same as video url parser, but with different response and url**

``` http
http://polarpod.herokuapp.com/apis/video/thumb?u=[URL]
```

supported platforms

* youtube
* vimeo

params:

* u: video url

response:

* json

## Bad-word message filter

```
``` http
https://polarpod.herokuapp.com/apis/filter?msg=[message_to_filter]
```
```

params:

params:<br>
* msg: message

response:<br>
* json
response:

* json

# responses

## og tags response sample:<br>
```
## og tags response sample

``` json
{
"name": "GitHub",
"title": "Build software better, together",
Expand All @@ -91,16 +118,32 @@ response:<br>
}
```

## video url parser:<br>
```
## video url parser

_thumbnails is currently avaliable for youtube and vimeo only_
_for youtube, maxresdefault will be retuned if avaliable, else will return '0.jpg', the same as hqdefault.jpg_
_for vimeo thumbails the image size '_640' is replaced by '_1920'_

``` json
{
"id": "jYCGSuNDy4M",
"mediaType": "video",
"provider": "youtube"
}
```
## bad-word filter:<br>
"provider": "youtube",
"thumb":"https://img.youtube.com/vi/jYCGSuNDy4M/maxresdefault.jpg"
},

{
"id": "76979871",
"mediaType": "video",
"provider": "vimeo",
"thumb":"https://i.vimeocdn.com/video/452001751_1920.jpg",
"thumbOriginal":"https://i.vimeocdn.com/video/452001751_640.jpg"
},
```

## bad-word filter

``` json
{
"msg":"****"
}
Expand All @@ -121,4 +164,3 @@ response:<br>
## LICENSE

* MIT

9 changes: 7 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"og tags api",
"video url parser api",
"bad word filter api"

],
"author": "Matsukii",
"license": "MIT",
Expand All @@ -27,6 +26,7 @@
"metafetch": "^1.9.2",
"mysql": "^2.17.1",
"nano-memoize": "^1.1.5",
"node-fetch": "^2.6.0",
"object-hash": "^1.3.1",
"open-graph-scraper": "^3.6.2",
"qrcode-svg": "^1.0.0"
Expand Down
28 changes: 26 additions & 2 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,39 @@ module.exports = (app, dir) => {
* @returns {Object} video metadata (mediaType, provider, type, chanel, id...)
*/
app.get('/apis/video/meta', function(req, res){
params = {
let params = {
url: req.query.u
}

if(params.url == undefined){
return res.status(400).send('no URL informed');
}
else{
return res.status(200).send(urlp(params))
urlp(params).then(r => {
return res.status(200).send(r)
})
}
})


/**
*
* @description get video thumbnail (is part of .../video/meta but returns only the image(s))
* @returns {Object} video metadata (mediaType, provider, type, chanel, id...)
*/
app.get('/apis/video/thumb', function(req, res){
let params = {
url: req.query.u,
thumb: true
}

if(params.url == undefined){
return res.status(400).send('no URL informed');
}
else{
urlp(params).then(r => {
return res.status(200).send(r)
})
}

})
Expand Down
53 changes: 51 additions & 2 deletions src/urlVideoParser.js
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;
}

};
4 changes: 4 additions & 0 deletions utils.md
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>

0 comments on commit bffad98

Please sign in to comment.