Skip to main content

A simple Python package for downloading videos and playlists from YouTube

Project description

YouTube Monk

A YouTube video and playlist downloader made in Python.

Report Bug · Request Feature

Table of Contents
  1. Important
  2. About The Project
  3. Getting Started
  4. Usage
  5. License

Important

This is my first project uploaded to Github. If you find a mistake or just anything you don't like, just let me know and I'll try to fix it.

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

Making the program

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.

To-do

  • Make a python package work
  • Upload the package to PyPi
  • Make a cli app
  • Make a js chrome extension
  • Make an exe app
  • Reorganize files

Getting Started

Now you have 3 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 or you can install it as a python library and use it in your code.

Getting the Windows executable

  1. Download yt_monk.exe

  2. Run it on Windows

  3. Windows might mark it as a , 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.

Getting the Python file

  1. Download yt_monk.py and requirements.txt

  2. Install requirements.txt using pip:

    pip install -r requirements.txt
    
  3. Run it using python:

    python yt_monk.py
    

Getting the library

I am stil working on getting it uploaded to PyPi. That is it for now.

Usage

Here are some basic examples of using my code

Using as an application

When you run yt_monk.py or yt_monk.exe 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:

import yt_monk

downloader = yt_monk.YT_Downloader()

Downloading a video:

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

downloader.downloadVideo(video_url)

Downloading a playlist:

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

downloader.downloadPlaylist(playlist_url)

License

Distributed under the MIT License. See LICENSE.txt for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yt_monk-0.1.1a0.tar.gz (10.9 kB view hashes)

Uploaded Source

Built Distribution

yt_monk-0.1.1a0-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page