An open API service indexing awesome lists of open source software.

https://github.com/jsem-nerad/yt-monk

A YouTube video and playlist downloader made in Python.
https://github.com/jsem-nerad/yt-monk

chrome-extension jasvascript js python python3 youtube youtube-downloader

Last synced: about 1 year ago
JSON representation

A YouTube video and playlist downloader made in Python.

Awesome Lists containing this project

README

          

YouTube Monk





A YouTube video and playlist downloader made in Python (or JS).




Report Bug
·
Request Feature


Table of Contents



  1. Important

  2. Downloads


  3. About The Project


  4. Getting Started

  5. Usage

  6. License

# !! - This doesn't work anymore. sorry. I might try to make it work again, but not for now - !!
`!! - This doesn't work anymore. sorry. I might try to make it work again, but not for now - !!`








## Downloads
#### TL;DR:

### Chrome extension
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](https://github.com/jsem-nerad/yt-monk/blob/master/dist/chrome_extension.zip) and follow the `instructions` or install on `Chrome Store` (I'll add this soon)

### Python library
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:`
```sh
pip install yt-monk
```

PyPi project site: [`yt-monk`](https://pypi.org/project/yt-monk/)

### Simple EXE file
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.

[Download here](https://github.com/jsem-nerad/yt-monk/blob/master/dist/yt_monk.exe)

### Simple Python file
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`](https://github.com/jsem-nerad/yt-monk/blob/master/yt_monk/yt_monk.py)\
Requiered libraries: [`requirements.txt`](https://github.com/jsem-nerad/yt-monk/blob/master/requirements.txt)\
The options file: [`options.json`](https://github.com/jsem-nerad/yt-monk/blob/master/examples/options.json)


## About The Project

This little project began when I wanted to download a playlist from YouTube. For downloading single videos, I always use [cobalt.tools](https://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](https://cobalt.tools) website)

So I decided to make my own YT video and playlist downloader in Python.

### Making the program
First, I downloaded a [testing video](https://www.youtube.com/watch?v=9bZkp7q19f0) and captured the network traffic from [cobalt](https://cobalt.tools), 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:
```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:

```python
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.

### To-do

- [ ] Upload extension to chrome store
- [x] Make a js chrome extension
- [x] Make an exe app
- [x] Reorganize files
- [x] Make a python package work
- [x] Upload the package to PyPi

## Getting Started

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).

### Getting the Chrome extension

I will upload it to Chrome Store soon (hopefully)


1. Download the [zipped version](https://github.com/jsem-nerad/yt-monk/blob/master/dist/chrome_extension.zip) of the Chrome extension

2. Unzip it

3. Enable `Developer mode` in Chrome in the right top corner of [`chrome://extensions/`](chrome://extensions/)

4. Click on `Load unpacked` in the left top corner

5. Select the extension directory (the directory that has `manifest.json` inside)

6. That is it!

### Getting the library

To install [the library from PyPi](https://pypi.org/project/yt-monk/), just run this command

```sh
pip install yt-monk
```

### Getting the Windows executable

1. Download [`yt_monk.exe`](https://github.com/jsem-nerad/yt-monk/blob/master/dist/yt_monk.exe)
2. Run it on Windows
3. Windows might mark it as a potential threat, so just click on `More info` and then click on `Run 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](https://pypi.org/project/yt-monk/)

### Getting the Python file

1. Download [`yt_monk.py`](https://github.com/jsem-nerad/yt-monk/blob/master/yt_monk/yt_monk.py) and [`requirements.txt`](https://github.com/jsem-nerad/yt-monk/blob/master/requirements.txt)

2. Install [`requirements.txt`](https://github.com/jsem-nerad/yt-monk/blob/master/requirements.txt) using pip:
```sh
pip install -r requirements.txt
```

3. Run it using python:

```python
python yt_monk.py
```

## Usage
Here are some basic examples of using my code

### Using as an application
When you run [`yt_monk.py`](https://github.com/jsem-nerad/yt-monk/blob/master/yt_monk/yt_monk.py) or [`yt_monk.exe`](https://github.com/jsem-nerad/yt-monk/blob/master/dist/yt_monk.exe) or use the [package](https://pypi.org/project/yt-monk/) 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.

### Using as a Python library

Import the library and define the `downloader` object:
```python
import yt_monk

downloader = yt_monk.Downloader()
```


#### Setting the options:

You can set it using keyword arguments when defining the object:

```python
downloader = yt_monk.Downloader(quality='720', codec='av1')
```

or you can set it using the `options.useCustom` function:

```python
downloader = yt_monk.Downloader()

downloader.options.useCustom(quality='720', codec='av1')
```


#### Here are all the options you can set:

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: ``, ``, ``

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: ``

ask_for_input -> if enabled, the code will ask whether or not to overwrite a file or a directory: `True` or `False`


#### Using JSON options file:
Alternatively, you can use a json file to set the options. You can download an example [`options.json`](https://github.com/jsem-nerad/yt-monk/blob/master/yt_monk/options.json) file here. Then just tell the code to use the JSON file:

```python
downloader = yt_monk.Downloader(json_path=r'path/to/options.json')
```

or you can do it like this:

```python
downloader = yt_monk.Downloader()

downloader.options.useJson(json_path=r'path/to/options.json')
```


#### Downloading a video:

```python
video_url = 'https://www.youtube.com/watch?v=9bZkp7q19f0'

downloader.downloadVideo(video_url)
```

#### Downloading a playlist:

```python
playlist_url = 'https://www.youtube.com/playlist?list=PLZHQObOWTQDNU6R1_67000Dx_ZCJB-3pi'

downloader.downloadPlaylist(playlist_url)
```

### Using the Chrome extension

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 :)``

## License

Distributed under the MIT License. See [`LICENSE.txt`](https://github.com/jsem-nerad/yt-monk/blob/master/LICENSE.txt) for more information