示例#1
0
def root(params):
    items = []

    region = TVCatchup.lookup_region(plugin.get_setting("region"))
    user_agent = plugin.get_setting("useragent")
    api = TVCatchup(region, user_agent)

    for channel in api.channels():
        items.append({
            "label":
            channel["name"] + (" [COLOR red][B](Off-air)[/B][/COLOR]"
                               if channel["online"] != 1 else ""),
            "label2":
            channel["epg"]["programme_title"],
            "url":
            plugin.get_url(action="play",
                           id=channel["id"],
                           name=channel["name"],
                           logo=channel["logo"],
                           slug=channel["slug"],
                           plot=channel["epg"]["programme_desc"],
                           title=channel["epg"]["programme_title"]),
            "thumb":
            channel["logo"] +
            "|User-Agent={0}".format(urllib.quote(user_agent)),
            "is_playable":
            True,
            "info": {
                "Video": {
                    "Plot": channel["epg"]["programme_desc"],
                }
            }
        })

    return Plugin.create_listing(items, sort_methods=(0, ), content="movies")
示例#2
0
def by_genre(params):
    xbmcplugin.setContent(int(sys.argv[1]), 'files')

    #vsdbg._bp()

    listing = [
        genre_item(genre) for genre in shikicore.genres()
        if genre['kind'] == 'anime'
    ]
    return Plugin.create_listing(
        listing,
        sort_methods=(xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE,
                      xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE))
    def test_run(self):
        plugin = Plugin('test.plugin')
        plugin.create_listing = mock.MagicMock()
        plugin.resolve_url = mock.MagicMock()
        plugin._add_directory_items = mock.MagicMock()
        plugin._set_resolved_url = mock.MagicMock()
        mock_actions = mock.MagicMock()
        # Test calling 'root' action
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '']):
            mock_actions.root.return_value = [{'label': 'root'}]
            plugin.actions['root'] = mock_actions.root
            plugin.run(category='Foo')
            mock_actions.root.assert_called_with({})
            plugin.create_listing.assert_called_with([{'label': 'root'}])
            # Test setting plugin category
            mock_xbmcplugin.setPluginCategory.assert_called_with(1, 'Foo')
        # Test calling a child action returning list or generator
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=foo&param=bar']):
            plugin.create_listing.reset_mock()
            mock_actions.foo.return_value = [{'label': 'foo'}]
            plugin.actions['foo'] = mock_actions.foo
            plugin.run()
            mock_actions.foo.assert_called_with({'action': 'foo', 'param': 'bar'})
            plugin.create_listing.assert_called_with([{'label': 'foo'}])
            plugin.create_listing.reset_mock()
            generator = test_generator()
            mock_actions.foo.return_value = generator
            plugin.run()
            mock_actions.foo.assert_called_with({'action': 'foo', 'param': 'bar'})
            plugin.create_listing.assert_called_with(generator)
        # Test calling a child action returning a str
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=play_str']):
            mock_actions.play_str.return_value = '/play/path'
            plugin.actions['play_str'] = mock_actions.play_str
            plugin.run()
            plugin.resolve_url.assert_called_with('/play/path')
        # Test calling a child action returning ListContext namedtuple
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=tuple_listing']):
            plugin._add_directory_items.reset_mock()
            list_context = ListContext(
                [{
                    'url': 'plugin://foo',
                    'label': 'Foo',
                    'is_folder': True
                }],
                True,
                True,
                True,
                (0,),
                50,
                'movies'
            )

            mock_actions.dict_listing.return_value = list_context
            plugin.actions['tuple_listing'] = mock_actions.dict_listing
            plugin.run()
            plugin._add_directory_items.assert_called_with(list_context)
        # Test calling a child action returning PlayContext namedtuple
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=tuple_play']):
            plugin._set_resolved_url.reset_mock()
            play_context = PlayContext('http://foo.bar', None, True)
            mock_actions.dict_play.return_value = play_context
            plugin.actions['tuple_play'] = mock_actions.dict_play
            plugin.run()
            plugin._set_resolved_url.assert_called_with(play_context)
        # Test unregistered action
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=invalid']):
            self.assertRaises(SimplePluginError, plugin.run)
示例#4
0
    def test_run(self):
        plugin = Plugin('test.plugin')
        plugin.create_listing = mock.MagicMock()
        plugin.resolve_url = mock.MagicMock()
        plugin._add_directory_items = mock.MagicMock()
        plugin._set_resolved_url = mock.MagicMock()
        mock_actions = mock.MagicMock()
        # Test calling 'root' action
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '']):
            mock_actions.root.return_value = [{'label': 'root'}]
            plugin.actions['root'] = mock_actions.root
            plugin.run(category='Foo')
            mock_actions.root.assert_called_with({})
            plugin.create_listing.assert_called_with([{'label': 'root'}])
            # Test setting plugin category
            mock_xbmcplugin.setPluginCategory.assert_called_with(1, 'Foo')
        # Test calling a child action returning list or generator
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=foo&param=bar']):
            plugin.create_listing.reset_mock()
            mock_actions.foo.return_value = [{'label': 'foo'}]
            plugin.actions['foo'] = mock_actions.foo
            plugin.run()
            mock_actions.foo.assert_called_with({
                'action': 'foo',
                'param': 'bar'
            })
            plugin.create_listing.assert_called_with([{'label': 'foo'}])
            plugin.create_listing.reset_mock()
            generator = test_generator()
            mock_actions.foo.return_value = generator
            plugin.run()
            mock_actions.foo.assert_called_with({
                'action': 'foo',
                'param': 'bar'
            })
            plugin.create_listing.assert_called_with(generator)
        # Test calling a child action returning a str
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=play_str']):
            mock_actions.play_str.return_value = '/play/path'
            plugin.actions['play_str'] = mock_actions.play_str
            plugin.run()
            plugin.resolve_url.assert_called_with('/play/path')
        # Test calling a child action returning ListContext namedtuple
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=tuple_listing']):
            plugin._add_directory_items.reset_mock()
            list_context = ListContext([{
                'url': 'plugin://foo',
                'label': 'Foo',
                'is_folder': True
            }], True, True, True, (0, ), 50, 'movies')

            mock_actions.dict_listing.return_value = list_context
            plugin.actions['tuple_listing'] = mock_actions.dict_listing
            plugin.run()
            plugin._add_directory_items.assert_called_with(list_context)
        # Test calling a child action returning PlayContext namedtuple
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=tuple_play']):
            plugin._set_resolved_url.reset_mock()
            play_context = PlayContext('http://foo.bar', None, True)
            mock_actions.dict_play.return_value = play_context
            plugin.actions['tuple_play'] = mock_actions.dict_play
            plugin.run()
            plugin._set_resolved_url.assert_called_with(play_context)
        # Test unregistered action
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=invalid']):
            self.assertRaises(SimplePluginError, plugin.run)