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..f87ba54 --- /dev/null +++ b/src/python/python_fmpi/src/config/commands.py @@ -0,0 +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 new file mode 100644 index 0000000..75210fd --- /dev/null +++ b/src/python/python_fmpi/src/config/stream_list.py @@ -0,0 +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/__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..20569b0 --- /dev/null +++ b/src/python/python_fmpi/src/web_streams/web_stream_player.py @@ -0,0 +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 new file mode 100644 index 0000000..5b4f8af --- /dev/null +++ b/src/python/python_fmpi/test/config/test_commands.py @@ -0,0 +1,21 @@ +__author__ = 'dev' + +import unittest +import subprocess +from config.commands import web_stream_commands as wcmd + + +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__': + 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..d8c1235 --- /dev/null +++ b/src/python/python_fmpi/test/config/test_stream_list.py @@ -0,0 +1,25 @@ +__author__ = 'dev' + +import unittest +import urllib.request +import urllib.error +from config.stream_list import web_stream_list as wsl + + +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__': + 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..383c262 --- /dev/null +++ b/src/python/python_fmpi/test/web_streams/test_web_stream_player.py @@ -0,0 +1,33 @@ +__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) + + 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()