Last active
September 3, 2022 04:32
-
-
Save jj-github-jj/3ad03361b1e970dbdbb0afd4b8b4b5df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing packages | |
# IF errors replace line 30 in cipher.py as follows | |
# var_regex = re.compile(r"^\$*\w+\W") | |
import sys | |
import os | |
ytpath=r'https://www.youtube.com/watch?v=2SCOYFkvXWQ' | |
!{sys.executable} -m pip install pytube | |
import pytube | |
from pytube import YouTube | |
# url input from user | |
yt = YouTube( | |
str(input("Enter the URL of the video you want to download: \n>> "))) | |
# extract only audio | |
video = yt.streams.filter(only_audio=True).first() | |
# check for destination to save file | |
print("Enter the destination (leave blank for current directory)") | |
destination = str(input(">> ")) or '.' | |
# download the file | |
out_file = video.download(output_path=destination) | |
# save the file | |
base, ext = os.path.splitext(out_file) | |
new_file = base + '.mp3' | |
os.rename(out_file, new_file) | |
# result of success | |
print(yt.title + " has been successfully downloaded.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment