From 53741bb363b54362dd3d1dc0b8f9424aa9b6e0d5 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 8 Oct 2014 00:27:10 +0200 Subject: [PATCH 1/2] add web stream player --- src/python/python_fmpi/src/config/__init__.py | 1 + src/python/python_fmpi/src/config/commands.py | 1 + .../python_fmpi/src/config/stream_list.py | 5 +++ .../python_fmpi/src/web_streams/__init__.py | 1 + .../src/web_streams/web_stream_player.py | 1 + .../python_fmpi/test/config/test_commands.py | 12 +++++++ .../test/config/test_stream_list.py | 12 +++++++ .../web_streams/test_web_stream_player.py | 34 +++++++++++++++++++ 8 files changed, 67 insertions(+) create mode 100644 src/python/python_fmpi/src/config/__init__.py create mode 100644 src/python/python_fmpi/src/config/commands.py create mode 100644 src/python/python_fmpi/src/config/stream_list.py create mode 100644 src/python/python_fmpi/src/web_streams/__init__.py create mode 100644 src/python/python_fmpi/src/web_streams/web_stream_player.py create mode 100644 src/python/python_fmpi/test/config/test_commands.py create mode 100644 src/python/python_fmpi/test/config/test_stream_list.py create mode 100644 src/python/python_fmpi/test/web_streams/test_web_stream_player.py diff --git a/src/python/python_fmpi/src/config/__init__.py b/src/python/python_fmpi/src/config/__init__.py new file mode 100644 index 0000000..f8bf4e8 --- /dev/null +++ b/src/python/python_fmpi/src/config/__init__.py @@ -0,0 +1 @@ +__author__ = 'dev' diff --git a/src/python/python_fmpi/src/config/commands.py b/src/python/python_fmpi/src/config/commands.py new file mode 100644 index 0000000..f8bf4e8 --- /dev/null +++ b/src/python/python_fmpi/src/config/commands.py @@ -0,0 +1 @@ +__author__ = 'dev' diff --git a/src/python/python_fmpi/src/config/stream_list.py b/src/python/python_fmpi/src/config/stream_list.py new file mode 100644 index 0000000..9e47bd8 --- /dev/null +++ b/src/python/python_fmpi/src/config/stream_list.py @@ -0,0 +1,5 @@ +__author__ = 'dev' + += { + +} \ No newline at end of file diff --git a/src/python/python_fmpi/src/web_streams/__init__.py b/src/python/python_fmpi/src/web_streams/__init__.py new file mode 100644 index 0000000..f8bf4e8 --- /dev/null +++ b/src/python/python_fmpi/src/web_streams/__init__.py @@ -0,0 +1 @@ +__author__ = 'dev' diff --git a/src/python/python_fmpi/src/web_streams/web_stream_player.py b/src/python/python_fmpi/src/web_streams/web_stream_player.py new file mode 100644 index 0000000..f8bf4e8 --- /dev/null +++ b/src/python/python_fmpi/src/web_streams/web_stream_player.py @@ -0,0 +1 @@ +__author__ = 'dev' diff --git a/src/python/python_fmpi/test/config/test_commands.py b/src/python/python_fmpi/test/config/test_commands.py new file mode 100644 index 0000000..ee73c95 --- /dev/null +++ b/src/python/python_fmpi/test/config/test_commands.py @@ -0,0 +1,12 @@ +__author__ = 'dev' + +import unittest + + +class MyTestCase(unittest.TestCase): + def test_something(self): + self.assertEqual(True, False) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/python/python_fmpi/test/config/test_stream_list.py b/src/python/python_fmpi/test/config/test_stream_list.py new file mode 100644 index 0000000..ee73c95 --- /dev/null +++ b/src/python/python_fmpi/test/config/test_stream_list.py @@ -0,0 +1,12 @@ +__author__ = 'dev' + +import unittest + + +class MyTestCase(unittest.TestCase): + def test_something(self): + self.assertEqual(True, False) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/python/python_fmpi/test/web_streams/test_web_stream_player.py b/src/python/python_fmpi/test/web_streams/test_web_stream_player.py new file mode 100644 index 0000000..8f81ab1 --- /dev/null +++ b/src/python/python_fmpi/test/web_streams/test_web_stream_player.py @@ -0,0 +1,34 @@ +__author__ = 'dev' + +import unittest +from web_streams.web_stream_player import WebStreamPlayer + + +class TestWebStreamPlayer(unittest.TestCase): + + def setUp(self): + self.__player = WebStreamPlayer() + self.__stream_name = "skaworld" + self.__wrong_stream_name = "skawrld" + + def tearDown(self): + self.__player.stop_stream() + + def test_play_stream(self): + self.__player.play_stream(self.__stream_name) + self.assertEqual(self.__player.get_current_stream_name(), self.__stream_name) + + def test_play_stream_error_wrong_stream_name(self): + self.__player.play_stream(self.__wrong_stream_name) + self.assertEqual(self.__player.get_current_stream_name(), None) + self.assertTrue(True) + + def test_stop_stream(self): + self.__player.play_stream(self.__stream_name) + self.assertEqual(self.__player.get_current_stream_name(), self.__stream_name) + self.__player.stop_stream() + self.assertEqual(self.__player.get_current_stream_name(), None) + + +if __name__ == '__main__': + unittest.main() From 3fdbef42450759a9bf75464fa3397c0075a3a4d6 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 8 Oct 2014 00:27:43 +0200 Subject: [PATCH 2/2] add wem stream player --- src/python/python_fmpi/src/config/commands.py | 3 +++ .../python_fmpi/src/config/stream_list.py | 5 ++-- .../src/web_streams/web_stream_player.py | 26 +++++++++++++++++++ .../python_fmpi/test/config/test_commands.py | 15 ++++++++--- .../test/config/test_stream_list.py | 19 +++++++++++--- .../web_streams/test_web_stream_player.py | 1 - 6 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/python/python_fmpi/src/config/commands.py b/src/python/python_fmpi/src/config/commands.py index f8bf4e8..f87ba54 100644 --- a/src/python/python_fmpi/src/config/commands.py +++ b/src/python/python_fmpi/src/config/commands.py @@ -1 +1,4 @@ __author__ = 'dev' + + +web_stream_commands = {"web_stream_player_command": "mplayer"} \ No newline at end of file diff --git a/src/python/python_fmpi/src/config/stream_list.py b/src/python/python_fmpi/src/config/stream_list.py index 9e47bd8..75210fd 100644 --- a/src/python/python_fmpi/src/config/stream_list.py +++ b/src/python/python_fmpi/src/config/stream_list.py @@ -1,5 +1,6 @@ __author__ = 'dev' -= { - +web_stream_list= { + "skaworld": "http://stream.laut.fm/skaworld", + "skafari ": "http://stream.laut.fm/skafari" } \ No newline at end of file diff --git a/src/python/python_fmpi/src/web_streams/web_stream_player.py b/src/python/python_fmpi/src/web_streams/web_stream_player.py index f8bf4e8..20569b0 100644 --- a/src/python/python_fmpi/src/web_streams/web_stream_player.py +++ b/src/python/python_fmpi/src/web_streams/web_stream_player.py @@ -1 +1,27 @@ __author__ = 'dev' + +from config.stream_list import web_stream_list as wsl +from config.commands import web_stream_commands as wcmd +from utility.subprocess_dict import SubprocessDict + + +class WebStreamPlayer: + + def __init__(self, player_command=wcmd["web_stream_player_command"], stream_list=wsl): + self.__player_command = player_command + self.__stream_list = stream_list + self.__process_list = SubprocessDict() + self.__current_stream_name = None + + def get_current_stream_name(self): + return self.__current_stream_name + + def play_stream(self, stream_name): + if stream_name in self.__stream_list: + self.__process_list.clear_dict() + self.__process_list.add_process([self.__player_command, self.__stream_list[stream_name]]) + self.__current_stream_name = stream_name + + def stop_stream(self): + self.__process_list.clear_dict() + self.__current_stream_name = None \ No newline at end of file diff --git a/src/python/python_fmpi/test/config/test_commands.py b/src/python/python_fmpi/test/config/test_commands.py index ee73c95..5b4f8af 100644 --- a/src/python/python_fmpi/test/config/test_commands.py +++ b/src/python/python_fmpi/test/config/test_commands.py @@ -1,11 +1,20 @@ __author__ = 'dev' import unittest +import subprocess +from config.commands import web_stream_commands as wcmd -class MyTestCase(unittest.TestCase): - def test_something(self): - self.assertEqual(True, False) +class TestCommands(unittest.TestCase): + + def setUp(self): + self.__wspc =wcmd["web_stream_player_command"] + + def test_web_stream_commands(self): + self.assertEqual(0, subprocess.call(self.__wspc)) + + def test_web_stream_commands_error_wrong_commands(self): + self.assertRaises(FileNotFoundError, subprocess.call,self.__wspc + "fail") if __name__ == '__main__': diff --git a/src/python/python_fmpi/test/config/test_stream_list.py b/src/python/python_fmpi/test/config/test_stream_list.py index ee73c95..d8c1235 100644 --- a/src/python/python_fmpi/test/config/test_stream_list.py +++ b/src/python/python_fmpi/test/config/test_stream_list.py @@ -1,11 +1,24 @@ __author__ = 'dev' import unittest +import urllib.request +import urllib.error +from config.stream_list import web_stream_list as wsl -class MyTestCase(unittest.TestCase): - def test_something(self): - self.assertEqual(True, False) +class TestStreamList(unittest.TestCase): + + def setUp(self): + self.__stream_url = wsl.values() + + def test_stream_available(self): + for url in self.__stream_url: + response = urllib.request.urlopen(url) + self.assertEqual(200, response.getcode()) + + def test_stream_wrong_url(self): + self.__stream_url = "http://wrong.stream" + self.assertRaises(urllib.error.URLError, urllib.request.urlopen, self.__stream_url) if __name__ == '__main__': diff --git a/src/python/python_fmpi/test/web_streams/test_web_stream_player.py b/src/python/python_fmpi/test/web_streams/test_web_stream_player.py index 8f81ab1..383c262 100644 --- a/src/python/python_fmpi/test/web_streams/test_web_stream_player.py +++ b/src/python/python_fmpi/test/web_streams/test_web_stream_player.py @@ -21,7 +21,6 @@ class TestWebStreamPlayer(unittest.TestCase): def test_play_stream_error_wrong_stream_name(self): self.__player.play_stream(self.__wrong_stream_name) self.assertEqual(self.__player.get_current_stream_name(), None) - self.assertTrue(True) def test_stop_stream(self): self.__player.play_stream(self.__stream_name)