1

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')
xilpex
  • 3,097
  • 2
  • 14
  • 45
Red
  • 26,798
  • 7
  • 36
  • 58

1 Answers1

0

Here is an example of watchdog detection:

import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    path = sys.argv[1] if len(sys.argv) > 1 else '.'
    event_handler = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()