A YouTube video and playlist downloader made in Python (or JS).
Report Bug
·
Request Feature
Table of Contents
!! - This doesn't work anymore. sorry. I might try to make it work again, but not for now - !!
This is probalby the most usable part of my project. You can download the video directly on YouTube using a button added by the JavaScript code. You can also change the options in the popup.
Download zip and follow the instructions
or install on Chrome Store
(I'll add this soon)
This is very useful for writing your own code with downloading youtube videos. For more info about the library, check the usage
.
Install using pip:
pip install yt-monk
PyPi project site: yt-monk
This is just a test of windows executable app. It can download videos and playlists. You can not set the options yet - it is using the defaults.
This is basically the same as the EXE file, but it is not built to EXE, so you can view and edit the code. You can use custom settings if you download the example options.json
file and add json_path='path_to/options.json'
argument to the main function.
Downloading:
The code: yt_monk.py
Requiered libraries: requirements.txt
The options file: options.json
This little project began when I wanted to download a playlist from YouTube. For downloading single videos, I always use cobalt.tools, because it is ad-free and open-source, but it is still missing something... a playlist downloader. I tried a few other YT downloaders to download a playlist, but I wasn't happy with their functionality.
(cobalt website)
So I decided to make my own YT video and playlist downloader in Python.
First, I downloaded a testing video and captured the network traffic from cobalt, because I wanted to know how do they download videos:
(the network traffic capture)
Based on that capture, I found out, that the user recieves the video as a stream of data from olly.imput.net/api
. Now I need to know how to make the request to their API to get the stream URL, so I looked into the JavaScript code, that was downloading the videos:
(some of the JavaScript code of the website)
Now that I know how to get the stream URL, I can recreate it in python:
response = json.loads(requests.post(self.api_url, headers=headers, data=json.dumps(data)).text)
if response['status'] == 'stream':
stream_url = response['url']
And capture the stream to a file:
def captureStream(self, stream_url, file_path):
with requests.get(stream_url, stream=True) as r:
r.raise_for_status()
with open(file_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
Then I just made some more functions.
- Upload extension to chrome store
- Make a js chrome extension
- Make an exe app
- Reorganize files
- Make a python package work
- Upload the package to PyPi
Now you have 4 options: download it as an exe file and run it on Windows without the need to install Python or you can download the Python file and run that. You can also install it as a python library and use it in your code. The final option and the most usable one is using it as a Chrome extension (I am still working on that - it is test version).
I will upload it to Chrome Store soon (hopefully)
-
Download the zipped version of the Chrome extension
-
Unzip it
-
Enable
Developer mode
in Chrome in the right top corner ofchrome://extensions/
- Click on
Load unpacked
in the left top corner
-
Select the extension directory (the directory that has
manifest.json
inside) -
That is it!
To install the library from PyPi, just run this command
pip install yt-monk
-
Download
yt_monk.exe
-
Run it on Windows
-
Windows might mark it as a potential threat, so just click on
More info
and then click onRun anyway
(I could try to fix that, but it is not my main goal now and also idk how to fix it)If you realy don't trust it (I get it), you can download the python code or the PyPi package
-
Download
yt_monk.py
andrequirements.txt
-
Install
requirements.txt
using pip:pip install -r requirements.txt
-
Run it using python:
python yt_monk.py
Here are some basic examples of using my code
When you run yt_monk.py
or yt_monk.exe
or use the package as a cli app, you will get prompted to enter the URL
You can enter video or playlist URL (the program will detect the URL type) or q
to quit the loop.
Import the library and define the downloader
object:
import yt_monk
downloader = yt_monk.Downloader()
You can set it using keyword arguments when defining the object:
downloader = yt_monk.Downloader(quality='720', codec='av1')
or you can set it using the options.useCustom
function:
downloader = yt_monk.Downloader()
downloader.options.useCustom(quality='720', codec='av1')
codec -> "h264"
, "av1"
, "vp9"
quality -> "max"
, "2160"
, "1440"
, "1080"
, "720"
, "480"
, "360"
, "240"
, "144"
file_name -> this can be set to any valid filename. you can use placeholders: <videoTitle>
, <selectedQuality>
, <selectedCodec>
file_type -> the file type can be either "video"
or "audio"
audio_format -> "mp3"
, "ogg"
, "wav"
, "opus"
mute_audio -> True
or False
overwrite_files -> this tells the program to overwrite existing files: True
or False
overwrite_directories -> this tells the program to overwrite existing directories: True
or False
download_directory -> the directory that the downloaded files will be saved to. you can use placeholder for default download directory like C:\users\name\Downloads\
on windows: <defaultDirectory>
ask_for_input -> if enabled, the code will ask whether or not to overwrite a file or a directory: True
or False
Alternatively, you can use a json file to set the options. You can download an example options.json
file here. Then just tell the code to use the JSON file:
downloader = yt_monk.Downloader(json_path=r'path/to/options.json')
or you can do it like this:
downloader = yt_monk.Downloader()
downloader.options.useJson(json_path=r'path/to/options.json')
video_url = 'https://www.youtube.com/watch?v=9bZkp7q19f0'
downloader.downloadVideo(video_url)
playlist_url = 'https://www.youtube.com/playlist?list=PLZHQObOWTQDNU6R1_67000Dx_ZCJB-3pi'
downloader.downloadPlaylist(playlist_url)
The extension has 2 main functions: a popup and adding a button directly to YouTube website
When you open a youtube video, it automatically adds a button saying MonkLoad
, but you can change that text in the popup options. If you click that button, it downloads the video using the default options.
You can also click the extension in the right top corner to display a popup with pre-filled url of the video, or you can just enter it manually.
You can edit the options using the popup window.
try turning on the cats button :)
Distributed under the MIT License. See LICENSE.txt
for more information