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

Provide mediaMetadata field in the api response #613

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions src/modules/processing/matchActionDecider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand Down
6 changes: 4 additions & 2 deletions src/modules/processing/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 14 additions & 1 deletion src/modules/processing/services/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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 };
Expand Down
6 changes: 6 additions & 0 deletions src/modules/processing/services/vk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
12 changes: 11 additions & 1 deletion src/modules/processing/services/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,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,
}
}

Expand Down