mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 11:18:28 +00:00
improvement: isAudioOnly support in nicovideo
This commit is contained in:
parent
6524d4d44c
commit
f956af06ed
@ -189,7 +189,8 @@ export default async function(host, patternMatch, lang, obj) {
|
|||||||
case "nicovideo":
|
case "nicovideo":
|
||||||
r = await nicovideo({
|
r = await nicovideo({
|
||||||
id: patternMatch.id,
|
id: patternMatch.id,
|
||||||
quality: obj.vQuality
|
quality: obj.vQuality,
|
||||||
|
isAudioOnly: isAudioOnly,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -91,7 +91,7 @@ async function fetchContentURL(id, actionTrackId, accessRightKey, outputs) {
|
|||||||
return data.data.contentUrl;
|
return data.data.contentUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getHLSContent(contentURL, quality) {
|
async function getHLSContent(contentURL, quality, isAudioOnly) {
|
||||||
const hls = await fetch(contentURL)
|
const hls = await fetch(contentURL)
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((response) => HLS.parse(response));
|
.then((response) => HLS.parse(response));
|
||||||
@ -110,41 +110,48 @@ async function getHLSContent(contentURL, quality) {
|
|||||||
.shift();
|
.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const audioUrl = hlsContent.audio.pop().uri;
|
||||||
|
return isAudioOnly
|
||||||
|
? { resolution: null, urls: audioUrl, type: "audio" }
|
||||||
|
: {
|
||||||
resolution: hlsContent.resolution,
|
resolution: hlsContent.resolution,
|
||||||
urls: [hlsContent.uri, hlsContent.audio.pop().uri],
|
urls: [hlsContent.uri, audioUrl],
|
||||||
|
type: "video",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO @synzr only audio support
|
|
||||||
// TODO @synzr better error handling
|
// TODO @synzr better error handling
|
||||||
export default async function nicovideo({ id, quality }) {
|
export default async function nicovideo({ id, quality, isAudioOnly }) {
|
||||||
try {
|
try {
|
||||||
const { actionTrackId, title, author } = await getBasicVideoInformation(id);
|
const { actionTrackId, title, author } = await getBasicVideoInformation(id);
|
||||||
const {
|
const { resolution, urls, type } = await fetchGuestData(id, actionTrackId)
|
||||||
resolution,
|
|
||||||
urls: [video, audio],
|
|
||||||
} = await fetchGuestData(id, actionTrackId)
|
|
||||||
.then(({ accessRightKey, outputs }) =>
|
.then(({ accessRightKey, outputs }) =>
|
||||||
fetchContentURL(id, actionTrackId, accessRightKey, outputs)
|
fetchContentURL(id, actionTrackId, accessRightKey, outputs)
|
||||||
)
|
)
|
||||||
.then((contentURL) => getHLSContent(contentURL, quality));
|
.then((contentURL) => getHLSContent(contentURL, quality, isAudioOnly));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
urls: [video, audio],
|
urls,
|
||||||
|
isAudioOnly: type === "audio",
|
||||||
|
fileMetadata: {
|
||||||
|
title: cleanString(title.trim()),
|
||||||
|
artist: cleanString(author.nickname.trim()),
|
||||||
|
},
|
||||||
|
// bible accurate object concatenation
|
||||||
filenameAttributes: {
|
filenameAttributes: {
|
||||||
service: "nicovideo",
|
service: "nicovideo",
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
author: author.nickname,
|
author: author.nickname,
|
||||||
resolution: `${resolution.width}x${resolution.height}`,
|
...(type === "video"
|
||||||
qualityLabel: `${resolution.height}p`,
|
? {
|
||||||
extension: "mp4",
|
extension: "mp4",
|
||||||
|
qualityLabel: `${resolution.height}p`,
|
||||||
|
resolution: `${resolution.width}x${resolution.height}`,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
},
|
},
|
||||||
fileMetadata: {
|
...(type === "audio" ? { isM3U8: true, bestAudio: "mp3" } : {}),
|
||||||
title: cleanString(title.trim()),
|
|
||||||
artist: cleanString(author.nickname.trim()),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { error: "ErrorEmptyDownload" };
|
return { error: "ErrorEmptyDownload" };
|
||||||
|
Loading…
Reference in New Issue
Block a user