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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  5. this software and associated documentation files (the "Software"), to deal in
  6. the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. the Software, and to permit persons to whom the Software is furnished to do so,
  9. subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. '''
  19. import gi
  20. gi.require_version('Gtk', '3.0')
  21. from gi.repository import Gtk
  22. import subprocess
  23. import time
  24. class StriemTrien(object):
  25. def __init__(self, page_url, video):
  26. self.page_url = page_url
  27. self.video = video
  28. def start_mpv(self):
  29. mpv_command = [
  30. 'mpv',
  31. '--msg-level=all=error',
  32. '--title=Striemtrien',
  33. self.page_url,
  34. ]
  35. if self.video == False:
  36. mpv_command.insert(1, '--no-video')
  37. mpv_command.insert(2, '--force-window')
  38. mpv_command.insert(3, '--window-scale=0.5')
  39. self.process = subprocess.Popen(mpv_command, stdout=subprocess.PIPE)
  40. begintime = time.time()
  41. while (time.time() - begintime) < 3:
  42. returncode = self.process.poll()
  43. if returncode == 2:
  44. error = self.process.stdout.read().decode('utf-8')
  45. win.show_message(
  46. "<b>No video could be found for the entered URL. Try again.</b>\n"
  47. + error
  48. )
  49. return
  50. Gtk.main_quit()
  51. class StriemTrienWindow(Gtk.Window):
  52. def __init__(self):
  53. Gtk.Window.__init__(self, title="Striemtrien")
  54. self.set_size_request(500, 100)
  55. self.timeout_id = None
  56. vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
  57. self.add(vbox)
  58. self.entry = Gtk.Entry()
  59. self.entry.set_text("")
  60. self.entry.connect("activate", self.on_button_clicked)
  61. vbox.pack_start(self.entry, True, True, 0)
  62. self.label = Gtk.Label()
  63. vbox.pack_start(self.label, True, True, 0)
  64. hbox = Gtk.Box(spacing=0)
  65. vbox.pack_start(hbox, True, True, 0)
  66. audio_button = Gtk.Button(label="Play audio only")
  67. hbox.pack_start(audio_button, False, False, 1)
  68. audio_button.connect("clicked", self.on_button_clicked, False)
  69. video_button = Gtk.Button(label="Play video")
  70. hbox.pack_start(video_button, True, True, 1)
  71. video_button.connect("clicked", self.on_button_clicked)
  72. def on_button_clicked(self, widget, video=True):
  73. page_url = self.entry.get_text()
  74. striemtrien = StriemTrien(page_url, video)
  75. striemtrien.start_mpv()
  76. def show_message(self, message):
  77. print(message)
  78. self.label.set_markup(message)
  79. if __name__ == '__main__':
  80. win = StriemTrienWindow()
  81. win.connect("delete-event", Gtk.main_quit)
  82. win.set_wmclass("Striemtrien", "Striemtrien")
  83. win.set_title("Striemtrien")
  84. win.show_all()
  85. Gtk.main()