add wem stream player
This commit is contained in:
@@ -1 +1,4 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
|
||||
web_stream_commands = {"web_stream_player_command": "mplayer"}
|
||||
@@ -1,5 +1,6 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
= {
|
||||
|
||||
web_stream_list= {
|
||||
"skaworld": "http://stream.laut.fm/skaworld",
|
||||
"skafari ": "http://stream.laut.fm/skafari"
|
||||
}
|
||||
@@ -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
|
||||
@@ -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__':
|
||||
|
||||
@@ -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__':
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user