def test_repr_003_01(self): """ Test '__repr__' and '__str__' methods of 'Frontend' class. """ db = MythDB() fe = Frontend("%s" % (self.testenv['FRONTENDIP']), 6546) print() print(repr(fe)) print(str(fe)) # print list of keys and jump values print() print(repr(fe.key)) print(str(fe.key)) print() print(repr(fe.jump)) print(str(fe.jump))
except socket.timeout: print "Could not connect to "+sys.argv[1] pass except TypeError: print sys.argv[1]+" does not exist" pass except KeyboardInterrupt: sys.exit() except: raise else: print "Please choose from the following available frontends:" frontends = None while frontend is None: if frontends is None: frontends = list(Frontend.fromUPNP()) if len(frontends) == 0: print "No frontends detected" sys.exit() for i,f in enumerate(frontends): print "%d. %s" % (i+1, f) try: i = int(raw_input('> '))-1 frontend = frontends[i] wrapper(main) except KeyboardInterrupt: sys.exit() except EOFError: sys.exit() except IndexError: print "This input requires a value between 1 and %d" % len(frontends)
def setUp(self): with add_log_flags(): # connect to frontend and prepare a recording to play self.fe = Frontend("%s" % (self.testenv['FRONTENDIP']), 6546) self.p = "%s %s" % (self.testenv['RECCHANID'], self.testenv['RECSTARTTIMEUTC'].strip('Z'))
class test_Methodheap_BEEventMonitor_001(unittest.TestCase): """Test methods from MythTV.BEEventMonitor(). """ @classmethod def setUpClass(cls): # get the global test environment global TestEnv cls.testenv = TestEnv def setUp(self): with add_log_flags(): # connect to frontend and prepare a recording to play self.fe = Frontend("%s" % (self.testenv['FRONTENDIP']), 6546) self.p = "%s %s" % (self.testenv['RECCHANID'], self.testenv['RECSTARTTIMEUTC'].strip('Z')) def tearDown(self): # close frontend self.fe.close() @classmethod def tearDownClass(cls): # clear test environment global TestEnv TestEnv.clear() # remove temorary files if os.path.exists('/tmp/my_logfile'): os.remove('/tmp/my_logfile') def test_test_Methodheap_BEEventMonitor_001_01(self): """Test 'BEEventMonitor' from MythTV.BEEventMonitor() with logging. Start the BEEventMonitor and watch the logs for events. """ self.a = 0 bemon = BEEventMonitor(systemevents=True) time.sleep(1) # start generating some log messages: # Jump to 'TV Recording Playback', loc = self.fe.sendQuery('location') if (loc != 'playbackbox'): self.fe.jump['playbackrecordings'] time.sleep(1) # Select recordings k1 = self.fe.key['enter'] self.assertTrue(k1) time.sleep(1) # Play program with chanid & starttime # play program CHANID yyyy-MM-ddThh:mm:ss k2 = self.fe.sendPlay('program %s' % self.p) self.assertTrue(k2) time.sleep(15) # stop playback of recording k3 = self.fe.key.escape self.assertTrue(k3) time.sleep(1) a = tailandgrep( '/tmp/my_logfile', 50, 'BACKEND_MESSAGE\[\]:\[\]SYSTEM_EVENT PLAY_STOPPED HOSTNAME') self.assertTrue((len(a) > 0))
def setUp(self): # connect to frontend self.fe = Frontend("%s" % (self.testenv['FRONTENDIP']), 6546)
class test_Methodheap_Frontend_001(unittest.TestCase): """Test methods from MythTV.Frontend(). See https://www.mythtv.org/wiki/Frontend_control_socket """ @classmethod def setUpClass(cls): # get the global test environment global TestEnv cls.testenv = TestEnv def setUp(self): # connect to frontend self.fe = Frontend("%s" % (self.testenv['FRONTENDIP']), 6546) def tearDown(self): # close frontend self.fe.close() @classmethod def tearDownClass(cls): if os.path.exists('/tmp/screenshot'): os.remove('/tmp/screenshot') if os.path.exists('/tmp/my_logfile'): os.remove('/tmp/my_logfile') def test_Methodheap_Frontend_001_query_play_01(self): """Test 'sendQuery', 'sendPlay' and 'jump' methods from MythTV.Frontend() """ # jump to MythVideo j1 = self.fe.jump.mythvideo self.assertTrue(j1) time.sleep(5) # Jump to 'TV Recording Playback', loc = self.fe.sendQuery('location') if (loc != 'playbackbox'): self.fe.jump['playbackrecordings'] time.sleep(10) # Select recordings k1 = self.fe.key['enter'] self.assertTrue(k1) time.sleep(1) # play first recording k2 = self.fe.key['enter'] self.assertTrue(k2) time.sleep(10) # stop playback of recording self.fe.sendPlay('stop') time.sleep(2) loc = self.fe.sendQuery('location') self.assertTrue(loc == 'playbackbox') # Clear bookmark caused by 'stop' k3 = self.fe.key.enter self.assertTrue(k3) time.sleep(10) k4 = self.fe.key.escape self.assertTrue(k4) def test_Methodheap_Frontend_001_getQuery_01(self): """Test 'getQuery'' methods from MythTV.Frontend(). """ q = self.fe.getQuery() # 'q' reports a list of tuples self.assertTrue('recordings' in [key for (key, desc) in q]) def test_Methodheap_Frontend_001_getPlay_01(self): """Test 'getPlay'' methods from MythTV.Frontend(). """ q = self.fe.getPlay() # 'q' reports a list of tuples self.assertTrue('seek beginning' in [key for (key, desc) in q]) def test_Methodheap_Frontend_001_getLoad_01(self): """Test 'getLoad' methods from MythTV.Frontend(). """ q = self.fe.getLoad() self.assertTrue(isinstance(q, tuple)) self.assertTrue(isinstance(q[0], float)) def test_Methodheap_Frontend_001_getUptime_01(self): """Test 'getUptime' methods from MythTV.Frontend(). """ q = self.fe.getUptime() self.assertTrue(isinstance(q, timedelta)) def test_Methodheap_Frontend_001_getTime_01(self): """Test 'getTime' methods from MythTV.Frontend(). """ q = self.fe.getTime() self.assertTrue(isinstance(q, MythTV.utility.dt.datetime)) def test_Methodheap_Frontend_001_getMemory_01(self): """Test 'getTime' methods from MythTV.Frontend(). """ q = self.fe.getMemory() # print(type(q['totalmem'])) --> 'future.types.newint.newint' self.assertTrue(isinstance(q, dict)) def test_Methodheap_Frontend_001_getScreenShot_01(self): """Test 'getScreenShot' methods from MythTV.Frontend(). """ screenshot = self.fe.getScreenShot() #print(type(screenshot)) with open('/tmp/screenshot', 'wb') as f: f.write(screenshot) os.system('file /tmp/screenshot > /tmp/my_logfile') a = (len(tailandgrep('/tmp/my_logfile', 2, 'JPEG|PNG')) > 0) self.assertTrue(a)
def init_tivo(self): """Initialize the MythTV Frontend connection""" self.frontend = Frontend('localhost', '6546')
class DemoApp(object): """GStreamer/PocketSphinx Demo Application""" def __init__(self): """Initialize a DemoApp object""" self.init_gst() self.init_tivo() def init_gst(self): """Initialize the speech components""" self.pipeline = gst.Pipeline('player') source = gst.element_factory_make('pulsesrc') convert = gst.element_factory_make('audioconvert') resample = gst.element_factory_make('audioresample') vader = gst.element_factory_make('vader') vader.set_property('name', 'vad') vader.set_property('auto-threshold', 'true') sphinx = gst.element_factory_make('pocketsphinx') sphinx.set_property('name', 'asr') sink = gst.element_factory_make('fakesink') self.pipeline.add(source, convert, resample, vader, sphinx, sink) gst.element_link_many(source, convert, resample, vader, sphinx, sink) asr = self.pipeline.get_by_name('asr') asr.connect('partial_result', self.asr_partial_result) asr.connect('result', self.asr_result) asr.set_property('configured', True) asr.set_property('lm', 'language_model.lm') asr.set_property('dict', 'dictionary.dic') bus = self.pipeline.get_bus() bus.add_signal_watch() bus.connect('message::application', self.application_message) self.pipeline.set_state(gst.STATE_PLAYING) def init_tivo(self): """Initialize the MythTV Frontend connection""" self.frontend = Frontend('localhost', '6546') def asr_partial_result(self, asr, text, uttid): """Forward partial result signals on the bus to the main thread.""" struct = gst.Structure('partial_result') struct.set_value('hyp', text) struct.set_value('uttid', uttid) asr.post_message(gst.message_new_application(asr, struct)) def asr_result(self, asr, text, uttid): """Forward result signals on the bus to the main thread.""" struct = gst.Structure('result') struct.set_value('hyp', text) struct.set_value('uttid', uttid) asr.post_message(gst.message_new_application(asr, struct)) def application_message(self, bus, msg): """Receive application messages from the bus.""" msgtype = msg.structure.get_name() if msgtype == 'result': res = msg.structure['hyp'] if res: print res self.dispatch_command(res) def dispatch_command(self, command): play_commands = { "TIVO PLAY": "speed normal", "TIVO PAUSE": "speed pause", "TIVO SKIP": "seek forward", "TIVO SKIP FORWARD": "seek forward", "TIVO SKIP BACK": "seek backward", } key_commands = { "TIVO STOP": "escape", "TIVO ESCAPE": "escape", "TIVO PAGE UP": "pageup", "TIVO PAGE DOWN": "pagedown", "TIVO UP": "up", "TIVO DOWN": "down", "TIVO ALTO": "up", "TIVO BAHO": "down", "TIVO LEFT": "left", "TIVO RIGHT": "right", "TIVO ENTER": "enter", "TIVO SELECT": "enter", "TIVO OK": "enter", } jump_commands = { "TIVO STOP": "playbackbox", } if command in play_commands.keys(): print "** received %s, sending 'play %s'" % (command, play_commands[command]) self.frontend.sendPlay(play_commands[command]) elif command in key_commands.keys(): print "** received %s, sending 'key %s'" % (command, key_commands[command]) try: self.frontend.sendKey(key_commands[command]) except AttributeError: self.frontend.key[key_commands[command]] elif command in jump_commands.keys(): print "** received %s, sending 'jump %s'" % (command, jump_commands[command]) try: self.frontend.sendJump(jump_commands[command]) except AttributeError: self.frontend.jump[jump_commands[command]] elif command == "TIVO PLAY DAILY SHOW": print "PLAYing latest daily show" daily_shows = [x for x in self.frontend.sendQuery('recordings').split('\r\n') if x.find('Daily Show') >= 0] latest_ds = sorted(daily_shows)[-1].split() self.frontend.sendPlay('program %s %s' % (latest_ds[0], latest_ds[1])) elif command == "TIVO PLAY COLBERT": print "PLAYing latest colbert" daily_shows = [x for x in self.frontend.sendQuery('recordings').split('\r\n') if x.find('Colbert Report') >= 0] latest_ds = sorted(daily_shows)[-1].split() self.frontend.sendPlay('program %s %s' % (latest_ds[0], latest_ds[1]))