Also provide mediaMetadata

This commit is contained in:
Aleksei Kolchanov 2024-07-06 22:56:26 +03:00
parent 87783a4c86
commit 4284661afe
5 changed files with 36 additions and 10 deletions

View File

@ -37,12 +37,13 @@ Content-Type: application/json
### response body variables
| key | type | variables |
|:-------------|:---------|:------------------------------------------------------------|
| `status` | `string` | `error / redirect / stream / success / rate-limit / picker` |
| `text` | `string` | various text, mostly used for errors |
| `url` | `string` | direct link to a file or a link to cobalt's live render |
| `pickerType` | `string` | `various / images` |
| `picker` | `array` | array of picker items |
| `audio` | `string` | direct link to a file or a link to cobalt's live render |
| `status` | `string` | `error / redirect / stream / success / rate-limit / picker` |
| `text` | `string` | various text, mostly used for errors |
| `url` | `string` | direct link to a file or a link to cobalt's live render |
| `pickerType` | `string` | `various / images` |
| `picker` | `array` | array of picker items |
| `audio` | `string` | direct link to a file or a link to cobalt's live render |
| `mediaMetadata` | `object` | Supported only on YouTube and Twitter videos. Object, that contains values `duration` (duration of the video in seconds), `likes` and `views` |
### picker item variables
item type: `object`

View File

@ -14,6 +14,7 @@ export default function(r, host, userFormat, isAudioOnly, lang, isAudioMuted, di
filename: r.filenameAttributes ?
createFilename(r.filenameAttributes, filenamePattern, isAudioOnly, isAudioMuted) : r.filename,
fileMetadata: !disableMetadata ? r.fileMetadata : false,
mediaMetadata: r.mediaMetadata,
requestIP
},
params = {},

View File

@ -59,13 +59,15 @@ export function createResponse(responseType, responseData) {
case "redirect":
response = {
url: responseData.u
url: responseData.u,
mediaMetadata: responseData.mediaMetadata,
}
break;
case "stream":
response = {
url: createStream(responseData)
url: createStream(responseData),
mediaMetadata: responseData.mediaMetadata,
}
break;

View File

@ -159,12 +159,18 @@ export default async function({ id, index, toGif, dispatcher }) {
case 0:
return { error: 'ErrorNoVideosInTweet' };
case 1:
const mediaMetadata = {
duration: Math.round(media[0].video_info.duration_millis / 1000),
likes: baseTweet.favorite_count,
views: Number(tweetResult.views.count)
};
return {
type: needsFixing(media[0]) ? "remux" : "normal",
urls: bestQuality(media[0].video_info.variants),
filename: `twitter_${id}.mp4`,
audioFilename: `twitter_${id}_audio`,
isGif: media[0].type === "animated_gif"
isGif: media[0].type === "animated_gif",
mediaMetadata
};
default:
const picker = media.map((content, i) => {
@ -180,10 +186,17 @@ export default async function({ id, index, toGif, dispatcher }) {
})
}
const mediaMetadata = {
duration: Math.round(content.video_info.duration_millis / 1000),
likes: baseTweet.favorite_count,
views: Number(tweetResult.views.count)
};
return {
type: 'video',
url,
thumb: content.media_url_https,
mediaMetadata
}
});
return { picker };

View File

@ -218,16 +218,25 @@ export default async function(o) {
urls = [video.decipher(yt.session.player), audio.decipher(yt.session.player)];
}
const mediaMetadata = {
duration: info.basic_info.duration,
likes: info.basic_info.like_count,
views: info.basic_info.view_count
};
if (match) {
filenameAttributes.qualityLabel = match.quality_label;
filenameAttributes.resolution = `${match.width}x${match.height}`;
filenameAttributes.extension = codecMatch[format].container;
filenameAttributes.youtubeFormat = format;
return {
type,
urls,
filenameAttributes,
fileMetadata
fileMetadata,
mediaMetadata,
}
}