Browse Source

Only audio.

master
jvs 2 years ago
parent
commit
7b4c48e170
1 changed files with 40 additions and 15 deletions
  1. 40
    15
      striemtrien.py

+ 40
- 15
striemtrien.py View File

@@ -18,14 +18,32 @@ import time

class StriemTrien(object):
def __init__(self, page_url):
mpv_command = ['mpv', '--really-quiet', '--title=Striemtrien', page_url]
process = subprocess.Popen(mpv_command, stderr=subprocess.PIPE)
def __init__(self, page_url, video):
self.page_url = page_url
self.video = video
def start_mpv(self):
mpv_command = [
'mpv',
'--force-window',
'--msg-level=all=error',
'--title=Striemtrien',
self.page_url,
]
if self.video == False:
mpv_command.insert(1, '--no-video')
self.process = subprocess.Popen(mpv_command, start_new_session=True)
def check(self):
begintime = time.time()
while (time.time() - begintime) < 15:
if process.poll() == 2:
win.show_message("No video could be found for the entered URL. Try again.")
while (time.time() - begintime) < 3:
returncode = self.process.poll()
if returncode == 2:
#error = self.process.stdout.read().decode('utf-8')
win.show_message(
"<b>No video could be found for the entered URL. Try again.</b>\n"
# + error
)
return
Gtk.main_quit()

@@ -41,29 +59,36 @@ class StriemTrienWindow(Gtk.Window):
self.add(vbox)

self.entry = Gtk.Entry()
self.entry.set_text("")
self.entry.set_text("https://www.youtube.com/watch?v=Y8ygKnBtKAk")
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)
hbox = Gtk.Box(spacing=0)
vbox.pack_start(hbox, True, True, 0)
button = Gtk.Button(label="Play video")
vbox.pack_start(button, True, True, 1)
button.connect("clicked", self.on_button_clicked)
audio_button = Gtk.Button(label="Play audio")
hbox.pack_start(audio_button, False, False, 1)
audio_button.connect("clicked", self.on_button_clicked, False)
video_button = Gtk.Button(label="Play video")
hbox.pack_start(video_button, True, True, 1)
video_button.connect("clicked", self.on_button_clicked)
def on_button_clicked(self, widget):
def on_button_clicked(self, widget, video=True):
page_url = self.entry.get_text()
StriemTrien(page_url)
striemtrien = StriemTrien(page_url, video)
striemtrien.start_mpv()
striemtrien.check()
def show_message(self, message):
self.label.set_text(message)
print(message)
self.label.set_markup(message)

if __name__ == '__main__':
win = StriemTrienWindow()
win.connect("delete-event", Gtk.main_quit)
win.set_wmclass("Striemtrien", "Striemtrien")

Loading…
Cancel
Save