mirror of
https://github.com/wukko/cobalt.git
synced 2025-06-12 21:27:39 +02:00
added file metadata to videos & fixed youtube dubs
This commit is contained in:
@ -9,6 +9,7 @@ export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted) {
|
||||
u: r.urls,
|
||||
service: host,
|
||||
filename: r.filename,
|
||||
fileMetadata: r.fileMetadata ? r.fileMetadata : false
|
||||
},
|
||||
params = {}
|
||||
|
||||
@ -28,10 +29,10 @@ export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted) {
|
||||
case "video":
|
||||
switch (host) {
|
||||
case "bilibili":
|
||||
params = { type: "render", time: r.time };
|
||||
params = { type: "render" };
|
||||
break;
|
||||
case "youtube":
|
||||
params = { type: r.type, time: r.time };
|
||||
params = { type: r.type };
|
||||
break;
|
||||
case "reddit":
|
||||
responseType = r.typeId;
|
||||
@ -139,8 +140,7 @@ export default function(r, host, audioFormat, isAudioOnly, lang, isAudioMuted) {
|
||||
type: processType,
|
||||
u: Array.isArray(r.urls) ? r.urls[1] : r.urls,
|
||||
audioFormat: audioFormat,
|
||||
copy: copy,
|
||||
fileMetadata: r.fileMetadata ? r.fileMetadata : false
|
||||
copy: copy
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -21,7 +21,6 @@ export default async function(obj) {
|
||||
|
||||
return {
|
||||
urls: [video[0]["baseUrl"], audio[0]["baseUrl"]],
|
||||
time: streamData.data.timelength,
|
||||
audioFilename: `bilibili_${obj.id}_audio`,
|
||||
filename: `bilibili_${obj.id}_${video[0]["width"]}x${video[0]["height"]}.mp4`
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { maxVideoDuration } from "../../config.js";
|
||||
import { cleanString } from "../../sub/utils.js";
|
||||
|
||||
let cachedID = {};
|
||||
|
||||
@ -72,8 +73,8 @@ export default async function(obj) {
|
||||
urls: file,
|
||||
audioFilename: `soundcloud_${json.id}`,
|
||||
fileMetadata: {
|
||||
title: json.title,
|
||||
artist: json.user.username,
|
||||
title: cleanString(json.title.replace(/\p{Emoji}/gu, '').trim()),
|
||||
artist: cleanString(json.user.username.replace(/\p{Emoji}/gu, '').trim()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Innertube } from 'youtubei.js';
|
||||
import { maxVideoDuration } from '../../config.js';
|
||||
import { cleanString } from '../../sub/utils.js';
|
||||
|
||||
const yt = await Innertube.create();
|
||||
|
||||
@ -50,7 +51,7 @@ export default async function(o) {
|
||||
if (info.basic_info.duration > maxVideoDuration / 1000) return { error: ['ErrorLengthLimit', maxVideoDuration / 60000] };
|
||||
|
||||
let checkBestAudio = (i) => (i["has_audio"] && !i["has_video"]),
|
||||
audio = adaptive_formats.find(i => checkBestAudio(i) && i["is_original"]);
|
||||
audio = adaptive_formats.find(i => checkBestAudio(i) && !i["is_dubbed"]);
|
||||
|
||||
if (o.dubLang) {
|
||||
let dubbedAudio = adaptive_formats.find(i => checkBestAudio(i) && i["language"] === o.dubLang);
|
||||
@ -59,24 +60,26 @@ export default async function(o) {
|
||||
isDubbed = true
|
||||
}
|
||||
}
|
||||
if (hasAudio && o.isAudioOnly) {
|
||||
let r = {
|
||||
type: "render",
|
||||
isAudioOnly: true,
|
||||
urls: audio.url,
|
||||
audioFilename: `youtube_${o.id}_audio${isDubbed ? `_${o.dubLang}`:''}`,
|
||||
fileMetadata: {
|
||||
title: info.basic_info.title,
|
||||
artist: info.basic_info.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")
|
||||
r.fileMetadata.album = descItems[2]
|
||||
r.fileMetadata.copyright = descItems[3]
|
||||
if (descItems[4].startsWith("Released on:")) r.fileMetadata.date = descItems[4].replace("Released on: ", '').trim();
|
||||
};
|
||||
return r
|
||||
|
||||
let fileMetadata = {
|
||||
title: cleanString(info.basic_info.title.replace(/\p{Emoji}/gu, '').trim()),
|
||||
artist: cleanString(info.basic_info.author.replace("- Topic", "").replace(/\p{Emoji}/gu, '').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");
|
||||
r.fileMetadata.album = descItems[2];
|
||||
r.fileMetadata.copyright = descItems[3];
|
||||
if (descItems[4].startsWith("Released on:")) {
|
||||
r.fileMetadata.date = descItems[4].replace("Released on: ", '').trim()
|
||||
}
|
||||
};
|
||||
|
||||
if (hasAudio && o.isAudioOnly) return {
|
||||
type: "render",
|
||||
isAudioOnly: true,
|
||||
urls: audio.url,
|
||||
audioFilename: `youtube_${o.id}_audio${isDubbed ? `_${o.dubLang}`:''}`,
|
||||
fileMetadata: fileMetadata
|
||||
}
|
||||
let checkSingle = (i) => ((qual(i) === quality || qual(i) === bestQuality) && i["mime_type"].includes(c[o.format].codec)),
|
||||
checkBestVideo = (i) => (i["has_video"] && !i["has_audio"] && qual(i) === bestQuality),
|
||||
@ -87,7 +90,8 @@ export default async function(o) {
|
||||
if (single) return {
|
||||
type: "bridge",
|
||||
urls: single.url,
|
||||
filename: `youtube_${o.id}_${single.width}x${single.height}_${o.format}.${c[o.format].container}`
|
||||
filename: `youtube_${o.id}_${single.width}x${single.height}_${o.format}.${c[o.format].container}`,
|
||||
fileMetadata: fileMetadata
|
||||
}
|
||||
};
|
||||
|
||||
@ -95,7 +99,8 @@ export default async function(o) {
|
||||
if (video && audio) return {
|
||||
type: "render",
|
||||
urls: [video.url, audio.url],
|
||||
filename: `youtube_${o.id}_${video.width}x${video.height}_${o.format}${isDubbed ? `_${o.dubLang}`:''}.${c[o.format].container}`
|
||||
filename: `youtube_${o.id}_${video.width}x${video.height}_${o.format}${isDubbed ? `_${o.dubLang}`:''}.${c[o.format].container}`,
|
||||
fileMetadata: fileMetadata
|
||||
};
|
||||
|
||||
return { error: 'ErrorYTTryOtherCodec' }
|
||||
|
Reference in New Issue
Block a user