muzier-cli - A Command Line Tool to Download MP3 from Youtube

There are number of tools available for downloading youtube mp3 using command line interface tool. But these tools generally needs a video player like vlc or mplayer. The muzier command line interface i.e muzier-cli downloads mp3 from youtube and soundcloud without using these players. By default, this is basically a YouTube audio player and down-loader. This article covers setup of muzier-cli in Ubuntu 16/CentOS 7 and its usages.

Muzier-cli needs FFMPEG, nodejs>=4.4.5. Therefore you need to install these dependencies before setting up muzier-cli. To install muzier-cli, you also need YARN package manager.

Install FFMPEG

Use apt-get to install ffmpeg in Ubuntu 16

# sudo apt-get update
# sudo apt-get install ffmpeg
# ffmpeg -v
ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg
developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609

Install FFMPEG in CentOS 7 using Nux Dextop repo.

Install YARN/Node

Yarn is a package manager for your code. It allows you to use and share code with other developers from around the world. Yarn does this quickly, securely, and reliably so you don’t ever have to worry.

On Ubuntu 16

Add yarn key to apt database and install it.

# curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
OK
# echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
deb https://dl.yarnpkg.com/debian/ stable main
# sudo apt-get update && sudo apt-get install yarn
Setting up nodejs (4.2.6)
.........................

The above command will also install nodejs version 4.2.6 but muzier-cli needs muzier-cli>=4.4.5. You need to update nodejs using nodejs package manager i.e npm. Install npm using apt-get.

# sudo apt-get install npm

Use n module from npm in order to upgrade node.

# sudo npm cache clean -f
# sudo npm install -g n
/usr/local/bin/n -> /usr/local/lib/node_modules/n/bin/n
/usr/local/lib
└── [email protected]
# sudo n stable
     install : node-v7.6.0
     mkdir : /usr/local/n/versions/node/7.6.0
     fetch : https://nodejs.org/dist/v7.6.0/node-v7.6.0-linux-x64.tar.gz
###################################################### 100.0%
   installed : v7.6.0
# sudo ln -sf /usr/local/n/versions/node/7.6.0/bin/node /usr/bin/node
# node -v
v7.6.0

On CentOS 7

Install nodejs

# curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
# yum install -y nodejs
# node -v
v6.10.1

Install Yarn

# wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
# yum install yarn

Get Youtube API key

Youtube requires all users who want to stream contents outside YouTubes website to register and create a Project to access the API. To create API key, follow the processes described below.

  1. Login to Google developers site
  2. Once you successfully logged in, create a new project by clicking  'Create project' in the top menu bar in  https://console.developers.google.com/iam-admin/projects Give a project name and click 'Create'.
  3. Now click on the link "YouTube Data API" under YouTube API.
  4. Click on the "ENABLE" button in the top section.
  5. Next click on the 'Create Credentials' button to the right.
  6. Choose the select option YouTube Data API v3 for the first select option and other UI (e.g Windows, CLI tool) for the second selection followed by public data. Next click the blue button 'What credentials do I need?.'
  7. In the next screen you should be able to copy the API key and click 'Done' button in the bottom section.

Install muzier-cli

Install muzier-cli using yarn

# yarn global add muzier-cli
yarn global v0.21.3
[1/4] Resolving packages...
...........................
...........................
success Installed "[email protected]" with binaries:
- muzier
Done in 5.45s.

Check muzier usage options using following command.

# muzier --help

   muzier 0.2.3 
     
   USAGE

     muzier  [options] 

   COMMANDS

     setup        setup youtube and soundcloud api key
       [url]           Default command                     
     help           Display help for a specific command 

   GLOBAL OPTIONS

     -h, --help         Display help                                      
     -V, --version      Display version                                   
     --no-color         Disable colors                                    
     --quiet            Quiet mode - only displays warn and error messages
     -v, --verbose      Verbose mode - will also output debug messages

Setup the API key for youtube.

# muzier setup youtube AIzaSyAyBHhjO3w1RVrKuDjr08ZMlNXOheAXcHw

Now stream youtube using muzier-cli by passing playlist id as a parameter.

# muzier youtube PLh6vppUwmWEMdp04u-tYABoDmgn9AX12n
Select Youtube playlist items (Press <space> to select, <a> to toggle all, <i> to inverse selection)
❯◯  1 Robin Thicke - Blurred Lines ft. T.I., Pharrell - yyDUC1LUXSU
 ◯  2 Adele - Someone Like You - hLQl3WQQoQ0
 ◯  3 Maroon 5 - Moves Like Jagger ft. Christina Aguilera - iEPTlhBmwRg
 ◯  4 Gotye - Somebody That I Used To Know (feat. Kimbra) - official video - 8UVNT4wvIGY
 ◯  5 The Black Eyed Peas - I Gotta Feeling - uSD4vsh1zDA
 ........................................................
 ........................................................

Save the stream specifying destination.

# muzier youtube PLh6vppUwmWEMdp04u-tYABoDmgn9AX12n --out  /home/ubuntu/Music

For Soundcloud, the process is same. You need to get the client ID from soundcloud instead of API as in the youtube.

# muzier setup soundcloud <client_id>
# muzier soundcloud <playlist_url> [--out <output_dir>]

Conclusion

Muzier-cli is a nice tool for downloading youtube/soundcloud mp3 if you use terminal very often. The installation is also pretty simple. But there is a scope for adding lot of features in it like other CLI tools. Thank you for reading this article.

About Dwijadas Dey

Dwijadas Dey is working with GNU/Linux, Open source systems since 2005. Having avid follower of GNU/Linux, He believes in sharing and spreading the open source ideas to the targeted audience. Apart from freelancing he also writes for community. His current interest includes information and network security.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.