Created
March 13, 2014 21:15
-
-
Save Sorseg/9537124 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from queue import Empty, Queue | |
import subprocess | |
import sys | |
import threading | |
if sys.version[0] > '2': | |
import tkinter | |
else: | |
import Tkinter as tkinter | |
out_queue = Queue() | |
def dwnl(_): | |
url = url_input.get() | |
url_input.delete(0, 'end') | |
proc = subprocess.Popen(['youtube-dl.exe', '-t', url], stdout=subprocess.PIPE) | |
def poll(): | |
result = b'' | |
while 1: | |
char = proc.stdout.read(1) | |
if not char: | |
out_queue.put(result) | |
break | |
result += char | |
if char == b'\r': | |
out_queue.put(result) | |
result = b'' | |
t = threading.Thread(target=poll) | |
t.start() | |
def update(): | |
root.after(20, update) | |
try: | |
line = out_queue.get_nowait().decode('utf8').rstrip() | |
except Empty: | |
return | |
if not line: | |
return | |
if line[0] != '\n': | |
output.delete('end-1l linestart', 'end') | |
line = '\n' + line | |
output.insert('end', line) | |
update() | |
root = tkinter.Tk() | |
url_input = tkinter.Entry(root) | |
url_input.pack(expand=0, fill='x') | |
url_input.bind('<Return>', dwnl) | |
output = tkinter.Text(root) | |
output.pack(expand=1, fill='both') | |
output['bg'] = 'black' | |
output['fg'] = 'white' | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment