mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 11:18:28 +00:00
Merge branch 'imputnet:current' into newgrounds-support
This commit is contained in:
commit
2439be868f
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@ -1 +0,0 @@
|
||||
custom: https://boosty.to/wukko/donate
|
@ -49,9 +49,9 @@ item type: `object`
|
||||
|
||||
| key | type | variables | description |
|
||||
|:--------|:---------|:--------------------------------------------------------|:---------------------------------------|
|
||||
| `type` | `string` | `video` | used only if `pickerType`is `various`. |
|
||||
| `type` | `string` | `video / photo / gif` | used only if `pickerType` is `various` |
|
||||
| `url` | `string` | direct link to a file or a link to cobalt's live render | |
|
||||
| `thumb` | `string` | item thumbnail that's displayed in the picker | used only for `video` type. |
|
||||
| `thumb` | `string` | item thumbnail that's displayed in the picker | used for `video` and `gif` types |
|
||||
|
||||
## GET: `/api/stream`
|
||||
cobalt's live render (or stream) endpoint. usually, you will receive a url to this endpoint
|
||||
|
13
package-lock.json
generated
13
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cobalt",
|
||||
"version": "7.14.6",
|
||||
"version": "7.15",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cobalt",
|
||||
"version": "7.14.6",
|
||||
"version": "7.15",
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"content-disposition-header": "0.6.0",
|
||||
@ -24,7 +24,7 @@
|
||||
"set-cookie-parser": "2.6.0",
|
||||
"undici": "^5.19.1",
|
||||
"url-pattern": "1.0.3",
|
||||
"youtubei.js": "^10.1.0"
|
||||
"youtubei.js": "^10.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
@ -1123,12 +1123,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/youtubei.js": {
|
||||
"version": "10.1.0",
|
||||
"resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-10.1.0.tgz",
|
||||
"integrity": "sha512-MokZMAnpWH11VYvWuW6qjPiiPmgRl5rfDgPQOpif9qXcVHoVw1hi8ePuRSD0AZSZ+uvWGe8rvas2dzp+Jv5JKQ==",
|
||||
"version": "10.2.0",
|
||||
"resolved": "https://registry.npmjs.org/youtubei.js/-/youtubei.js-10.2.0.tgz",
|
||||
"integrity": "sha512-JLKW9AHQ1qrTwBbre1aDkH8UJFmNcc4+kOSaVou5jSY7AzfFPFJK0yvX6afnLst0UVC9wfXHrLiNx93sutVErA==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/LuanRT"
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jintr": "^2.0.0",
|
||||
"tslib": "^2.5.0",
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "cobalt",
|
||||
"description": "save what you love",
|
||||
"version": "7.14.6",
|
||||
"version": "7.15",
|
||||
"author": "imput",
|
||||
"exports": "./src/cobalt.js",
|
||||
"type": "module",
|
||||
@ -40,7 +40,7 @@
|
||||
"set-cookie-parser": "2.6.0",
|
||||
"undici": "^5.19.1",
|
||||
"url-pattern": "1.0.3",
|
||||
"youtubei.js": "^10.1.0"
|
||||
"youtubei.js": "^10.2.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"freebind": "^0.2.2"
|
||||
|
@ -147,7 +147,6 @@ export default async function({ id, index, toGif, dispatcher }) {
|
||||
}
|
||||
|
||||
let media = (repostedTweet?.media || baseTweet?.extended_entities?.media);
|
||||
media = media?.filter(m => m.video_info?.variants?.length);
|
||||
|
||||
// check if there's a video at given index (/video/<index>)
|
||||
if (index >= 0 && index < media?.length) {
|
||||
@ -159,18 +158,38 @@ export default async function({ id, index, toGif, dispatcher }) {
|
||||
case 0:
|
||||
return { error: 'ErrorNoVideosInTweet' };
|
||||
case 1:
|
||||
if (media[0].type === "photo") {
|
||||
return {
|
||||
type: "normal",
|
||||
isPhoto: true,
|
||||
urls: `${media[0].media_url_https}?name=4096x4096`
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
};
|
||||
}
|
||||
default:
|
||||
const picker = media.map((content, i) => {
|
||||
if (content.type === "photo") {
|
||||
let url = `${content.media_url_https}?name=4096x4096`;
|
||||
return {
|
||||
type: "photo",
|
||||
url,
|
||||
thumb: url,
|
||||
}
|
||||
}
|
||||
|
||||
let url = bestQuality(content.video_info.variants);
|
||||
const shouldRenderGif = content.type === 'animated_gif' && toGif;
|
||||
|
||||
let type = "video";
|
||||
if (shouldRenderGif) type = "gif";
|
||||
|
||||
if (needsFixing(content) || shouldRenderGif) {
|
||||
url = createStream({
|
||||
service: 'twitter',
|
||||
@ -181,9 +200,9 @@ export default async function({ id, index, toGif, dispatcher }) {
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'video',
|
||||
type,
|
||||
url,
|
||||
thumb: content.media_url_https,
|
||||
thumb: content.media_url_https
|
||||
}
|
||||
});
|
||||
return { picker };
|
||||
|
@ -1,25 +1,27 @@
|
||||
import { Innertube, Session } from 'youtubei.js';
|
||||
import { env } from '../../config.js';
|
||||
import { cleanString } from '../../sub/utils.js';
|
||||
import { fetch } from 'undici'
|
||||
import { getCookie, updateCookieValues } from '../cookie/manager.js'
|
||||
import { fetch } from "undici";
|
||||
|
||||
import { Innertube, Session } from "youtubei.js";
|
||||
|
||||
import { env } from "../../config.js";
|
||||
import { cleanString } from "../../sub/utils.js";
|
||||
import { getCookie, updateCookieValues } from "../cookie/manager.js";
|
||||
|
||||
const ytBase = Innertube.create().catch(e => e);
|
||||
|
||||
const codecMatch = {
|
||||
h264: {
|
||||
codec: "avc1",
|
||||
aCodec: "mp4a",
|
||||
videoCodec: "avc1",
|
||||
audioCodec: "mp4a",
|
||||
container: "mp4"
|
||||
},
|
||||
av1: {
|
||||
codec: "av01",
|
||||
aCodec: "mp4a",
|
||||
videoCodec: "av01",
|
||||
audioCodec: "mp4a",
|
||||
container: "mp4"
|
||||
},
|
||||
vp9: {
|
||||
codec: "vp9",
|
||||
aCodec: "opus",
|
||||
videoCodec: "vp9",
|
||||
audioCodec: "opus",
|
||||
container: "webm"
|
||||
}
|
||||
}
|
||||
@ -94,11 +96,16 @@ const cloneInnertube = async (customFetch) => {
|
||||
|
||||
export default async function(o) {
|
||||
const yt = await cloneInnertube(
|
||||
(input, init) => fetch(input, { ...init, dispatcher: o.dispatcher })
|
||||
(input, init) => fetch(input, {
|
||||
...init,
|
||||
dispatcher: o.dispatcher
|
||||
})
|
||||
);
|
||||
|
||||
let info, isDubbed, format = o.format || "h264";
|
||||
let quality = o.quality === "max" ? "9000" : o.quality; // 9000(p) - max quality
|
||||
const quality = o.quality === "max" ? "9000" : o.quality;
|
||||
|
||||
let info, isDubbed,
|
||||
format = o.format || "h264";
|
||||
|
||||
function qual(i) {
|
||||
if (!i.quality_label) {
|
||||
@ -121,6 +128,7 @@ export default async function(o) {
|
||||
if (!info) return { error: 'ErrorCantConnectToServiceAPI' };
|
||||
|
||||
const playability = info.playability_status;
|
||||
const basicInfo = info.basic_info;
|
||||
|
||||
if (playability.status === 'LOGIN_REQUIRED') {
|
||||
if (playability.reason.endsWith('bot')) {
|
||||
@ -135,11 +143,11 @@ export default async function(o) {
|
||||
}
|
||||
|
||||
if (playability.status !== 'OK') return { error: 'ErrorYTUnavailable' };
|
||||
if (info.basic_info.is_live) return { error: 'ErrorLiveVideo' };
|
||||
if (basicInfo.is_live) return { error: 'ErrorLiveVideo' };
|
||||
|
||||
// return a critical error if returned video is "Video Not Available"
|
||||
// or a similar stub by youtube
|
||||
if (info.basic_info.id !== o.id) {
|
||||
if (basicInfo.id !== o.id) {
|
||||
return {
|
||||
error: 'ErrorCantConnectToServiceAPI',
|
||||
critical: true
|
||||
@ -148,11 +156,16 @@ export default async function(o) {
|
||||
|
||||
let bestQuality, hasAudio;
|
||||
|
||||
const filterByCodec = (formats) => formats.filter(e =>
|
||||
e.mime_type.includes(codecMatch[format].codec) || e.mime_type.includes(codecMatch[format].aCodec)
|
||||
).sort((a, b) => Number(b.bitrate) - Number(a.bitrate));
|
||||
const filterByCodec = (formats) =>
|
||||
formats
|
||||
.filter(e =>
|
||||
e.mime_type.includes(codecMatch[format].videoCodec)
|
||||
|| e.mime_type.includes(codecMatch[format].audioCodec)
|
||||
)
|
||||
.sort((a, b) => Number(b.bitrate) - Number(a.bitrate));
|
||||
|
||||
let adaptive_formats = filterByCodec(info.streaming_data.adaptive_formats);
|
||||
|
||||
if (adaptive_formats.length === 0 && format === "vp9") {
|
||||
format = "h264"
|
||||
adaptive_formats = filterByCodec(info.streaming_data.adaptive_formats)
|
||||
@ -162,27 +175,43 @@ export default async function(o) {
|
||||
hasAudio = adaptive_formats.find(i => i.has_audio && i.content_length);
|
||||
|
||||
if (bestQuality) bestQuality = qual(bestQuality);
|
||||
if (!bestQuality && !o.isAudioOnly || !hasAudio) return { error: 'ErrorYTTryOtherCodec' };
|
||||
if (info.basic_info.duration > env.durationLimit) return { error: ['ErrorLengthLimit', env.durationLimit / 60] };
|
||||
|
||||
let checkBestAudio = (i) => (i.has_audio && !i.has_video),
|
||||
audio = adaptive_formats.find(i => checkBestAudio(i) && !i.is_dubbed);
|
||||
if ((!bestQuality && !o.isAudioOnly) || !hasAudio)
|
||||
return { error: 'ErrorYTTryOtherCodec' };
|
||||
|
||||
if (basicInfo.duration > env.durationLimit)
|
||||
return { error: ['ErrorLengthLimit', env.durationLimit / 60] };
|
||||
|
||||
const checkBestAudio = (i) => (i.has_audio && !i.has_video);
|
||||
|
||||
let audio = adaptive_formats.find(i =>
|
||||
checkBestAudio(i) && i.is_original
|
||||
);
|
||||
|
||||
if (o.dubLang) {
|
||||
let dubbedAudio = adaptive_formats.find(i =>
|
||||
checkBestAudio(i) && i.language === o.dubLang && i.audio_track && !i.audio_track.audio_is_default
|
||||
);
|
||||
checkBestAudio(i)
|
||||
&& i.language === o.dubLang
|
||||
&& i.audio_track
|
||||
)
|
||||
|
||||
if (dubbedAudio) {
|
||||
audio = dubbedAudio;
|
||||
isDubbed = true
|
||||
isDubbed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!audio) {
|
||||
audio = adaptive_formats.find(i => checkBestAudio(i));
|
||||
}
|
||||
|
||||
let fileMetadata = {
|
||||
title: cleanString(info.basic_info.title.trim()),
|
||||
artist: cleanString(info.basic_info.author.replace("- Topic", "").trim()),
|
||||
title: cleanString(basicInfo.title.trim()),
|
||||
artist: cleanString(basicInfo.author.replace("- Topic", "").trim()),
|
||||
}
|
||||
if (info.basic_info.short_description && info.basic_info.short_description.startsWith("Provided to YouTube by")) {
|
||||
let descItems = info.basic_info.short_description.split("\n\n");
|
||||
|
||||
if (basicInfo?.short_description?.startsWith("Provided to YouTube by")) {
|
||||
let descItems = basicInfo.short_description.split("\n\n");
|
||||
fileMetadata.album = descItems[2];
|
||||
fileMetadata.copyright = descItems[3];
|
||||
if (descItems[4].startsWith("Released on:")) {
|
||||
@ -198,19 +227,23 @@ export default async function(o) {
|
||||
youtubeDubName: isDubbed ? o.dubLang : false
|
||||
}
|
||||
|
||||
if (hasAudio && o.isAudioOnly) return {
|
||||
if (audio && o.isAudioOnly) return {
|
||||
type: "render",
|
||||
isAudioOnly: true,
|
||||
urls: audio.decipher(yt.session.player),
|
||||
filenameAttributes: filenameAttributes,
|
||||
fileMetadata: fileMetadata,
|
||||
bestAudio: format === "h264" ? 'm4a' : 'opus'
|
||||
bestAudio: format === "h264" ? "m4a" : "opus"
|
||||
}
|
||||
|
||||
const matchingQuality = Number(quality) > Number(bestQuality) ? bestQuality : quality,
|
||||
checkSingle = i => qual(i) === matchingQuality && i.mime_type.includes(codecMatch[format].codec),
|
||||
checkRender = i => qual(i) === matchingQuality && i.has_video && !i.has_audio;
|
||||
checkSingle = i =>
|
||||
qual(i) === matchingQuality && i.mime_type.includes(codecMatch[format].videoCodec),
|
||||
checkRender = i =>
|
||||
qual(i) === matchingQuality && i.has_video && !i.has_audio;
|
||||
|
||||
let match, type, urls;
|
||||
|
||||
if (!o.isAudioOnly && !o.isAudioMuted && format === 'h264') {
|
||||
match = info.streaming_data.formats.find(checkSingle);
|
||||
type = "bridge";
|
||||
@ -218,10 +251,14 @@ export default async function(o) {
|
||||
}
|
||||
|
||||
const video = adaptive_formats.find(checkRender);
|
||||
if (!match && video) {
|
||||
|
||||
if (!match && video && audio) {
|
||||
match = video;
|
||||
type = "render";
|
||||
urls = [video.decipher(yt.session.player), audio.decipher(yt.session.player)];
|
||||
urls = [
|
||||
video.decipher(yt.session.player),
|
||||
audio.decipher(yt.session.player)
|
||||
]
|
||||
}
|
||||
|
||||
if (match) {
|
||||
|
@ -11,8 +11,7 @@
|
||||
"code": 200,
|
||||
"status": "redirect"
|
||||
}
|
||||
},
|
||||
{
|
||||
}, {
|
||||
"name": "video with mobile web mediaviewer",
|
||||
"url": "https://twitter.com/X/status/1697304622749086011/mediaViewer?currentTweet=1697304622749086011¤tTweetUser=X¤tTweet=1697304622749086011¤tTweetUser=X",
|
||||
"params": {},
|
||||
@ -137,6 +136,22 @@
|
||||
"code": 200,
|
||||
"status": "redirect"
|
||||
}
|
||||
}, {
|
||||
"name": "post with 1 image",
|
||||
"url": "https://x.com/PopCrave/status/1815960083475423235",
|
||||
"params": {},
|
||||
"expected": {
|
||||
"code": 200,
|
||||
"status": "redirect"
|
||||
}
|
||||
}, {
|
||||
"name": "post with 4 images",
|
||||
"url": "https://x.com/PopCrave/status/1816260887147114696",
|
||||
"params": {},
|
||||
"expected": {
|
||||
"code": 200,
|
||||
"status": "picker"
|
||||
}
|
||||
}, {
|
||||
"name": "retweeted video, isAudioOnly",
|
||||
"url": "https://twitter.com/hugekiwinuts/status/1618671150829309953?s=46&t=gItGzgwGQQJJaJrO6qc1Pg",
|
||||
@ -1065,6 +1080,7 @@
|
||||
}, {
|
||||
"name": "yappy",
|
||||
"url": "https://rutube.ru/yappy/c8c32bf7aee04412837656ea26c2b25b/",
|
||||
"canFail": true,
|
||||
"params": {},
|
||||
"expected": {
|
||||
"code": 200,
|
||||
|
Loading…
Reference in New Issue
Block a user