I was playing around with youtube-dl the other day and trying to find the best way to import music into Apple Music without the need of transcoding it and always got the “zsh: no matches found: bestaudio[ext=m4a]” error.
Youtube-dl will automatically download the best audio version (which usually is .ogg) but you’d have to transcode it and transcoding means worse quality – so better to download it directly in the right format.
The best command to do so is:
youtube-dl -f bestaudio[ext=m4a] --embed-thumbnail --add-metadata {VideoURL}
Unfortunately this doesn’t work on MacOS and/or ZSH and returns said error.
There has been a bug in ZSH due to special characters in the video URL but this seems to have been fixed in more recent versions because URLs are automatically put in double quotes by ZSH. But we are on the right track and I tried escaping the “bestaudio” part and this way it works on MacOS and ZSH.
youtube-dl -f "bestaudio[ext=m4a]" --embed-thumbnail --add-metadata {VideoURL}
This is what the working command looks like. It will download the audio file only without transcoding and also embed the thumbnail and metadata. So you can import it directly into Apple Music with everything you need and get the best possible quality.
Note: For embed-thumbnail to work you need “atomicparsley” installed. You can simply install it with:
brew install atomicparsley