From eb9115b486b498af0b1506fcec4c3c8e39581457 Mon Sep 17 00:00:00 2001 From: 20xd6 <20xd6@airmail.cc> Date: Fri, 8 Jan 2021 16:11:25 -0500 Subject: [PATCH] First commit. Minimum viable product on both a command line video player and a gui player. Both need work and neither stream auido by default. --- README.md | 3 +++ audio-streamer.py | 31 ++++++++++++++++++++++++++ gi-test.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 README.md create mode 100755 audio-streamer.py create mode 100755 gi-test.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..f53fe40 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Audio Streamer + +A python application to stream audio, primarily from YouTube, using MPV and YouTube-dl. \ No newline at end of file diff --git a/audio-streamer.py b/audio-streamer.py new file mode 100755 index 0000000..44996ed --- /dev/null +++ b/audio-streamer.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +import mpv +import argparse +import os + +cmd_option_set = argparse.ArgumentParser(description='Stream Audio') +cmd_option_set.add_argument('audio_stream_URL', type=str, help='URL of the audio you want streamed.') +cmd_options = cmd_option_set.parse_args() + +audio_stream = cmd_options.audio_stream_URL + + + +if ( not audio_stream ): + print ("No URL given\nPlease provide one.") + os._exit(0) + +audio_player = mpv.MPV(ytdl=True, input_default_bindings=True, input_vo_keyboard=True, osc=True) + +@audio_player.on_key_press('q') +def my_q_binding(): + print('THERE IS NO ESCAPE') + +try: + audio_player.play(audio_stream) + audio_player.fullscreen + audio_player.wait_for_playback() + + del audio_player +except mpv.ShutdownError: + print("Playback has ended.") diff --git a/gi-test.py b/gi-test.py new file mode 100755 index 0000000..5579a8f --- /dev/null +++ b/gi-test.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +import gi + +import mpv +import locale + +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +locale.setlocale(locale.LC_NUMERIC, 'C') +class MainClass(Gtk.Window): + + def __init__(self): + super(MainClass, self).__init__() + self.set_default_size(600, 400) + self.connect("destroy", self.on_destroy) + + widget = Gtk.Frame() + + entry_container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) + self.add(entry_container) + self.entry_box = Gtk.Entry() + entry_container.pack_start(self.entry_box, True, True, 0) + play_button = Gtk.Button(label="Start") + play_button.connect("clicked", self.on_play) + entry_container.pack_start(play_button, True, True, 1) + exit_btn = Gtk.Button(label="Exit") + exit_btn.connect("clicked", self.on_destroy) + entry_container.pack_start(exit_btn, True, True, 2) + # ~ self.add(play_button) + self.add(widget) + self.show_all() + # ~ @self.mpv.on_key_press('q') + # ~ def my_q_binding(): + # ~ print('THERE IS NO ESCAPE') + # ~ self.mpv.terminate() + + + def on_play(self, widget): + # Must be created >after< the widget is shown, else property 'window' will be None + self.mpv = mpv.MPV(wid=str(widget.get_property("window").get_xid()), ytdl=True, input_default_bindings=True, input_vo_keyboard=True, osc=True) + input_media = self.entry_box.get_text() + + self.mpv.play(input_media) + self.mpv.wait_for_playback() + self.mpv.terminate() + + def on_destroy(self, widget, data=None): + #self.mpv.terminate() + Gtk.main_quit() + + +if __name__ == '__main__': + application = MainClass() + Gtk.main()