mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-15 17:58:31 +00:00
Added title to mediaMetadata, improved twitter mediaMetadata building
This commit is contained in:
parent
7c7c60cccc
commit
92db295619
@ -36,6 +36,17 @@ function bestQuality(arr) {
|
|||||||
.url
|
.url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildMediaMetadata(tweetResult, media){
|
||||||
|
return {
|
||||||
|
duration: Math.round(media.video_info.duration_millis / 1000) || 0,
|
||||||
|
likes: tweetResult.legacy.favorite_count || 0,
|
||||||
|
views: Number(tweetResult.views.count) || 0,
|
||||||
|
title: (tweetResult.legacy && tweetResult.legacy.full_text && Array.isArray(tweetResult.legacy.display_text_range) && tweetResult.legacy.display_text_range[0] !== undefined && tweetResult.legacy.display_text_range[1] !== undefined)
|
||||||
|
? tweetResult.legacy.full_text.substr(tweetResult.legacy.display_text_range[0], tweetResult.legacy.display_text_range[1] - tweetResult.legacy.display_text_range[0])
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let _cachedToken;
|
let _cachedToken;
|
||||||
const getGuestToken = async (dispatcher, forceReload = false) => {
|
const getGuestToken = async (dispatcher, forceReload = false) => {
|
||||||
if (_cachedToken && !forceReload) {
|
if (_cachedToken && !forceReload) {
|
||||||
@ -154,6 +165,8 @@ export default async function({ id, index, toGif, dispatcher }) {
|
|||||||
media = [media[index]]
|
media = [media[index]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(tweetResult)
|
||||||
|
|
||||||
switch (media?.length) {
|
switch (media?.length) {
|
||||||
case undefined:
|
case undefined:
|
||||||
case 0:
|
case 0:
|
||||||
@ -165,11 +178,7 @@ export default async function({ id, index, toGif, dispatcher }) {
|
|||||||
filename: `twitter_${id}.mp4`,
|
filename: `twitter_${id}.mp4`,
|
||||||
audioFilename: `twitter_${id}_audio`,
|
audioFilename: `twitter_${id}_audio`,
|
||||||
isGif: media[0].type === "animated_gif",
|
isGif: media[0].type === "animated_gif",
|
||||||
mediaMetadata: {
|
mediaMetadata: buildMediaMetadata(tweetResult, media[0])
|
||||||
duration: Math.round(media[0].video_info.duration_millis / 1000),
|
|
||||||
likes: baseTweet.favorite_count,
|
|
||||||
views: Number(tweetResult.views.count)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
const picker = media.map((content, i) => {
|
const picker = media.map((content, i) => {
|
||||||
@ -189,11 +198,7 @@ export default async function({ id, index, toGif, dispatcher }) {
|
|||||||
type: 'video',
|
type: 'video',
|
||||||
url,
|
url,
|
||||||
thumb: content.media_url_https,
|
thumb: content.media_url_https,
|
||||||
mediaMetadata: {
|
mediaMetadata: buildMediaMetadata(tweetResult, content)
|
||||||
duration: Math.round(content.video_info.duration_millis / 1000),
|
|
||||||
likes: baseTweet.favorite_count,
|
|
||||||
views: Number(tweetResult.views.count)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return { picker };
|
return { picker };
|
||||||
|
@ -221,7 +221,8 @@ export default async function(o) {
|
|||||||
const mediaMetadata = {
|
const mediaMetadata = {
|
||||||
duration: info.basic_info.duration,
|
duration: info.basic_info.duration,
|
||||||
likes: info.basic_info.like_count,
|
likes: info.basic_info.like_count,
|
||||||
views: info.basic_info.view_count
|
views: info.basic_info.view_count,
|
||||||
|
title: info.basic_info.title,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
|
Loading…
Reference in New Issue
Block a user