A simple python script and it's used for mp4 type video downloading from youtube.

Overview

Youtube Video Downloader Python Script

Build


Description

This is a simple python script and it's used for mp4 type video downloading from youtube. also, it's used inbuilt python module "pytube". Furthermore, I know we have so many apps and online websites to do the same thing so it's just an experiment to study how to do those things in python.


Feature

  • Easy to download youtube videos
  • You can choose a video format would you like
  • MPEG4 format video

Pre-Requests

  • python 3.x
  • python3-pip

How to Install Python (for windows)

once you have installed git bash then please use your windows command prompt with limited linux commands

Pre-Requests (for RedHat-based-Linux)

yum install -y git
yum install -y python3
yum install -y python3-pip

Pre-Requests (for Debian-based-Linux)

apt install -y git
apt install -y python3
apt install -y python3-pip

Pre-Requests (for Termux-based-Linux)

pkg upgrade
pkg install git
pkg install python3
pkg install pip

using termux who you guys please install requirements use pip install -r requirements.txt don't need to use pip3


Modules Used


How to Get

git clone https://github.com/yousafkhamza/youtube-video-downloader-pyscript.git
cd youtube-video-downloader-pyscript
pip3 install -r requirements.txt

How to execute

python3 youtube_downloader.py

Output be like

dir Downloads Volume in drive C is Windows Directory of C:\Users\yousa\youtube-video-downloader-pyscript\Downloads 01/10/2022 08:49 AM 13,601,616 Thathaka Theithare Video Song Hridayam Pranav Vineeth Prithviraj Hesham Visakh Merryland.mp4 C:\Users\yousa\youtube-video-downloader-pyscript>">
C:\Users\yousaf>git clone https://github.com/yousafkhamza/youtube-video-downloader-pyscript.git
Cloning into 'youtube-video-downloader-pyscript'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 9 (delta 2), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (9/9), done.
Resolving deltas: 100% (2/2), done.

C:\Users\yousaf>cd youtube-video-downloader-pyscript

C:\Users\yousaf\youtube-video-downloader-pyscript>pip3 install -r requirements.txt
Collecting pytube
  Downloading pytube-11.0.2-py3-none-any.whl (56 kB)
     |████████████████████████████████| 56 kB 654 kB/s
Installing collected packages: pytube
Successfully installed pytube-11.0.2

C:\Users\yousaf\youtube-video-downloader-pyscript>python3 youtube_downloader.py
Youtube URL: https://youtu.be/gJB3l7uc4RA                            <------------------- URL pasted here.

Fetching "Thathaka Theithare Video Song | Hridayam | Pranav | Vineeth | Prithviraj | Hesham |Visakh |Merryland"..
Information:
Highest Resolution: 720p
Author: Think Music India
Views: 1,312,619

Available Formats:
['360p', '720p']
Choose one format would you like to download (eg:360p): 720p        <------------------- Choose any resolution when available here.

Information about the video format you had selected:
File size: 13.6 MB
Selected Resolution: 720p

Downloading....
69.38%
100.00%
Download Successful
Please go and watch the same under 'C:\Users\yousaf\youtube-video-downloader-pyscript/Downloads'....

C:\Users\yousaf\youtube-video-downloader-pyscript>dir Downloads
 Volume in drive C is Windows

 Directory of C:\Users\yousa\youtube-video-downloader-pyscript\Downloads

01/10/2022  08:49 AM        13,601,616 Thathaka Theithare Video Song  Hridayam  Pranav  Vineeth  Prithviraj  Hesham Visakh Merryland.mp4

C:\Users\yousa\youtube-video-downloader-pyscript>

ScreenShots

alt_txt alt_txt


Behind the code

import pytube  
from pytube import YouTube  
import os


current_path = os.getcwd()
if not os.path.exists("./Downloads"):
    os.makedirs("./Downloads")

video_url = input("Youtube URL: ")
    
def on_progress(stream, chunk, bytes_remaining):
    total_size = stream.filesize
    bytes_downloaded = total_size - bytes_remaining
    percentage_of_completion = bytes_downloaded / total_size * 100
    formated_percentage = "{:.2f}".format(percentage_of_completion)
    print(formated_percentage+"%")
        
def main():
    chunk_size = 1024
    video = yt.streams.get_highest_resolution()
    title = video.title
    print(f"\nFetching \"{video.title}\"..")
    print(f"Information: \n"
          f"Highest Resolution: {video.resolution}\n"
          f"Author: {yt.author}")
    print("Views: {:,}".format(yt.views))

    print("\nAvailable Formats: ")
    A=[]
    res=yt.streams.filter(progressive=True, file_extension='mp4')
    if res.filter(resolution="360p"):
        A.append("360p")

    if res.filter(resolution="480p"):
        A.append("480p")

    if res.filter(resolution="720p"):
        A.append("720p")

    if res.filter(resolution="1080p"):
        A.append("1080p")

    if res.filter(resolution="1440p"):
        A.append("1440p")
    print(A)
    
    format_res = input("Chosse one format would you like to download (eg:360p): ")
    if format_res.endswith("p"):
        if format_res in A:
            video = yt.streams.filter(res=format_res, file_extension = "mp4").first()
            print(f"\nInformation about the video format you had selected: \n"
                  f"File size: {round(video.filesize * 0.000001, 2)} MB\n"
                  f"Selected Resolution: {video.resolution}\n")
            print("Downloading....")
            yt.register_on_progress_callback(on_progress)
            yt.streams.filter(res=format_res, file_extension = "mp4").first().download("./downloads")
            print("Download Successful")
            print("Please go and watch same under '{}/Downloads'....".format(current_path))
        else:
            print("Choose a valid format from the available list mentioned above")
    else:
        format_res=format_res+"p"
        if format_res in A:
            video = yt.streams.filter(res=format_res, file_extension = 'mp4').first()
            print(f"\nInformation of the current video format: \n"
                  f"File size: {round(video.filesize * 0.000001, 2)} MB\n"
                  f"Selected Resolution: {video.resolution}\n")
            print("Downloading....")
            yt.register_on_progress_callback(on_progress)
            yt.streams.filter(res=format_res, file_extension = 'mp4').first().download("./downloads")
            print("Download Successful")
            print("Please go and watch the same under '{}/Downloads'....".format(current_path))
        else:
            print("Choose a valid format from the available list mentioned above")
            
if video_url.startswith("http"):
    yt=YouTube(video_url)
    main()
else:
    print("Please enter a valid URL.")

Conclusion

This is a simple python script and it's used for mp4 type video downloading from youtube.

⚙️ Connect with Me


Owner
Yousaf K Hamza
DevOps Engineer
Yousaf K Hamza
AkShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库

Overview AkShare requires Python(64 bit) 3.7 or greater, aims to make fetch financial data as convenient as possible. Write less, get more! Documentat

Albert King 5.8k Jan 03, 2023
A toolkit to automatically crawl the paper list and download paper pdfs of ACL Ahthology.

ACL-Anthology-Crawler A toolkit to automatically crawl the paper list and download paper pdfs of ACL Anthology

Ray GG 9 Oct 09, 2022
Super S3 command line tool

s4cmd Super S3 command line tool Author: Chou-han Yang (@chouhanyang) Current Maintainers: Debodirno Chandra (@debodirno) | Naveen Vardhi (@rozuur) |

Bloomreach 1.2k Dec 27, 2022
a simple ehentai downloader with jpg 2 pdf

Simple_Ehentai_DownLoader a simple ehentai downloader with jpg 2 pdf 中文介绍 Environment python3.8 How to use before you start,there are some tips. the q

Hibian 6 Dec 11, 2022
QGIS plugin to dwonload DEMs from OpenTopography.org

OpenTopography-DEM-Downloader-qgis-plugin QGIS plugin to dwonload DEMs from OpenTopography.org This plug-in allows you to download DEMs from OpenTopgr

Kyaw Naing Win 7 Sep 20, 2022
Python-Youtube-Downloader - An Open Source Python Youtube Downloader

Python-Youtube-Downloader Hello There This Is An Open Source Python Youtube Down

Flex Tools 3 Jun 14, 2022
An automatic beatmapset downloader via txt file, suitable for tourney mappools.

Pooler Pooler is a bulk osu! mapset downloader, perfect for use with osu! Tournament Mappools. Prerequisites Python 3.10 Requests (pip install request

Thomas 0 Feb 11, 2022
YouTube to MP3 or 4, you get to choose...

UTubeToMP YouTube to MP3 or 4, you get to choose... If you don't wanna git clone andor dont wanna install python. Here: Repl.it Instructions: Pretty s

1 Jan 29, 2022
A standalone pytube wrapper for downloading individual videos from YouTube.

pytube-runner This is a Python CLI script for downloading individual videos from YouTube. The pytube project is the core of this runner, so naturally

Shiva 2 Jun 21, 2022
Downloads photos you saved from a specific profile.

instagram-download-saved A python script that downloads photos you saved from a specific profile. The only dependency is instaloader, an open-source p

Aviv 1 Dec 19, 2021
Newsemble is an API that provides easy access to the current news for programmatic analysis

Newsemble is an API that provides easy access to the current news for programmatic analysis. It has been built using Python, BeautifulSoup and MongoDB.

Rishabh 43 Dec 16, 2022
Download all posts and comments in a subreddit

subreddit downloader This subreddit downloader downloads all posts and comments in a subreddit For a tutorial to use this program please follow this m

Guneet 6 Dec 16, 2022
A small distributed download manager to help bypass device-specific bandwidth limitations.

Distributed Download Manager A small distributed download manager to help bypass device-specific bandwidth limitations. Architecture The download mana

Anand Balaji 3 Sep 23, 2022
Fetch papers and metadata.

Fetch PubMed Central for open-access papers as well as Sci-Hub

4 Oct 31, 2022
GTK4 + Python tutorial with code examples

Taiko's GTK4 Python tutorial Wanna make apps for Linux but not sure how to start with GTK? This guide will hopefully help! The intent is to show you h

190 Jan 08, 2023
Convert BMS songs to osu! With options to convert keysounds and convert to 7key.

bmx2osu Convert BMS to osu! With options to: convert keysounds to one song file using BMX2WAV include 7k version change Overall Difficulty and HP Drai

7 Nov 28, 2022
Simple python script to download .mp3 formatted files from YouTube video URLs

Introduction: Simple python script to download .mp3 formatted files from YouTube video URLs Requirements: Requires: youtube_dl module Requires: ffmpeg

Pat 2 Aug 18, 2022
Python module to download all media from a GoFile gallery.

GoFile Downloader Setup First of all, clone this repository : ~$ git clone https://github.com/quatrecentquatre-404/gofile-downloader Second, oh wait..

Quatrecentquatre 61 Jan 01, 2023
This repository contains code for a youtube-dl GUI written in PyQt.

youtube-dl-GUI This repository contains code for a youtube-dl GUI written in PyQt. It is based on youtube-dl which is a Video downloading script maint

M.Yasoob Ullah Khalid ☺ 191 Jan 02, 2023
Fully Automated YouTube Channel ▶️with Added Extra Features.

Fully Automated Youtube Channel ▒█▀▀█ █▀▀█ ▀▀█▀▀ ▀▀█▀▀ █░░█ █▀▀▄ █▀▀ █▀▀█ ▒█▀▀▄ █░░█ ░░█░░ ░▒█░░ █░░█ █▀▀▄ █▀▀ █▄▄▀ ▒█▄▄█ ▀▀▀▀ ░░▀░░ ░▒█░░ ░▀▀▀ ▀▀▀░

sam-sepiol 249 Jan 02, 2023