Skip to content

Commit

Permalink
Return a collection of urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 1, 2018
1 parent 2838e12 commit 7f54518
Show file tree
Hide file tree
Showing 5 changed files with 731 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,14 @@ exports['vimeo 1'] = {
"logo": "https://i.vimeocdn.com/favicon/main-touch_180",
"url": "https://vimeo.com/188175573"
}

exports['filter by mp4 1'] = [
"https://r6---sn-w511uxa-8aje.googlevideo.com/videoplayback?itag=160&aitags=133%2C134%2C135%2C136%2C160%2C242%2C243%2C244%2C247%2C278%2C298%2C302&mime=video%2Fmp4&pl=20&expire=1534224522&mv=m&lmt=1534184853954309&fvip=4&source=youtube&clen=1232192&id=o-AH-F7AllkKVHynK8qqnw4B_x0q76t92S_pPhPul-9lU7&mn=sn-w511uxa-8aje%2Csn-h5q7knez&mm=31%2C29&c=WEB&key=yt6&ip=95.17.206.54&keepalive=yes&signature=B71A314816CBE56289EC15C8A1C6BF7EE74C169D.164175CF39A4BDFD2DA2DE6147BD09545AAA01DE&initcwndbps=928750&gir=yes&mt=1534202758&ms=au%2Crdu&ipbits=0&requiressl=yes&sparams=aitags%2Cclen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&dur=283.850&ei=KhRyW4nkJIvkV7yXvugN&ratebypass=yes",
"https://r6---sn-w511uxa-8aje.googlevideo.com/videoplayback?itag=133&aitags=133%2C134%2C135%2C136%2C160%2C242%2C243%2C244%2C247%2C278%2C298%2C302&mime=video%2Fmp4&pl=20&expire=1534224522&mv=m&lmt=1534184853956556&fvip=4&source=youtube&clen=2122314&id=o-AH-F7AllkKVHynK8qqnw4B_x0q76t92S_pPhPul-9lU7&mn=sn-w511uxa-8aje%2Csn-h5q7knez&mm=31%2C29&c=WEB&key=yt6&ip=95.17.206.54&keepalive=yes&signature=E3307C18153DDB5E7AACAEAB9942F8B002012050.173DE890AE005232725CB8ADA7A50B7CF25692F0&initcwndbps=928750&gir=yes&mt=1534202758&ms=au%2Crdu&ipbits=0&requiressl=yes&sparams=aitags%2Cclen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&dur=283.850&ei=KhRyW4nkJIvkV7yXvugN&ratebypass=yes",
"https://r6---sn-w511uxa-8aje.googlevideo.com/videoplayback?itag=134&aitags=133%2C134%2C135%2C136%2C160%2C242%2C243%2C244%2C247%2C278%2C298%2C302&mime=video%2Fmp4&pl=20&expire=1534224522&mv=m&lmt=1534184854055225&fvip=4&source=youtube&clen=5015666&id=o-AH-F7AllkKVHynK8qqnw4B_x0q76t92S_pPhPul-9lU7&mn=sn-w511uxa-8aje%2Csn-h5q7knez&mm=31%2C29&c=WEB&key=yt6&ip=95.17.206.54&keepalive=yes&signature=3DEFAB448DC70677960CAF56B11FB769592FC440.5CD5B13E517668562CCE3F430CF16734E3DD63CA&initcwndbps=928750&gir=yes&mt=1534202758&ms=au%2Crdu&ipbits=0&requiressl=yes&sparams=aitags%2Cclen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&dur=283.850&ei=KhRyW4nkJIvkV7yXvugN&ratebypass=yes",
"https://r6---sn-w511uxa-8aje.googlevideo.com/videoplayback?itag=135&aitags=133%2C134%2C135%2C136%2C160%2C242%2C243%2C244%2C247%2C278%2C298%2C302&mime=video%2Fmp4&pl=20&expire=1534224522&mv=m&lmt=1534184854155850&fvip=4&source=youtube&clen=9629112&id=o-AH-F7AllkKVHynK8qqnw4B_x0q76t92S_pPhPul-9lU7&mn=sn-w511uxa-8aje%2Csn-h5q7knez&mm=31%2C29&c=WEB&key=yt6&ip=95.17.206.54&keepalive=yes&signature=B4B7A543DEAEEF890B8E6D2DCD83F8F07633DA9F.503058111885647E7E14FA29CA781D0AC0EACA6D&initcwndbps=928750&gir=yes&mt=1534202758&ms=au%2Crdu&ipbits=0&requiressl=yes&sparams=aitags%2Cclen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&dur=283.850&ei=KhRyW4nkJIvkV7yXvugN&ratebypass=yes",
"https://r6---sn-w511uxa-8aje.googlevideo.com/videoplayback?itag=136&aitags=133%2C134%2C135%2C136%2C160%2C242%2C243%2C244%2C247%2C278%2C298%2C302&mime=video%2Fmp4&pl=20&expire=1534224522&mv=m&lmt=1534184854254121&fvip=4&source=youtube&clen=18536895&id=o-AH-F7AllkKVHynK8qqnw4B_x0q76t92S_pPhPul-9lU7&mn=sn-w511uxa-8aje%2Csn-h5q7knez&mm=31%2C29&c=WEB&key=yt6&ip=95.17.206.54&keepalive=yes&signature=15992BA735625E478060A1DFD9C01D00C0702BE4.C887CC9578BFCBE0ABF4FFCA47139C40B07436E3&initcwndbps=928750&gir=yes&mt=1534202758&ms=au%2Crdu&ipbits=0&requiressl=yes&sparams=aitags%2Cclen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&dur=283.850&ei=KhRyW4nkJIvkV7yXvugN&ratebypass=yes",
"https://r6---sn-w511uxa-8aje.googlevideo.com/videoplayback?itag=298&aitags=133%2C134%2C135%2C136%2C160%2C242%2C243%2C244%2C247%2C278%2C298%2C302&mime=video%2Fmp4&pl=20&expire=1534224522&mv=m&lmt=1534184834230729&fvip=4&source=youtube&clen=30831030&id=o-AH-F7AllkKVHynK8qqnw4B_x0q76t92S_pPhPul-9lU7&mn=sn-w511uxa-8aje%2Csn-h5q7knez&mm=31%2C29&c=WEB&key=yt6&ip=95.17.206.54&keepalive=yes&signature=3ED7C0216A6CBFD79647E8BD4E9463A955EB2E8D.4B933FF684BCA75D1E10C2771A101A646875F4BF&initcwndbps=928750&gir=yes&mt=1534202758&ms=au%2Crdu&ipbits=0&requiressl=yes&sparams=aitags%2Cclen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&dur=283.850&ei=KhRyW4nkJIvkV7yXvugN&ratebypass=yes",
"https://r6---sn-w511uxa-8aje.googlevideo.com/videoplayback?itag=18&mime=video%2Fmp4&pl=20&expire=1534224522&mv=m&lmt=1534185137343773&fvip=4&source=youtube&clen=14141551&id=o-AH-F7AllkKVHynK8qqnw4B_x0q76t92S_pPhPul-9lU7&ratebypass=yes&mn=sn-w511uxa-8aje%2Csn-h5q7knez&mm=31%2C29&c=WEB&key=yt6&ip=95.17.206.54&signature=250354E58D1DBCA03CBD4DC9E3FB244C5E1152A0.952F5690B6C36A18ADEA9DDA89ED78148CAFA2A4&initcwndbps=928750&gir=yes&mt=1534202758&ms=au%2Crdu&ipbits=0&requiressl=yes&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&dur=283.910&ei=KhRyW4nkJIvkV7yXvugN",
"https://r6---sn-w511uxa-8aje.googlevideo.com/videoplayback?itag=22&mm=31%2C29&c=WEB&mn=sn-w511uxa-8aje%2Csn-h5q7knez&mime=video%2Fmp4&ip=95.17.206.54&pl=20&signature=26B8FCB51DC7903132039080C3888D83EC65E0F1.07B5FDE4D99FF3C3354D4D164FBC3CA838F6DEFF&expire=1534224522&initcwndbps=928750&mv=m&mt=1534202758&ms=au%2Crdu&ipbits=0&lmt=1534185082305521&requiressl=yes&sparams=dur%2Cei%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&source=youtube&ratebypass=yes&dur=283.910&id=o-AH-F7AllkKVHynK8qqnw4B_x0q76t92S_pPhPul-9lU7&key=yt6&ei=KhRyW4nkJIvkV7yXvugN&fvip=4"
]
26 changes: 8 additions & 18 deletions packages/metascraper-media-provider/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const {
isEmpty,
eq,
has,
round,
size,
get,
chain,
find,
Expand All @@ -24,32 +22,24 @@ const isHttp = video => eq(get(video, 'protocol'), 'http')
const isHttps = video => eq(get(video, 'protocol'), 'https')
const hasAudio = video => has(video, 'abr')

/**
* Get a Video source quality enough good
* compatible to be consumed for the browser.
*/
const getVideoUrl = (videos, filters = []) => {
const getVideoUrls = (videos, filters = []) => {
const urls = chain(videos)
.filter(overEvery(filters))
.orderBy('tbr', 'asc')
.map('url')
.value()

if (isEmpty(urls)) return false
const index = round(size(urls) / 2) - 1
return get(urls, index)
return isEmpty(urls) ? false : urls
}

/**
* Get a URL-like video source
*/
const getVideoProvider = async ({ url }) => {
const { formats } = await getVideoInfo(url)

const videoUrl =
getVideoUrl(formats, [isMp4, isHttps, hasAudio]) ||
getVideoUrl(formats, [isMp4, isHttp, hasAudio]) ||
getVideoUrl(formats, [isMp4, isHttps]) ||
getVideoUrl(formats, [isMp4])
getVideoUrls(formats, [isMp4, isHttps, hasAudio]) ||
getVideoUrls(formats, [isMp4, isHttp, hasAudio]) ||
getVideoUrls(formats, [isMp4, isHttps]) ||
getVideoUrls(formats, [isMp4])

return isUrl(videoUrl) && videoUrl
}
Expand Down Expand Up @@ -94,7 +84,7 @@ module.exports = () => {
}
}

module.exports.getVideoUrl = getVideoUrl
module.exports.getVideoUrls = getVideoUrls
module.exports.isMp4 = isMp4
module.exports.isHttp = isHttp
module.exports.isHttps = isHttps
Expand Down

This file was deleted.

Loading

0 comments on commit 7f54518

Please sign in to comment.