Finish streamlist
This commit is contained in:
1
src/python/python_fmpi/src/config/__init__.py
Normal file
1
src/python/python_fmpi/src/config/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'dev'
|
||||
4
src/python/python_fmpi/src/config/commands.py
Normal file
4
src/python/python_fmpi/src/config/commands.py
Normal file
@@ -0,0 +1,4 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
|
||||
web_stream_commands = {"web_stream_player_command": "mplayer"}
|
||||
6
src/python/python_fmpi/src/config/stream_list.py
Normal file
6
src/python/python_fmpi/src/config/stream_list.py
Normal file
@@ -0,0 +1,6 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
web_stream_list= {
|
||||
"skaworld": "http://stream.laut.fm/skaworld",
|
||||
"skafari ": "http://stream.laut.fm/skafari"
|
||||
}
|
||||
1
src/python/python_fmpi/src/web_streams/__init__.py
Normal file
1
src/python/python_fmpi/src/web_streams/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'dev'
|
||||
27
src/python/python_fmpi/src/web_streams/web_stream_player.py
Normal file
27
src/python/python_fmpi/src/web_streams/web_stream_player.py
Normal file
@@ -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
|
||||
21
src/python/python_fmpi/test/config/test_commands.py
Normal file
21
src/python/python_fmpi/test/config/test_commands.py
Normal file
@@ -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()
|
||||
25
src/python/python_fmpi/test/config/test_stream_list.py
Normal file
25
src/python/python_fmpi/test/config/test_stream_list.py
Normal file
@@ -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()
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user