mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
show ffmpeg progress
This commit is contained in:
@ -111,7 +111,7 @@ async function downloadSong(url, playlistFolder = undefined, trackId = undefined
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!presets[config.get('preset')]) {
|
if (!presets[config.get('preset')]) {
|
||||||
const fileBuffer = await toMP3(iterableStream, metadata, format.content_length, sendFeedback, increasePlaylistProgress);
|
const fileBuffer = await bufferToMP3(iterableStream, metadata, format.content_length, sendFeedback, increasePlaylistProgress);
|
||||||
writeFileSync(filePath, await writeID3(fileBuffer, metadata, sendFeedback));
|
writeFileSync(filePath, await writeID3(fileBuffer, metadata, sendFeedback));
|
||||||
} else {
|
} else {
|
||||||
const file = createWriteStream(filePath);
|
const file = createWriteStream(filePath);
|
||||||
@ -186,7 +186,7 @@ async function writeID3(buffer, metadata, sendFeedback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function toMP3(stream, metadata, content_length, sendFeedback, increasePlaylistProgress = () => { }, extension = "mp3") {
|
async function bufferToMP3(stream, metadata, content_length, sendFeedback, increasePlaylistProgress = () => { }, extension = "mp3") {
|
||||||
const chunks = [];
|
const chunks = [];
|
||||||
let downloaded = 0;
|
let downloaded = 0;
|
||||||
let total = content_length;
|
let total = content_length;
|
||||||
@ -196,7 +196,9 @@ async function toMP3(stream, metadata, content_length, sendFeedback, increasePla
|
|||||||
const ratio = downloaded / total;
|
const ratio = downloaded / total;
|
||||||
const progress = Math.floor(ratio * 100);
|
const progress = Math.floor(ratio * 100);
|
||||||
sendFeedback("Download: " + progress + "%", ratio);
|
sendFeedback("Download: " + progress + "%", ratio);
|
||||||
increasePlaylistProgress(ratio);
|
// 15% for download, 85% for conversion
|
||||||
|
// This is a very rough estimate, trying to make the progress bar look nice
|
||||||
|
increasePlaylistProgress(ratio * 0.15);
|
||||||
}
|
}
|
||||||
sendFeedback("Loading…", 2); // indefinite progress bar after download
|
sendFeedback("Loading…", 2); // indefinite progress bar after download
|
||||||
|
|
||||||
@ -214,6 +216,11 @@ async function toMP3(stream, metadata, content_length, sendFeedback, increasePla
|
|||||||
|
|
||||||
sendFeedback("Converting…");
|
sendFeedback("Converting…");
|
||||||
|
|
||||||
|
ffmpeg.setProgress(({ ratio }) => {
|
||||||
|
sendFeedback("Converting: " + Math.floor(ratio * 100) + "%", ratio);
|
||||||
|
increasePlaylistProgress(0.15 + ratio * 0.85);
|
||||||
|
});
|
||||||
|
|
||||||
await ffmpeg.run(
|
await ffmpeg.run(
|
||||||
"-i",
|
"-i",
|
||||||
safeVideoName,
|
safeVideoName,
|
||||||
@ -307,6 +314,12 @@ async function downloadPlaylist(givenUrl) {
|
|||||||
sendError("Error getting playlist info: make sure it isn't a private or \"Mixed for you\" playlist\n\n" + e);
|
sendError("Error getting playlist info: make sure it isn't a private or \"Mixed for you\" playlist\n\n" + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (playlist.items.length === 0) sendError(new Error("Playlist is empty"));
|
||||||
|
if (playlist.items.length === 1) {
|
||||||
|
sendFeedback("Playlist has only one item, downloading it directly");
|
||||||
|
await downloadSong(playlist.items[0].url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let isAlbum = playlist.title.startsWith('Album - ');
|
let isAlbum = playlist.title.startsWith('Album - ');
|
||||||
if (isAlbum) {
|
if (isAlbum) {
|
||||||
playlist.title = playlist.title.slice(8);
|
playlist.title = playlist.title.slice(8);
|
||||||
|
|||||||
Reference in New Issue
Block a user