Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement and more easly to use and i add a progressBar #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.mp4
*.mp3
/__pycache__
24 changes: 13 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import youtube_downloader as yd
import file_converter as fc
import os

print("Welcome to NeuralNine YouTube Downloader and Converter v0.2 Alpha")
print("Loading...")

import pytube
import youtube_downloader
import file_converter

print('''
What do you want?

Expand All @@ -21,22 +21,24 @@
choice = input("Choice: ")

if choice == "1" or choice == "2":
quality = input("Please choose a quality (low, medium, high, very high):")
quality = input("Please choose a quality (low or 0, medium or 1, high or 2, very high or 3):")
if choice == "2":
link = input("Enter the link to the playlist: ")
print("Downloading playlist...")
youtube_downloader.download_playlist(link, quality)
yd.download_playlist(link, quality)
print("Download finished!")
if choice == "1":
links = youtube_downloader.input_links()
links = yd.input_links()
for link in links:
youtube_downloader.download_video(link, quality)
yd.download_video(link, quality)
print("Download finished!")
elif choice == "3":
links = youtube_downloader.input_links()
links = yd.input_links()
for link in links:
print("Downloading...")
filename = youtube_downloader.download_video(link, 'low')
filename = yd.download_video(link, 'low')
print("Converting...")
file_converter.convert_to_mp3(filename)
fc.convert_to_mp3(filename)
os.remove(filename)
else:
print("Invalid input! Terminating...")
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
moviepy==1.0.3
pytube==12.1.0
27 changes: 17 additions & 10 deletions youtube_downloader.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import pytube
from pytube import YouTube, Playlist
from pytube.cli import on_progress
import os

def download_video(url, resolution):
itag = choose_resolution(resolution)
video = pytube.YouTube(url)
video = YouTube(url,on_progress_callback=on_progress)
stream = video.streams.get_by_itag(itag)
stream.download()
return stream.default_filename
Expand All @@ -12,32 +14,37 @@ def download_videos(urls, resolution):
download_video(url, resolution)

def download_playlist(url, resolution):
playlist = pytube.Playlist(url)
playlist = Playlist(url)
download_videos(playlist.video_urls, resolution)

def choose_resolution(resolution):
if resolution in ["low", "360", "360p"]:
if resolution in ["low", "360", "360p","0"]:
itag = 18
elif resolution in ["medium", "720", "720p", "hd"]:
elif resolution in ["medium", "720", "720p", "hd","1"]:
itag = 22
elif resolution in ["high", "1080", "1080p", "fullhd", "full_hd", "full hd"]:
elif resolution in ["high", "1080", "1080p", "fullhd", "full_hd", "full hd","2"]:
itag = 137
elif resolution in ["very high", "2160", "2160p", "4K", "4k"]:
elif resolution in ["very high", "2160", "2160p", "4K", "4k","3"]:
itag = 313
else:
itag = 18
return itag


def input_links():
print("Enter the links of the videos (end by entering 'STOP'):")
print("Enter the links of the videos (end by entering 'STOP' or 0):")

links = []
link = ""

while link != "STOP" and link != "stop":
link = input()
while link != "0" and link.lower() != "stop":
link = input("video_url: ")
links.append(link)

if len(links)==0:
print("you dont input links")
print("you dont input links")
os.exit()

links.pop()

Expand Down