Browse Source

Handle errors

master
jvs 2 years ago
parent
commit
220693333f
1 changed files with 23 additions and 9 deletions
  1. 23
    9
      striemtrien.py

+ 23
- 9
striemtrien.py View File

@@ -19,12 +19,19 @@ import subprocess
class StriemTrien(object):
def __init__(self, page_url):
mpv_command = "mpv --really-quiet "+page_url
self.run_command(mpv_command)
Gtk.main_quit()
def run_command(self, command):
subprocess.Popen(command.split(), stdout=subprocess.PIPE)
youtube_dl_command = "youtube-dl --get-url " + page_url
youtube_dl_output = subprocess.getoutput(youtube_dl_command)
if 'ERROR' in youtube_dl_output:
win.show_message("No video could be found for the entered URL. Try again.")
else:
video_url = youtube_dl_output
mpv_command = "mpv --really-quiet " + video_url
subprocess.Popen(mpv_command.split())
Gtk.main_quit()


class StriemTrienWindow(Gtk.Window):

@@ -38,10 +45,13 @@ class StriemTrienWindow(Gtk.Window):
self.add(vbox)

self.entry = Gtk.Entry()
self.entry.set_text("")
self.entry.set_text("https://npo.nl/live/npo-1")
self.entry.connect("activate", self.on_button_clicked)
vbox.pack_start(self.entry, True, True, 0)

self.label = Gtk.Label()
vbox.pack_start(self.label, True, True, 0)
hbox = Gtk.Box(spacing=6)
vbox.pack_start(hbox, True, True, 0)
@@ -50,8 +60,12 @@ class StriemTrienWindow(Gtk.Window):
button.connect("clicked", self.on_button_clicked)
def on_button_clicked(self, widget):
url = self.entry.get_text()
StriemTrien(url)
self.label.set_text(" ")
page_url = self.entry.get_text()
StriemTrien(page_url)
def show_message(self, message):
self.label.set_text(message)

if __name__ == '__main__':

Loading…
Cancel
Save