Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get language from twitter payload #129

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/metascraper-media-provider/src/get-media/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { isEmpty, reduce, set } = require('lodash')
const { protocol } = require('@metascraper/helpers')
const { get, reduce, set } = require('lodash')
const memoizeOne = require('memoize-one')

const createTwitterInfo = require('./twitter-info')
Expand All @@ -19,20 +19,20 @@ module.exports = opts => {
getTwitterInfo(url)
])

const twitterVideo = { ...videoInfo, extractor_key: 'Twitter' }

if (isEmpty(twitterVideos)) return twitterVideo
const { formats: twitterVideoFormats, ...twitterVideosData } = twitterVideos

const formats = reduce(
twitterVideos,
twitterVideoFormats,
(acc, twitterVideo, index) => {
const { url } = twitterVideo
set(acc, index, { ...acc[index], url, protocol: protocol(url) })
const format = get(acc, index, {})
set(acc, index, { ...format, url, protocol: protocol(url) })
return acc
},
videoInfo.formats
get(videoInfo, 'formats')
)
return { ...twitterVideo, formats }

return { ...videoInfo, ...twitterVideosData, formats }
}

return memoizeOne(getInfo)
Expand Down
18 changes: 11 additions & 7 deletions packages/metascraper-media-provider/src/get-media/twitter-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@ const getTwitterInfo = ({ getToken }) => async url => {
tweetId
)

return chain(body)
.get(
`globalObjects.tweets.${id}.extended_entities.media.0.video_info.variants`
)
.filter('bitrate')
.orderBy('bitrate', 'asc')
.value()
const tweetObj = get(body, `globalObjects.tweets.${id}`)

return {
extractor_key: 'Twitter',
language: get(tweetObj, 'lang'),
formats: chain(tweetObj)
.get('extended_entities.media.0.video_info.variants')
.filter('bitrate')
.orderBy('bitrate', 'asc')
.value()
}
}

module.exports = opts => {
Expand Down