Skip to content

Commit

Permalink
Added:
Browse files Browse the repository at this point in the history
 - Open songs folder;
 - Display song length in both playlist or single;

Code cleanup and better display
  • Loading branch information
t0ry003 committed Jun 28, 2022
1 parent f0ea11f commit 4932fcd
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import sys
import re
import shutil
from time import sleep
from pytube import YouTube
from pytube import Playlist
import moviepy.editor as mp # moviepy needs ffmpeg


# calculate the size of the songs folder
def calculate_size():
dir_name = "./Songs"
test = os.listdir(dir_name)
Expand All @@ -18,45 +20,45 @@ def calculate_size():
return size


def disk_space():
disk_space = shutil.disk_usage(".")
return disk_space


# convert bytes to MB
def convert_bytes_into_mb(num):
for i in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if num < 1024.0:
return "%3.1f %s" % (num, i)
num /= 1024.0


# convert seconds to minutes and seconds
def convert_seconds_to_minutes(seconds):
minutes = seconds // 60
seconds = seconds % 60
return f"{minutes}:{seconds}"


# download playlist
def download_playlist():
print("Insert the playlist link:")
link = input(">>")
playlist = Playlist(link)

for url in playlist:
print(url)

for vid in playlist.videos:
print(vid)

for url in playlist:
print(f"Downloading {YouTube(url).title};")
print(f"Downloading {YouTube(url).title} - {convert_seconds_to_minutes(YouTube(url).length)};")
YouTube(url).streams.filter(only_audio=True).first().download()
print(f"Downloaded {playlist.title};")
print(f"Downloaded {playlist.title} - {convert_seconds_to_minutes(playlist.length)};")


# download song
def download_song():
print("Insert the song link:")
link = input(">>")

song = YouTube(link)
print(f"Downloading {song.title};")
print(f"Downloading {song.title} - {convert_seconds_to_minutes(song.length)};")
song.streams.filter(only_audio=True).first().download()
print(f"Downloaded {song.title};")
print(f"Downloaded {song.title} - {convert_seconds_to_minutes(song.length)};")


# convert to mp3
def convert_to_mp3():
folder = "./songs"

Expand All @@ -69,6 +71,7 @@ def convert_to_mp3():
os.remove(mp4_path)


# move files to songs folder
def move():
source_path = './'
source_files = os.listdir(source_path)
Expand All @@ -90,6 +93,7 @@ def move():
os.path.join(destination_path, file))


# remove 3gbp
def remove_3gbp():
dir_name = "./Songs"
test = os.listdir(dir_name)
Expand All @@ -100,15 +104,17 @@ def remove_3gbp():

menu()


# main menu
def menu():
os.system('cls')
print("-YouTube Download Manager-\n")
check_folder = os.path.isdir("./Songs")
if check_folder:
print(
f"Songs: {convert_bytes_into_mb(calculate_size())}\nDisk Space: {convert_bytes_into_mb(disk_space()[0])}\n")
f"Songs: {convert_bytes_into_mb(calculate_size())}\nDisk Space: {convert_bytes_into_mb(shutil.disk_usage('.')[0])}\n")
choice = input(
"""A: YouTube PlayList Download;\nB: YouTube Song Download;\nQ: Quit;\n\nPlease enter your choice: """)
"""A: YouTube PlayList Download;\nB: YouTube Song Download;\nO: Open 'Songs' Folder;\nQ: Quit;\n\nPlease enter your choice: """)

if choice == "A" or choice == "a":
os.system('cls')
Expand All @@ -124,14 +130,25 @@ def menu():
convert_to_mp3()
remove_3gbp()

elif choice == "O" or choice == "o":
os.system('cls')
if check_folder:
print("Opening songs folder...")
os.startfile("Songs")
sleep(2)
else:
print("No songs folder found! Please download some songs first!")
sleep(3)
menu()

elif choice == "Q" or choice == "q":
os.system('cls')
sys.exit()

else:
os.system('cls')
print("You must only select either A, B or Q")
print("Please try again")
print("You must only select either A, B, O or Q;\nPlease try again!")
sleep(3)
menu()


Expand Down

0 comments on commit 4932fcd

Please sign in to comment.