mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 11:18:28 +00:00
Merge 29ee3a6e7e
into cb2bde5b51
This commit is contained in:
commit
d25aad8d32
17
docs/api.md
17
docs/api.md
@ -35,14 +35,15 @@ Content-Type: application/json
|
||||
| `tiktokH265` | `boolean` | `true / false` | `false` | changes whether 1080p h265 videos are preferred or not. |
|
||||
|
||||
### 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 |
|
||||
| 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 |
|
||||
| `mediaMetadata` | `object` | Supported only on YouTube and Twitter videos. Object, that contains values `duration` (duration of the video in seconds), `likes`, `views`, `title` |
|
||||
|
||||
### picker item variables
|
||||
item type: `object`
|
||||
|
@ -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 = {},
|
||||
|
@ -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;
|
||||
|
||||
|
@ -36,6 +36,17 @@ function bestQuality(arr) {
|
||||
.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;
|
||||
const getGuestToken = async (dispatcher, forceReload = false) => {
|
||||
if (_cachedToken && !forceReload) {
|
||||
@ -164,7 +175,8 @@ export default async function({ id, index, toGif, dispatcher }) {
|
||||
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: buildMediaMetadata(tweetResult, media[0])
|
||||
};
|
||||
default:
|
||||
const picker = media.map((content, i) => {
|
||||
@ -184,6 +196,7 @@ export default async function({ id, index, toGif, dispatcher }) {
|
||||
type: 'video',
|
||||
url,
|
||||
thumb: content.media_url_https,
|
||||
mediaMetadata: buildMediaMetadata(tweetResult, content)
|
||||
}
|
||||
});
|
||||
return { picker };
|
||||
|
@ -49,6 +49,12 @@ export default async function(o) {
|
||||
resolution: `${quality}p`,
|
||||
qualityLabel: `${quality}p`,
|
||||
extension: "mp4"
|
||||
},
|
||||
mediaMetadata: {
|
||||
duration: js.player.params[0].duration,
|
||||
likes: js.mvData.likes,
|
||||
views: js.videoModalInfoData.views,
|
||||
title: js.mvData.title
|
||||
}
|
||||
}
|
||||
return { error: 'ErrorEmptyDownload' }
|
||||
|
@ -224,16 +224,26 @@ 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,
|
||||
title: info.basic_info.title,
|
||||
};
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user