A Python script to download Audio, Video and Playlist of audio and video files just by providing the URL and get them at the best quality.
For Asynchrnous go here
Tested and developed on Windows 7 32-bit SP1, Ubuntu GNOME 16.04 LTS, Ubuntu 16.10 and macOS Sierra 10.12.5
youtube-dl
- Used to download the file from the internetffmpeg
- Used for postprocess data, i.e., to convert file from .webm to .mp3 format
For Light weight script without error handling, run ydl-lite.py
, you can skip the unnecessary library installations that way. But, you can't do monkey error testing with it.
Libraries used on Py 3.6.1 Anaconda, works with other py3 versions and distributions for ydl.py
and ydl-windows.py
.
- subprocess - For running commands from python.
- os - to get the current working directory.
- urllib.request - For making GET methods
- urllib.error - For considering URLError
- sys - For exiting out of the script
- bs4 - For scraping content while the user is connected to the internet or not, in case of wifi-connected , but not logged in
- lxml - For parsing the HTML document
If you don't have either of the last two packages install them using,
pip install bs4
and
pip install lxml
If you don't have pip3 or pip go or dunno which one to use go here
-
On Windows
-
Install
youtube-dl
via cmdpip install youtube-dl
-
Install
ffmpeg
from here and the instructions -
And important thing : Move the contents of ffmpeg/bin/ to the location where
youtube-dl.py
is present as described in the issue -
Run the script
ydl-windows.py
via cmd
-
-
On Ubunutu or similar Distros
-
Install
youtube-dl
via terminalpip install youtube-dl
-
Install
ffmpeg
sudo apt-get install ffmpeg
-
Run the scrpipt
ydl.py
in the terminal or the lightweight versionydl-lite.py
.
-
* On macOS
1. Install `youtube-dl` via terminal
```youtube-dl installation
brew install youtube-dl
```
2. Install `ffmpeg`
```ffmpeg installation
brew install ffmpeg
```
3. Run the scrpipt `ydl.py` in the terminal or the lightweight version `ydl-lite.py`.
### Possible errors:
It sometimes asks you to install 'pyattr' or the 'xattr' module, even GNU's 'attr' module by throwing an error
Simple solution :
```
pip install xattr
```
- wikiHow to Install FFmpeg on Windows - Helped me.
- Installing FFmpeg on all kind of environments
- extract audio with youtube-dl on windows - Hack for the issue
- YouTube download using youtube-dl embedded with Python - 2017 pretty useful summary of important stuff mentioned from youtube-dl's documentation
- Improper documentation for Python - You are all alone on the sea to understand the code and try if you want to use the package 'youtube_dl' , gave up trying to use the classes.
- for format conversion and extracting audio followed this
- Your downloads resume, if your laptop falls asleep or enters sleep mode, assuming the terminal is still left open.
- In case of network error or out of storage, if you establish the connection back or clear someother storage for the sake of playlist, restart the script with the same link at the same location. It resumes downloading from the place where it left, instead of downloading the entire playlist again from the beginning.
- If you are concerned about the data usage like every other Indian (incl myself), don't worry quality control is present for video and video playlist downloads.
Thanks @MINOSai for quality control.