Esempio n. 1
0
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)
Esempio n. 2
0
    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)
 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)
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)
Esempio n. 5
0
    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 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'],
     })
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.handler = Handler(self.kodi)

    def test_search_and_display(self):
        self.handler.handler({
            "type": "command",
            "commandType": "searchAndDisplay",
            "filter": {
                'actors': ['Jason Statham'],
            }
        })
        run_one()
Esempio n. 8
0
    def setUp(self):
        library_cache = LibraryCache()
        self.kodi = KodiInterface(library_cache)
        self.handler = Handler(self.kodi)

        self.handler.handler({
            "type": "command",
            "commandType": "setVolume",
            "volume": 50,
        })
        run_one()

        self.handler.handler({
            "type": "command",
            "commandType": "setMute",
            "volume": False,
        })
        run_one()
class TestSearchAndDisplay(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.handler = Handler(self.kodi)

    def test_search_and_display(self):
        self.handler.handler({
            "type": "command",
            "commandType": "searchAndDisplay",
            "filter": {
                'actors': ['Jason Statham'],
            }
        })
        run_one()
Esempio n. 10
0
class TestHandler(unittest.TestCase):
    def setUp(self):
        library_cache = LibraryCache()
        self.kodi = KodiInterface(library_cache)
        self.handler = Handler(self.kodi)

    def test_unknown_type(self):
        response = self.handler.handler({
            "type": "unknownType",
        })

        self.assertEqual(response['status'], 'error')
        self.assertEqual(response['error'], 'unknown_command')

    def test_unknown_command_type(self):
        response = self.handler.handler({
            "type": "command",
            "commandType": "unknownCommandType",
        })

        self.assertEqual(response['status'], 'error')
        self.assertEqual(response['error'], 'unknown_command')
Esempio n. 11
0
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')
Esempio n. 12
0
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')
Esempio n. 13
0
class TestVolume(unittest.TestCase):
    def setUp(self):
        library_cache = LibraryCache()
        self.kodi = KodiInterface(library_cache)
        self.handler = Handler(self.kodi)

        self.handler.handler({
            "type": "command",
            "commandType": "setVolume",
            "volume": 50,
        })
        run_one()

        self.handler.handler({
            "type": "command",
            "commandType": "setMute",
            "volume": False,
        })
        run_one()

    def _test_set_volume(self, volume):
        self.handler.handler({
            "type": "command",
            "commandType": "setVolume",
            "volume": volume,
        })
        run_one()

        kodi_volume = kodi_rpc.get_volume()
        self.assertEqual(kodi_volume, volume)

    def _test_adjust_volume(self, volume, expected_volume):
        self.handler.handler({
            "type": "command",
            "commandType": "adjustVolume",
            "volume": volume,
        })
        run_one()

        kodi_volume = kodi_rpc.get_volume()
        self.assertEqual(kodi_volume, expected_volume)

    def _test_set_mute(self, mute):
        self.handler.handler({
            "type": "command",
            "commandType": "setMute",
            "mute": mute,
        })
        run_one()

        kodi_muted = kodi_rpc.get_muted()
        self.assertEqual(kodi_muted, mute)

    def test_set_volume(self):
        self._test_set_volume(50)
        self._test_set_volume(0)
        self._test_set_volume(100)
        self._test_set_volume(25)

    def test_adjust_volume(self):
        self._test_adjust_volume(20, 70)
        self._test_adjust_volume(100, 100)
        self._test_adjust_volume(10, 100)
        self._test_adjust_volume(-45, 55)
        self._test_adjust_volume(-70, 0)
        self._test_adjust_volume(-20, 0)

    def test_set_mute(self):
        self._test_set_mute(True)
        self._test_set_mute(False)
        self._test_set_mute(False)
        self._test_set_mute(True)
        self._test_set_mute(True)
    def setUp(self):
        self.kodi = KodiInterface(self.library_cache)
        self.kodi.library_index = self.library_index

        self.handler = Handler(self.kodi)
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)
Esempio n. 17
0
 def setUp(self):
     library_cache = LibraryCache()
     self.kodi = KodiInterface(library_cache)
     self.handler = Handler(self.kodi)