class TestPlaybackControl(unittest.TestCase): @classmethod def setUpClass(cls): cls.library_cache, cls.library_index = get_library_cache_and_index() def setUp(self): self.kodi = KodiInterface(self.library_cache) self.kodi.library_index = self.library_index self.player = CustomPlayer() self.player.set_kodi(self.kodi) self.handler = Handler(self.kodi) self.kodi.find_and_play({ 'titles': ['Maze Runner'], }) def test_pause(self): self.handler.handler({ "type": "command", "commandType": "pause", }) run_one() self.assertEqual(self.player.speed, 0) def test_resume(self): self.handler.handler({ "type": "command", "commandType": "pause", }) run_one() self.assertEqual(self.player.speed, 0) self.handler.handler({ "type": "command", "commandType": "resume", }) run_one() self.assertEqual(self.player.speed, 1) def test_stop(self): self.handler.handler({ "type": "command", "commandType": "stop", }) run_one() self.assertEqual(self.player.speed, 0) self.assertIsNone(self.player.current_item) self.handler.handler({ "type": "command", "commandType": "resume", }) run_one() self.assertEqual(self.player.speed, 0) self.assertIsNone(self.player.current_item)
class TestPlaybackControl(unittest.TestCase): def setUp(self): library_cache = LibraryCache() self.kodi = KodiInterface(library_cache) self.kodi.update_cache() wait_for_library_index(self.kodi) self.player = CustomPlayer() self.player.set_kodi(self.kodi) self.handler = Handler(self.kodi) self.kodi.find_and_play({ 'titles': ['Maze Runner'], }) def test_pause(self): self.handler.handler({ "type": "command", "commandType": "pause", }) run_one() self.assertEqual(self.player.speed, 0) def test_resume(self): self.handler.handler({ "type": "command", "commandType": "pause", }) run_one() self.assertEqual(self.player.speed, 0) self.handler.handler({ "type": "command", "commandType": "resume", }) run_one() self.assertEqual(self.player.speed, 1) def test_stop(self): self.handler.handler({ "type": "command", "commandType": "stop", }) run_one() self.assertEqual(self.player.speed, 0) self.assertIsNone(self.player.current_item) self.handler.handler({ "type": "command", "commandType": "resume", }) run_one() self.assertEqual(self.player.speed, 0) self.assertIsNone(self.player.current_item)
def main(): """Main function""" logger.debug('Starting') logger.debug(u'pid={}'.format(os.getpid())) try: __once__ = OnlyOnce() logger.debug(str(__once__)) except OnlyOnceException: logger.debug('Tunnel already running, exiting') sys.exit(0) io_loop = IOLoop(make_current=False) library_cache = LibraryCache() kodi = KodiInterface(library_cache) handler = Handler(kodi) monitor = CustomMonitor(kodi) player = CustomPlayer() player.set_io_loop(io_loop) player.set_kodi(kodi) tunnel = Tunnel(io_loop, KODI_CONNECT_URL, kodi, handler) tunnel_thread = TunnelThread(tunnel) tunnel_thread.start() async_tunnel = tunnel.get_async_tunnel() player.set_async_tunnel(async_tunnel) try: while not monitor.abortRequested(): # Sleep/wait for abort for 3 seconds if monitor.waitForAbort(3): # Abort was requested while waiting. We should exit break except KeyboardInterrupt: logger.debug('Interrupted') logger.debug('Stopping __once__') __once__.stop() logger.debug('Stopping Tunnel') tunnel_thread.stop() logger.debug('Joining Tunnel Thread') tunnel_thread.join() logger.debug('Clearing main IOLoop') IOLoop.clear_current() logger.debug('Stopping concurrent ThreadPool') concurrent.futures.thread._python_exit() # pylint: disable=protected-access logger.debug('Exit')
def main(): """Main function""" logger.debug('Starting') logger.debug('pid={}'.format(os.getpid())) try: __once__ = OnlyOnce() logger.debug(str(__once__)) except OnlyOnceException: logger.debug('Tunnel already running, exiting') sys.exit(0) library_cache = LibraryCache() kodi = KodiInterface(library_cache) handler = Handler(kodi) monitor = CustomMonitor(kodi) player = CustomPlayer() player.set_kodi(kodi) client = Client(KODI_CONNECT_URL, kodi, handler) client_thread = ClientThread(client) client_thread.start() try: while not monitor.abortRequested(): # Sleep/wait for abort for 3 seconds if monitor.waitForAbort(3): # Abort was requested while waiting. We should exit break except KeyboardInterrupt: logger.debug('Interrupted') logger.debug('Stopping Tunnel') client_thread.stop() logger.debug('Joining Tunnel Thread') client_thread.join() logger.debug('Exit')
class TestSearchAndPlay(unittest.TestCase): def setUp(self): library_cache = LibraryCache() self.kodi = KodiInterface(library_cache) self.kodi.update_cache() wait_for_library_index(self.kodi) self.player = CustomPlayer() self.player.set_kodi(self.kodi) self.handler = Handler(self.kodi) def test_search_and_play_not_found(self): self.handler.handler({ "type": "command", "commandType": "searchAndPlay", "filter": { 'titles': ['some made up name'], } }) run_one() current_item = self.player._get_current_item() self.assertIsNone(current_item) def test_search_and_play_tvshow(self): self.handler.handler({ "type": "command", "commandType": "searchAndPlay", "filter": { 'titles': ['How I Met Your Mother'], 'season': '2', 'episode': '1', } }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'episode') self.assertEqual(current_item['tvshowid'], 21) self.assertEqual(current_item['id'], 423) self.assertEqual(current_item['season'], 2) self.assertEqual(current_item['episode'], 1) def test_search_and_play_tvshow_next_episode(self): self.handler.handler({ "type": "command", "commandType": "searchAndPlay", "filter": { u'genres': [], u'episode': None, u'roles': [], u'season': None, u'mediaType': None, u'titles': [u'How I Met Your Mother', u'Goodbye How I Met Your Mother', u'How I Met Your Mother: Extras', u'How I Met Your Puppet Mother'], u'actors': [], u'collections': [], } }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'episode') self.assertEqual(current_item['tvshowid'], 21) self.assertEqual(current_item['id'], 487) self.assertEqual(current_item['season'], 4) self.assertEqual(current_item['episode'], 23) def test_search_and_play_movie_by_title(self): self.handler.handler({ "type": "command", "commandType": "searchAndPlay", "filter": { 'titles': ['Maze Runner'], } }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'movie') self.assertEqual(current_item['id'], 161) def test_search_and_play_movie_by_title_and_movie_mediatype(self): self.handler.handler({ "type": "command", "commandType": "searchAndPlay", "filter": { 'titles': ['Maze Runner'], 'mediaType': 'movie', } }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'movie') self.assertEqual(current_item['id'], 161) def test_search_and_play_movie_by_title_and_tvshow_mediatype(self): self.handler.handler({ "type": "command", "commandType": "searchAndPlay", "filter": { 'titles': ['Maze Runner'], 'mediaType': 'tv show', } }) run_one() current_item = self.player._get_current_item() self.assertIsNone(current_item) def test_search_and_play_movie_by_actor(self): self.handler.handler({ "type": "command", "commandType": "searchAndPlay", "filter": { 'actors': ['Jason Statham'], } }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'movie') self.assertIn(current_item['id'], [202, 163, 48]) def test_search_and_play_movie_by_title_and_actor(self): self.handler.handler({ "type": "command", "commandType": "searchAndPlay", "filter": { 'titles': ['Furious'], 'actors': ['Jason Statham'], } }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'movie') self.assertEqual(current_item['id'], 202)
class TestPreviousNext(unittest.TestCase): def setUp(self): library_cache = LibraryCache() self.kodi = KodiInterface(library_cache) self.kodi.update_cache() wait_for_library_index(self.kodi) self.player = CustomPlayer() self.player.set_kodi(self.kodi) self.handler = Handler(self.kodi) def test_no_current_item_previous(self): current_item = self.player._get_current_item() self.assertIsNone(current_item) self.assertFalse(self.kodi.previous_item()) current_item = self.player._get_current_item() self.assertIsNone(current_item) def test_no_previous_item(self): self.kodi.find_and_play({ 'titles': ['How I Met Your Mother'], 'season': '1', 'episode': '1', }) self.handler.handler({ "type": "command", "commandType": "previous", }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'episode') self.assertEqual(current_item['tvshowid'], 21) self.assertEqual(current_item['id'], 401) self.assertEqual(current_item['season'], 1) self.assertEqual(current_item['episode'], 1) def test_no_next_item(self): self.kodi.find_and_play({ 'titles': ['How I Met Your Mother'], 'season': '6', 'episode': '24', }) self.handler.handler({ "type": "command", "commandType": "next", }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'episode') self.assertEqual(current_item['tvshowid'], 21) self.assertEqual(current_item['id'], 536) self.assertEqual(current_item['season'], 6) self.assertEqual(current_item['episode'], 24) def test_previous_item(self): self.kodi.find_and_play({ 'titles': ['How I Met Your Mother'], 'season': '2', 'episode': '2', }) self.handler.handler({ "type": "command", "commandType": "previous", }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'episode') self.assertEqual(current_item['tvshowid'], 21) self.assertEqual(current_item['id'], 423) self.assertEqual(current_item['season'], 2) self.assertEqual(current_item['episode'], 1) def test_previous_item_cross_season(self): self.kodi.find_and_play({ 'titles': ['How I Met Your Mother'], 'season': '2', 'episode': '1', }) self.handler.handler({ "type": "command", "commandType": "previous", }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'episode') self.assertEqual(current_item['tvshowid'], 21) self.assertEqual(current_item['id'], 422) self.assertEqual(current_item['season'], 1) self.assertEqual(current_item['episode'], 22) def test_next_item(self): self.kodi.find_and_play({ 'titles': ['How I Met Your Mother'], 'season': '1', 'episode': '1', }) self.handler.handler({ "type": "command", "commandType": "next", }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'episode') self.assertEqual(current_item['tvshowid'], 21) self.assertEqual(current_item['id'], 402) self.assertEqual(current_item['season'], 1) self.assertEqual(current_item['episode'], 2) def test_next_item_cross_season(self): self.kodi.find_and_play({ 'titles': ['How I Met Your Mother'], 'season': '1', 'episode': '22', }) self.handler.handler({ "type": "command", "commandType": "next", }) run_one() current_item = self.player._get_current_item() self.assertEqual(current_item['type'], 'episode') self.assertEqual(current_item['tvshowid'], 21) self.assertEqual(current_item['id'], 423) self.assertEqual(current_item['season'], 2) self.assertEqual(current_item['episode'], 1)