Skip to content

Instantly share code, notes, and snippets.

@mohithgupta
Created July 12, 2021 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohithgupta/6b5f884b7c5046be42513d66b378ba51 to your computer and use it in GitHub Desktop.
Save mohithgupta/6b5f884b7c5046be42513d66b378ba51 to your computer and use it in GitHub Desktop.
YT_VLC.py without threading
import clipboard
# import threading
import time
import os
import sys
from pathlib import Path
from infi.systray import SysTrayIcon
from win10toast import ToastNotifier
from win32gui import GetWindowText, GetForegroundWindow
def done(systray):
sys.exit()
def about(systray):
command_about="start https://github.com/mohithgupta/Auto-YT_VLC-player"
os.system(command_about)
def run_step2():
link=clipboard.paste()
if( ( link.find("https://www.youtube.com/watch?v=")==0 or link.find("https://www.youtube.com/playlist?list=")==0 ) and "-vlc" in link):
link=link[:-4]
command = ("vlc " + link)
os.system('cd /d C:\\Program Files\\VideoLAN\\VLC')
os.system(command)
clipboard.copy('')
else:
pass
def get_active():
while True:
time.sleep(0.5)
if(GetWindowText(GetForegroundWindow())[-6:]=="Chrome" or GetWindowText(GetForegroundWindow())[-4:]=="Edge"):
run_step2()
if __name__ == "__main__":
toaster = ToastNotifier()
toaster.show_toast("YLC","I am running in Background ✔️",icon_path=str(Path(__file__).parent.absolute())+"\\icon\\vlc_yt.ico",duration=3,threaded=True)
menu_options = (("About", None, about),)
systray = SysTrayIcon(str(Path(__file__).parent.absolute())+"\\icon\\vlc_yt.ico", "YT_VLC", menu_options,on_quit=done)
systray.start()
# t1 = threading.Thread(target=get_active)
# t1.start()
get_active()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment