Skip to content

Instantly share code, notes, and snippets.

@milleniumbug
Last active April 14, 2024 22:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save milleniumbug/6aae4cc5b77303d73be07cc74923fa6f to your computer and use it in GitHub Desktop.
Save milleniumbug/6aae4cc5b77303d73be07cc74923fa6f to your computer and use it in GitHub Desktop.
download video from YouTube, extract music and normalize volume
param(
[string]$url
)
yt-dlp `
$url `
--quiet `
--extract-audio `
--audio-format mp3 `
--audio-quality 3 `
--embed-thumbnail `
--embed-metadata `
--exec 'mp3gain -q -r -c "{}"'
#!/bin/bash
yt-dlp \
--quiet \
--extract-audio \
--audio-format mp3 \
--audio-quality 3 \
--embed-thumbnail \
--embed-metadata \
"$@" \
--exec 'mp3gain -q -r -c {} > /dev/null && echo {}'
@stesj4
Copy link

stesj4 commented Dec 17, 2018

Thank You, perfect. Just a couple of notations. I'm now running Ubuntu under Win 10 (Subsystem for Linux) and then I had to change from two "&&" to just one "&". It wasn't necessary under native Linux???.
I've also added a couple of lines so that the finished file is also tagged (even a Picture, only in YouTube):

#!/bin/bash
read -p ' Title : ' title
read -p 'Artist : ' artist
read -p ' Album : ' album
read -p ' Genre : ' genre
youtube-dl
"$1" \
--quiet \
--extract-audio \
--audio-format mp3 \
--audio-quality 3 \
--embed-thumbnail \
--exec 'mp3gain -q -r -c -s i {} > /dev/null & echo -n {}' \
|xargs -0 mid3v2 -t "$title" -a "$artist" -A "$album" -g "$genre"

@jazz-it
Copy link

jazz-it commented Jun 8, 2020

FYI

  • mp3gain is no longer available in repositories, does not compile and has been replaced with r128gain.
  • ReplayGain 2.0 targets the same loudness as ReplayGain 1.0 specification, but utilizes the improved ITU BS.1770 algorithm for measuring original tracks.
  • mp3gain is based on ReplayGain 1.0 specification.

Improved script: https://gist.github.com/madjoe/b981fa7f3f81089a37257e366c1ef581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment