You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

striemtrien.py 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. '''
  3. Copyright 2017 Justin van Steijn, Kevin Keijzer
  4. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  5. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  6. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  7. '''
  8. import gi
  9. gi.require_version('Gtk', '3.0')
  10. from gi.repository import Gtk
  11. import subprocess
  12. class StriemTrien(object):
  13. def __init__(self, page_url):
  14. youtube_dl_command = "youtube-dl --get-url " + page_url
  15. youtube_dl_output = subprocess.getoutput(youtube_dl_command)
  16. if 'ERROR' in youtube_dl_output:
  17. win.show_message("No video could be found for the entered URL. Try again.")
  18. else:
  19. video_url = youtube_dl_output
  20. mpv_command = "mpv --quiet " + video_url
  21. subprocess.Popen(mpv_command.split())
  22. Gtk.main_quit()
  23. class StriemTrienWindow(Gtk.Window):
  24. def __init__(self):
  25. Gtk.Window.__init__(self, title="Striemtrien")
  26. self.set_size_request(500, 100)
  27. self.timeout_id = None
  28. vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
  29. self.add(vbox)
  30. self.entry = Gtk.Entry()
  31. self.entry.set_text("")
  32. self.entry.connect("activate", self.on_button_clicked)
  33. vbox.pack_start(self.entry, True, True, 0)
  34. self.label = Gtk.Label()
  35. vbox.pack_start(self.label, True, True, 0)
  36. hbox = Gtk.Box(spacing=6)
  37. vbox.pack_start(hbox, True, True, 0)
  38. button = Gtk.Button(label="Play video")
  39. vbox.pack_start(button, True, True, 1)
  40. button.connect("clicked", self.on_button_clicked)
  41. def on_button_clicked(self, widget):
  42. self.label.set_text(" ")
  43. page_url = self.entry.get_text()
  44. StriemTrien(page_url)
  45. def show_message(self, message):
  46. self.label.set_text(message)
  47. if __name__ == '__main__':
  48. win = StriemTrienWindow()
  49. win.connect("delete-event", Gtk.main_quit)
  50. win.set_wmclass("Striemtrien", "Striemtrien")
  51. win.set_title("Striemtrien")
  52. win.show_all()
  53. Gtk.main()