I made this program that lets the user input what they want to download. It then opens up a browser and YouTube with the keywords the user input. The user can copy and pastes as many URLs to the text file url.txt
. Simply save the text file, press enter in the python shell, and the downloading starts. Is there a way for python to detect a certain file being closed or saved so that I won't have to press enter for the downloading to start?
import webbrowser
import pytube
from subprocess import call
key = input('Input what you want to download: ')
a_website = "https://www.youtube.com/results?search_query="+key
webbrowser.open_new(a_website)
open('url.txt', 'w')
call(['notepad', 'url.txt'])
start = input('Press enter when ready to download >>> ')
with open('url.txt','r') as f:
urls = f.readlines()
number = len(urls)
num = 0
for url in urls:
num += 1
print('Downloading video',num,'of',number)
yt = pytube.YouTube(url)
stream = yt.streams.first()
stream.download()
open('url.txt', 'w')