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

Add a spinner to youtube downloads logs #139

Open
wants to merge 1 commit 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
230 changes: 230 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"progress-estimator": "^0.3.1",
"puppeteer": "23.11.1",
"youtube-dl-exec": "3.0.7",
"dotenv": "16.4.5",
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ async function main() {
logger.info(`description: ${description}`);
logger.info(`Upload date: ${JSON.stringify(uploadDate)}`);

await Promise.all([downloadThumbnail(youtubeVideoId), downloadAudio(youtubeVideoId)]);
if (env.LOAD_THUMBNAIL) {
await downloadThumbnail(youtubeVideoId);
}
await downloadAudio(youtubeVideoId);

logger.info('Posting episode to spotify');
await postEpisode(youtubeVideoInfo);
Expand Down
11 changes: 7 additions & 4 deletions src/youtube-yt-dlp/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const youtubedl = require('youtube-dl-exec');
const progress = require('progress-estimator')()
const env = require('../environment-variables');
const { AUDIO_FILE_FORMAT, THUMBNAIL_FILE_FORMAT } = require('../environment-variables');
const { parseDate } = require('../dateutils');
Expand Down Expand Up @@ -66,19 +67,21 @@ async function getVideoInfo(videoId) {
}

async function downloadThumbnail(videoId) {
logger.info(`Downloading thumbnail for video id ${videoId}`);
try {
await youtubedl(getVideoUrl(videoId), getDownloadThumbnailOptions());
const promise = youtubedl(getVideoUrl(videoId), getDownloadThumbnailOptions());
const result = await progress(promise, `Downloading thumbnail for video id ${videoId}`);
logger.info(result)
logger.info(`Downloaded thumbnail for video id ${videoId}`);
} catch (err) {
throw new Error(`Unable to download video thumbnail: ${err}`);
}
}

async function downloadAudio(videoId) {
logger.info(`Downloading audio for video id ${videoId}`);
try {
await youtubedl(getVideoUrl(videoId), getDownloadAudioOptions());
const promise = youtubedl(getVideoUrl(videoId), getDownloadAudioOptions());
const result = await progress(promise, `Downloading audio for video id ${videoId}`);
logger.info(result)
logger.info(`Downloaded audio for video id ${videoId}`);
} catch (err) {
throw new Error(`Unable to download audio: ${err}`);
Expand Down