Skip to content

Commit

Permalink
Exit early if no twitter videos detected
Browse files Browse the repository at this point in the history
This change make possible extract gif from tweets as mp4 video
  • Loading branch information
Kikobeats committed Sep 5, 2018
1 parent 25cec6f commit 273b346
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@ exports['twitter 1'] = "https://video.twimg.com/amplify_video/943561675927519232

exports['vimeo 1'] = "https://gcs-vimeo.akamaized.net/exp=1535800514~acl=%2A%2F823603782.mp4%2A~hmac=1ff98e8349d222bbb11b2e7e3105729a578f83c632a34e252db61034b2b05d6b/vimeo-prod-skyfire-std-us/01/2635/7/188175573/823603782.mp4"

exports['twitter 2'] = false

exports['vimeo 2'] = false

exports['youtube 1'] = "https://r3---sn-aigl6nek.googlevideo.com/videoplayback?keepalive=yes&fvip=3&mime=audio%2Fmp4&gir=yes&ipbits=0&lmt=1507952811949144&expire=1535818875&pl=24&mm=31%2C26&ip=95.131.170.224&mn=sn-aigl6nek%2Csn-4g5ednss&initcwndbps=301250&ms=au%2Conr&itag=140&mt=1535797130&dur=141.502&mv=m&id=o-AMQjKkqESQJsZjtvcGYi-wuToRTYpm-mUp5Ck3IHofXM&sparams=clen%2Cdur%2Cei%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&ei=G2iKW_jiIMTjV6OjsqgF&key=yt6&requiressl=yes&c=WEB&source=youtube&clen=2248120&signature=E3942E3A3682B75BD7ADA0D3B23D839993029231.CA74D985A1158F2EAD22633C998E28A30F5F28A2&ratebypass=yes"

18 changes: 11 additions & 7 deletions packages/metascraper-media-provider/src/get-media/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'

const { protocol } = require('@metascraper/helpers')
const { isEmpty, reduce } = require('lodash')

const { isTwitterUrl, getTwitterInfo } = require('./twitter-info')
const createGetMedia = require('./get-media')

const { protocol } = require('@metascraper/helpers')
const { chain } = require('lodash')

// Local cache for successive calls
let cachedVideoInfoUrl
let cachedVideoInfo
Expand All @@ -21,8 +21,11 @@ module.exports = opts => {
getTwitterInfo(url)
])

const formats = chain(videoInfo.formats)
.reduce((acc, format, index) => {
if (isEmpty(twitterVideos)) return videoInfo

const formats = reduce(
videoInfo.formats,
(acc, format, index) => {
const { url } = twitterVideos[index]
const item = {
...format,
Expand All @@ -31,8 +34,9 @@ module.exports = opts => {
extractor_key: 'Twitter'
}
return [...acc, item]
}, [])
.value()
},
[]
)

return { ...videoInfo, formats }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const getTwitterInfo = async url => {
.get(
`globalObjects.tweets.${tweetId}.extended_entities.media.0.video_info.variants`
)
.filter('bitrate')
.orderBy('bitrate', 'asc')
.value()
}
Expand Down
5 changes: 3 additions & 2 deletions packages/metascraper-media-provider/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ describe('metascraper-media-provider', () => {
})
})

describe.only('twitter', () => {
describe('twitter', () => {
;[
'https://twitter.com/verge/status/957383241714970624',
'https://twitter.com/telediario_tve/status/1036860275859775488'
'https://twitter.com/telediario_tve/status/1036860275859775488',
'https://twitter.com/Mei_Gui8/status/1037374230785142785'
].forEach(url => {
it(url, async () => {
const metadata = await metascraper({ html: '<title></title>', url })
Expand Down

0 comments on commit 273b346

Please sign in to comment.