Skip to content

silvanohirtie/youtube-mp3-downloader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

YouTube MP3 Downloader

A python tool that let you download and convert to mp3 a YouTube video

Install

Use the package manager pip to install youtube-dl.

pip install youtube-dl

Then you will need to install ffmpeg, for linux based machines, you will just need to use your console.
Example Ubuntu:

sudo apt update
sudo apt install ffmpeg

On windows ones instead, you will need to download the last build
At this point copy the 3 files you can find on bin folder, and paste them in the main Python's scripts folder
alt text

Info

youtube-dl will be used to download the video from youtube
ffmpeg will convert them to mp3

Setup

In the first part of the code, we will need to import unicode_literals from future and import youtube_dl
We want to make the person using the tool to choose the youtube video's link directly in the console, and not in the code, we will make that by declaring a variable named link, which will take the user's input when the tool is runned.

from __future__ import unicode_literals
import youtube_dl
print("Insert the link")
link = input ("")

alt text

YTDL Options

We need to specify all the options for the video, like the quality, the codec, etc...
We will download our video with the maximum quality and in a mp3 format

ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '320',
    }],
}

Download and convert

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([link])

Code

So our code will look like:

from __future__ import unicode_literals
import youtube_dl
print("Insert the link")
link = input ("")

ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '320',
    }],
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([link])

For any issue contact me on discord: Silvano#8106

About

A python tool that let you download and convert to mp3 a YouTube video

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages