Convert youtube to mp3 [duplicate]

Solution 1:

youtube-dl has a command line option to extract the audio into an mp3 and discard the video downloaded:

youtube-dl --extract-audio --audio-format mp3 -l [YOUTUBE VIDEO LINK]

This works in my version of youtube-dl, which is 2012.09.27. Download youtube-dl from its website.

Solution 2:

You could always try clipgrab you can download youtube videos and also select which format you would like it to be in. It has a nice interface also...

ppa:clipgrab-team/ppa Launchpad logo (Click here for instructions on using PPAs.)

sudo add-apt-repository ppa:clipgrab-team/ppa && sudo apt-get update && sudo apt-get install clipgrab

by adding this ppa you will get the clipgrab package...you can search for youtube videos via this application and also copy and paste the link to the video into it and it will download the video, also you can select the format you want it in. enter image description here

Solution 3:

Ubuntu. Convert youtube video to mp3 on-line with a command line script.

http://iasptk.com/ubuntu-convert-youtube-video-mp3-line-command-line-script/

Before you can use the script make sure you have "youtube-dl" and "ffmpeg" installed. We will use youtube-dl to download youtube videos, and ffmpeg to convert them into the mp3 format. Create a new file...

gedit youtube2mp3

...and paste the following script:


#!/bin/bash

x=/tmp/.youtube-dl-$(date +%y.%m.%d_%H.%M.%S)-$RANDOM.flv

youtube-dl --output=$x --format=18 "$1"

avconv -i $x -acodec libmp3lame -ac 2 -ab 128k -vn -y "$2"

rm $x

# if you get "ERROR: unable to download video" 
# update youtube-dl with
# sudo youtube-dl -U

(avconv is used in DEBIAN and UBUNTU instead of ffmpeg)

Save and close gedit. Now install the script somewhere easily accessible.

sudo install youtube2mp3 /usr/local/bin

Now you can convert youtube videos into mp3 files by using the following command (including the double quotes):

youtube2mp3 "youtube-link" "mp3-file.mp3"

For this script to work, avconv OR ffmpeg must be able to use the libmp3lame code (libavcodec-extra-53 and libavcodec-extra-52), not provided with the ffmpeg on Ubuntu (see installation).

Also, the script is very verbose. Use the following command if you don't want to see all the messages on your screen:

youtube2mp3 "youtube-link" "mp3-file.mp3" > /dev/null

You can also use the following command to make the script run in the background. This way you will be able to run multiple instances of the script at the same time.

youtube2mp3 "youtube-link" "mp3-file.mp3" > /dev/null &

How it works

The way this script works is really simple. First it downloads the youtube video into a temporary file, converts the video to mp3 and then deletes the temporary file. Let's go through this script step-by-step.

  1. The first line of the script assigns a random .flv filename to the variable $x.

  2. The second line downloads the youtube video into the temporary file named $x. It automatically downloads the HQ version of the video if it's available.

  3. The third line extracts the audio from the video and converts it into an mp3 file with the filename you specified.

  4. The last line removes the temporary file created in step 2.

youtube-dl install from Ubuntu Software Center

youtube-dl is a small command-line program to download videos from YouTube.com and other sites that don't provide direct links to the videos served.

Solution 4:

You can use jDownloader. You can paste a youtube link and it offers you to download the video and the audio as mp3 separately. You can install jDownloader using the ppa.

sudo add-apt-repository ppa:jd-team/jdownloader
sudo apt-get update
sudo apt-get install jdownloader