Accessing Youtube plugin to play youtube Videos
#1
Hi

The addon I am working on provides a category to play Youtube Videos. XBMC itself ships a Youtube Plugin. I was wondering it is possible to pass URL of youtube video from my plugin to external youtube plugin, it then plays video? Also I want user can get back to my original plugin.

Thanks
Reply
#2
Yes, instead of setting your list item's URL to plugin://plugin.video.myplugin, set it to plugin://plugin.video.YouTube?mode=foo&bar=baz
Obviously, those params are examples so you'll have to take a look at the YouTube plugin to see what params you need to pass
Reply
#3
I tried using the exact URL used for youtube plugin but it's getting stuck, not loading the plugin at all. My question was, will it load it seperately?
Reply
#4
You need to use a URL like:
Code:
plugin://plugin.video.youtube/?action=play_video&videoid=<VIDEO-ID>
plugin://plugin.video.youtube/?action=play_video&videoid=oHg5SJYRHA0

On a PLAYABLE (non folder) ListItem, else it won't work.

Show us your code, then we can better help you.
My GitHub. My Add-ons:
Image
Reply
#5
And if I want to open a FOLDER ListItem from another plugin, is it possible ?

I would like to open Discovery Channel within my Addon.

I did extract the URL of Discovery Channel using xbmc.log in plugin.video.discovery_com

But, just like you said, it doesn't work using RunPlugin. No error, xbmc just opens an empty folder.

Here's my code :
xbmc.executebuiltin( 'RunPlugin(plugin://plugin.video.discovery_com/?channelID=Discovery&channelThumb=%2fhome%2fjp%2f.xbmc%2faddons%2fplugin.video.discovery_com%2fresources%2fthumbs%2fdiscovery_channel.png&mode=listShows&type&url=http%3a%2f%2fdsc.discovery.com%2fvideos)' )
Reply
#6
(2014-01-18, 21:46)JohnSea2 Wrote: And if I want to open a FOLDER ListItem from another plugin, is it possible ?

I would like to open Discovery Channel within my Addon.

I did extract the URL of Discovery Channel using xbmc.log in plugin.video.discovery_com

But, just like you said, it doesn't work using RunPlugin. No error, xbmc just opens an empty folder.

Here's my code :
xbmc.executebuiltin( 'RunPlugin(plugin://plugin.video.discovery_com/?channelID=Discovery&channelThumb=%2fhome%2fjp%2f.xbmc%2faddons%2fplugin.video.discovery_com%2fresources%2fthumbs%2fdiscovery_channel.png&mode=listShows&type&url=http%3a%2f%2fdsc.discovery.com%2fvideos)' )

This is also possible, just add a ListItem with a url pointing to a different plugins URL.

In your case:
PHP Code:
li xbmcgui.ListItem('Folder of a different plugin')
url 'plugin://plugin.video.discovery_com/?channelID=Discovery&channelThumb=%2fhome%2fjp%2f.xbmc%2faddons%2fplugin.video.discovery_com%2fresources%2fthumbs%2fdiscovery_channel.png&mode=listShows&type&url=http%3a%2f%2fdsc.discovery.com%2fvideos'
xbmcplugin.addDirectoryItem(handle=addon_handleurl=urllistitem=liisFolder=true

And if you definitely need to use a builtin, you can also do so:
PHP Code:
xbmc.executebuiltin'Container.Update(plugin://plugin.video.discovery_com/?channelID=Discovery&channelThumb=%2fhome%2fjp%2f.xbmc%2faddons%2fplugin.video.discovery_com%2fre​sources%2fthumbs%2fdiscovery_channel.png&mode=listShows&type&url=http%3a%2f%2fdsc.discovery.com%2fvideos)' 
My GitHub. My Add-ons:
Image
Reply
#7
xbmc.executebuiltin works, but I cannot navigate back to my Addon, that said, the addDirectoryItem solution works like a charm !

Thanks man, I can now built my own Addon with all the goodies :-)
Reply
#8
Just in case people come across this thread like I did and want to know what built-in function to use to play a Youtube video, you can use this:

Code:
xbmc.executebuiltin('PlayMedia(plugin://plugin.video.youtube/?action=play_video&videoid=<VIDEO-ID>)')

I found this useful for playing a Youtube video from the context menu.
Reply
#9
(2014-01-17, 14:34)sphere Wrote: You need to use a URL like:
Code:
plugin://plugin.video.youtube/?action=play_video&videoid=<VIDEO-ID>
plugin://plugin.video.youtube/?action=play_video&videoid=oHg5SJYRHA0

On a PLAYABLE (non folder) ListItem, else it won't work.

Show us your code, then we can better help you.

How do you do a list? For example I have this channel: https://www.youtube.com/watch?v=aaJOwmHe...cTrzNn5LpA
Reply
#10
Ive been using an example addon from github to create my own addon.. I have it working with locally hosted files but cannot figure out how to edit it to play youtube streams.. An example of my code is posted below

Any help or advice would be appreciated..

Code:
# -*- coding: utf-8 -*-
# Module: default
# Author: Roman V. M.
# Created on: 28.11.2014
# License: GPL v.3 https://www.gnu.org/copyleft/gpl.html

import sys
from urlparse import parse_qsl
import xbmcgui
import xbmcplugin

# Get the plugin url in plugin:// notation.
__url__ = sys.argv[0]
# Get the plugin handle as an integer number.
__handle__ = int(sys.argv[1])

# Free sample videos are provided by www.vidsplay.com
# Here we use a fixed set of properties simply for demonstrating purposes
# In a "real life" plugin you will need to get info and links to video files/streams
# from some web-site or online service.
VIDEOS = {'Test Video': [{'name': 'Crab',
                       'thumb': 'http://www.vidsplay.com/vids/crab.jpg',
                       'video': 'https://www.youtube.com/watch?v=vrqJ89M7hxg',
                       'genre': 'Kodi'},
                    
                     ]}


def get_categories():
    """
    Get the list of video categories.
    Here you can insert some parsing code that retrieves
    the list of video categories (e.g. 'Movies', 'TV-shows', 'Documentaries' etc.)
    from some site or server.
    :return: list
    """
    return VIDEOS.keys()


def get_videos(category):
    """
    Get the list of videofiles/streams.
    Here you can insert some parsing code that retrieves
    the list of videostreams in a given category from some site or server.
    :param category: str
    :return: list
    """
    return VIDEOS[category]


def list_categories():
    """
    Create the list of video categories in the Kodi interface.
    :return: None
    """
    # Get video categories
    categories = get_categories()
    # Create a list for our items.
    listing = []
    # Iterate through categories
    for category in categories:
        # Create a list item with a text label and a thumbnail image.
        list_item = xbmcgui.ListItem(label=category, thumbnailImage=VIDEOS[category][0]['thumb'])
        # Set a fanart image for the list item.
        # Here we use the same image as the thumbnail for simplicity's sake.
        list_item.setProperty('fanart_image', VIDEOS[category][0]['thumb'])
        # Set additional info for the list item.
        # Here we use a category name for both properties for for simplicity's sake.
        # setInfo allows to set various information for an item.
        # For available properties see the following link:
        # http://mirrors.xbmc.org/docs/python-docs/15.x-isengard/xbmcgui.html#ListItem-setInfo
        list_item.setInfo('video', {'title': category, 'genre': category})
        # Create a URL for the plugin recursive callback.
        # Example: plugin://plugin.video.example/?action=listing&category=Animals
        url = '{0}?action=listing&category={1}'.format(__url__, category)
        # is_folder = True means that this item opens a sub-list of lower level items.
        is_folder = True
        # Add our item to the listing as a 3-element tuple.
        listing.append((url, list_item, is_folder))
    # Add our listing to Kodi.
    # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
    # instead of adding one by ove via addDirectoryItem.
    xbmcplugin.addDirectoryItems(__handle__, listing, len(listing))
    # Add a sort method for the virtual folder items (alphabetically, ignore articles)
    xbmcplugin.addSortMethod(__handle__, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
    # Finish creating a virtual folder.
    xbmcplugin.endOfDirectory(__handle__)


def list_videos(category):
    """
    Create the list of playable videos in the Kodi interface.
    :param category: str
    :return: None
    """
    # Get the list of videos in the category.
    videos = get_videos(category)
    # Create a list for our items.
    listing = []
    # Iterate through videos.
    for video in videos:
        # Create a list item with a text label and a thumbnail image.
        list_item = xbmcgui.ListItem(label=video['name'], thumbnailImage=video['thumb'])
        # Set a fanart image for the list item.
        # Here we use the same image as the thumbnail for simplicity's sake.
        list_item.setProperty('fanart_image', video['thumb'])
        # Set additional info for the list item.
        list_item.setInfo('video', {'title': video['name'], 'genre': video['genre']})
        # Set 'IsPlayable' property to 'true'.
        # This is mandatory for playable items!
        list_item.setProperty('IsPlayable', 'true')
        # Create a URL for the plugin recursive callback.
        # Example: plugin://plugin.video.example/?action=play&video=http://www.vidsplay.com/vids/crab.mp4
        url = '{0}?action=play&video={1}'.format(__url__, video['video'])
        # Add the list item to a virtual Kodi folder.
        # is_folder = False means that this item won't open any sub-list.
        is_folder = False
        # Add our item to the listing as a 3-element tuple.
        listing.append((url, list_item, is_folder))
    # Add our listing to Kodi.
    # Large lists and/or slower systems benefit from adding all items at once via addDirectoryItems
    # instead of adding one by ove via addDirectoryItem.
    xbmcplugin.addDirectoryItems(__handle__, listing, len(listing))
    # Add a sort method for the virtual folder items (alphabetically, ignore articles)
    xbmcplugin.addSortMethod(__handle__, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
    # Finish creating a virtual folder.
    xbmcplugin.endOfDirectory(__handle__)


def play_video(path):
    """
    Play a video by the provided path.
    :param path: str
    :return: None
    """
    # Create a playable item with a path to play.
    play_item = xbmcgui.ListItem(path=path)
    # Pass the item to the Kodi player.
    xbmcplugin.setResolvedUrl(__handle__, True, listitem=play_item)


def router(paramstring):
    """
    Router function that calls other functions
    depending on the provided paramstring
    :param paramstring:
    :return:
    """
    # Parse a URL-encoded paramstring to the dictionary of
    # {<parameter>: <value>} elements
    params = dict(parse_qsl(paramstring[1:]))
    # Check the parameters passed to the plugin
    if params:
        if params['action'] == 'listing':
            # Display the list of videos in a provided category.
            list_videos(params['category'])
        elif params['action'] == 'play':
            # Play a video from a provided URL.
            play_video(params['video'])
    else:
        # If the plugin is called from Kodi UI without any parameters,
        # display the list of video categories
        list_categories()


if __name__ == '__main__':
    # Call the router function and pass the plugin call parameters to it.
    router(sys.argv[2])
Reply
#11
Anyone?
Reply

Logout Mark Read Team Forum Stats Members Help
Accessing Youtube plugin to play youtube Videos0