Make Your Own Video Downloader


Youtube videos.. can’t live with them and can’t live without them. BUT sometimes we need them on our machines to work with.

As you probably already know, many of the free downloaders online are either filled with ads or might not work at all.

BUILD YOUR OWN (using Python)

Here’s how:

PREREQUISITE:
pip install pytube
pip install moviepy
(You should be using conda for this. Read here)


1. create a file name youtube_downloader.py (or whatever)

from pytube import YouTube
import os
from moviepy.editor import VideoFileClip, AudioFileClip

# Prompt the user to enter the YouTube video URL
url = input("Enter the YouTube video URL: ")

# Create a YouTube object
yt = YouTube(url)
y
# Get available streams and display resolutions
streams = yt.streams.all()
for i, stream in enumerate(streams):
    print(f"{i+1}. Resolution: {stream.resolution}, Format: {stream.mime_type}")

# Prompt the user to select a resolution
choice = int(input("Enter the number corresponding to the desired resolution: "))
selected_stream = streams[choice - 1]

# Define download directory
download_dir = 'C:/'

# Download the selected stream
file_path = selected_stream.download(download_dir)

# Check if the downloaded file is in webm format
if file_path.endswith('.webm'):
    # Download the audio stream
    audio_stream = yt.streams.get_audio_only()
    audio_file_path = audio_stream.download(download_dir)

    # Define output file paths
    output_file_path = os.path.splitext(file_path)[0] + '_with_audio.mp4'
    
    # Combine video and audio
    video_clip = VideoFileClip(file_path)
    audio_clip = AudioFileClip(audio_file_path)
    final_clip = video_clip.set_audio(audio_clip)
    
    # Write the final clip to the output file
    final_clip.write_videofile(output_file_path, codec='libx264', audio_codec='aac')

    # Remove the temporary audio file
    os.remove(audio_file_path)

    print(f"Combined video and audio saved at {output_file_path}")
else:
    print("Downloaded successfully.")

2. Create a file called: “youtube_dl.bat”

@echo off
REM Activate the virtual environment (assuming you're using a virtual environment)
call C:\miniconda\condabin\activate.bat ytube

REM Execute the Python script to download YouTube video
python download_youtube.py

Put these files in the same folder and

3. Create a shortcut on the desktop

4. Go to youtube and get a URL

5. Double click your shortcut and paste the link

6. Your file will be downloaded to the C:\ drive (you can change this easily in the .py file)

ENJOY!

Leave a Reply

Your email address will not be published. Required fields are marked *