Perfect Copy of YouTube Audio

Updated:

So, you see a YouTube video, and you want to keep the audio for yourself, as perfectly as can be…

$ cclive --query-formats 'http://www.youtube.com/watch?v=BqtmXnQZ6Qk'
Checking ... ......... ....... done.
fmt05_240p|fmt17_144p|fmt18_360p|fmt34_360p|fmt35_480p|fmt36_240p : http://www.youtube.com/watch?v=BqtmXnQZ6Qk

Looking at Wikipedia, YouTube, Quality and codecs, we see format 34 and 35 provide the best audio, 128kbs AAC, and since we don't care about the video, we'll take the lower video quality, 34.

$ cclive --format 34 'http://www.youtube.com/watch?v=BqtmXnQZ6Qk'
Checking ... ....... ....... .........done.
Tonight You Belong To Me from The Jerk.flv  6.11M  [video/x-flv]
[#########################################################################]  100%  6.1M  73.6K/s  00:01:25
$ avconv -i "Tonight You Belong To Me from The Jerk.flv" \
    -vn \
    -codec copy \
    "Tonight You Belong To Me from The Jerk.m4a"
  1. We don't want video (-vn)
  2. Copy the remaining audio (do not re-encode it) (-codec copy)
  3. Add the title in the file metadata (metadata title=)
  4. AAC encoded music is usually in a MP4 container with the file extension, .m4a

Adding more metadata and normalizing are left as an exercise to the reader. ;)