def _get_core_components(addon_id=None):
    provider = Provider()
    if addon_id is not None:
        context = Context(params={'addon_id': addon_id}, plugin_id='plugin.video.youtube')
    else:
        context = Context(plugin_id='plugin.video.youtube')
    client = provider.get_client(context=context)

    return provider, context, client
Exemplo n.º 2
0
def __get_core_components(addon_id=None):
    """
    :param addon_id: addon id associated with developer keys to use for requests
    :return: addon provider, context and client 
    """
    provider = Provider()
    if addon_id is not None:
        context = Context(params={'addon_id': addon_id}, plugin_id='plugin.video.youtube')
    else:
        context = Context(plugin_id='plugin.video.youtube')
    client = provider.get_client(context=context)

    return provider, context, client
Exemplo n.º 3
0
def __add_new_developer(addon_id):
    """

    :param addon_id: id of the add-on being added
    :return:
    """
    params = {'addon_id': addon_id}
    context = Context(params=params, plugin_id='plugin.video.youtube')

    access_manager = context.get_access_manager()
    developers = access_manager.get_developers()
    if not developers.get(addon_id, None):
        developers[addon_id] = access_manager.get_new_developer()
        access_manager.set_developers(developers)
        context.log_debug('Creating developer user: |%s|' % addon_id)
def __add_new_developer(addon_id):
    """

    :param addon_id: id of the add-on being added
    :return:
    """
    params = {'addon_id': addon_id}
    context = Context(params=params, plugin_id='plugin.video.youtube')

    access_manager = context.get_access_manager()
    developers = access_manager.get_developers()
    if not developers.get(addon_id, None):
        developers[addon_id] = access_manager.get_new_developer()
        access_manager.set_developers(developers)
        context.log_debug('Creating developer user: |%s|' % addon_id)
def reset_access_tokens(addon_id):
    """

    :param addon_id: id of the add-on having it's access tokens reset
    :return:
    """
    if not addon_id or addon_id == 'plugin.video.youtube':
        context = Context(plugin_id='plugin.video.youtube')
        context.log_error('Developer reset access tokens: |%s| Invalid addon_id' % addon_id)
        return
    params = {'addon_id': addon_id}
    context = Context(params=params, plugin_id='plugin.video.youtube')

    access_manager = context.get_access_manager()
    access_manager.update_dev_access_token(addon_id, access_token='', refresh_token='')
def resolve(video_id):
    provider = Provider()
    context = Context(plugin_id='plugin.video.youtube')
    client = provider.get_client(context=context)
    streams = client.get_video_streams(context=context, video_id=video_id)
    sorted_streams = sorted(streams, key=lambda x: x.get('sort', 0), reverse=True)
    return sorted_streams
Exemplo n.º 7
0
def register_api_keys(addon_id, api_key, client_id, client_secret):
    """
    Usage:

    addon.xml
    ---
    <import addon="plugin.video.youtube" version="6.0.0"/>
    ---

    .py
    ---
    import youtube_registration
    youtube_registration.register_api_keys(addon_id='plugin.video.example',
                                           api_key='A1zaSyA0b5sTjgxzTzYLmVtradlFVBfSHNOJKS0',
                                           client_id='825419953561-ert5tccq1r0upsuqdf5nm3le39czk23a.apps.googleusercontent.com',
                                           client_secret='Y5cE1IKzJQe1NZ0OsOoEqpu3')
    # then use your keys by appending an addon_id param to the plugin url
    xbmc.executebuiltin('RunPlugin(plugin://plugin.video.youtube/channel/UCaBf1a-dpIsw8OxqH4ki2Kg/?addon_id=plugin.video.example)')
    # addon_id will be passed to all following calls
    ---

    :param addon_id: id of the add-on being registered
    :param api_key: YouTube Data v3 API key
    :param client_id: YouTube Data v3 Client id
    :param client_secret: YouTube Data v3 Client secret
    """

    context = Context(plugin_id='plugin.video.youtube')

    if not addon_id or addon_id == 'plugin.video.youtube':
        context.log_error('Register API Keys: |%s| Invalid addon_id' %
                          addon_id)
        return

    api_jstore = APIKeyStore(context)
    json_api = api_jstore.load()

    jkeys = json_api['keys']['developer'].get(addon_id, {})

    api_keys = {
        'origin': addon_id,
        'main': {
            'system': 'JSONStore',
            'key': b64encode(api_key),
            'id': b64encode(client_id),
            'secret': b64encode(client_secret)
        }
    }
    if jkeys and jkeys == api_keys:
        context.log_debug('Register API Keys: |%s| No update required' %
                          addon_id)
    else:
        json_api['keys']['developer'][addon_id] = api_keys
        api_jstore.save(json_api)
        context.log_debug('Register API Keys: |%s| Keys registered' % addon_id)
def __auth(addon_id, mode=SIGN_IN):
    """

    :param addon_id: id of the add-on being signed in
    :param mode: SIGN_IN or SIGN_OUT
    :return: addon provider, context and client
    """
    if not addon_id or addon_id == 'plugin.video.youtube':
        context = Context(plugin_id='plugin.video.youtube')
        context.log_error('Developer authentication: |%s| Invalid addon_id' % addon_id)
        return
    __add_new_developer(addon_id)
    params = {'addon_id': addon_id}
    provider = Provider()
    context = Context(params=params, plugin_id='plugin.video.youtube')

    _ = provider.get_client(context=context)  # NOQA
    logged_in = provider.is_logged_in()
    if mode == SIGN_IN:
        if logged_in:
            return True
        else:
            provider.reset_client()
            yt_login.process(mode, provider, context, sign_out_refresh=False)
    elif mode == SIGN_OUT:
        if not logged_in:
            return True
        else:
            provider.reset_client()
            try:
                yt_login.process(mode, provider, context, sign_out_refresh=False)
            except:
                reset_access_tokens(addon_id)
    else:
        raise Exception('Unknown mode: |%s|' % mode)

    _ = provider.get_client(context=context)  # NOQA
    if mode == SIGN_IN:
        return provider.is_logged_in()
    else:
        return not provider.is_logged_in()
Exemplo n.º 9
0
 def get_media_url(self, host, media_id):
     if Provider is None or Context is None:
         return 'plugin://plugin.video.youtube/play/?video_id=' + media_id
     else:
         provider = Provider()
         context = Context(plugin_id='plugin.video.youtube')
         client = provider.get_client(context=context)
         streams = client.get_video_streams(context=context, video_id=media_id)
         streams_no_dash = [item for item in streams if item['container'] != 'mpd']
         sorted_streams = sorted(streams_no_dash, key=lambda x: x.get('sort', 0), reverse=True)
         sorted_streams = [(item['title'], item['url']) for item in sorted_streams]
         return helpers.pick_source(sorted_streams)
Exemplo n.º 10
0
def __auth(addon_id, mode=SIGN_IN):
    """

    :param addon_id: id of the add-on being signed in
    :param mode: SIGN_IN or SIGN_OUT
    :return: addon provider, context and client
    """
    if not addon_id or addon_id == 'plugin.video.youtube':
        context = Context(plugin_id='plugin.video.youtube')
        context.log_error('Developer authentication: |%s| Invalid addon_id' %
                          addon_id)
        return
    __add_new_developer(addon_id)
    params = {'addon_id': addon_id}
    provider = Provider()
    context = Context(params=params, plugin_id='plugin.video.youtube')

    client = provider.get_client(context=context)  # NOQA
    logged_in = provider.is_logged_in()
    if mode == SIGN_IN:
        if logged_in:
            return True
        else:
            provider.reset_client()
            yt_login.process(mode,
                             provider,
                             context,
                             re_match=None,
                             sign_out_refresh=False)
    elif mode == SIGN_OUT:
        if not logged_in:
            return True
        else:
            provider.reset_client()
            try:
                yt_login.process(mode,
                                 provider,
                                 context,
                                 re_match=None,
                                 sign_out_refresh=False)
            except:
                reset_access_tokens(addon_id)
    else:
        raise Exception('Unknown mode: |%s|' % mode)

    client = provider.get_client(context=context)  # NOQA
    if mode == SIGN_IN:
        return provider.is_logged_in()
    else:
        return not provider.is_logged_in()
Exemplo n.º 11
0
def reset_access_tokens(addon_id):
    """

    :param addon_id: id of the add-on having it's access tokens reset
    :return:
    """
    if not addon_id or addon_id == 'plugin.video.youtube':
        context = Context(plugin_id='plugin.video.youtube')
        context.log_error(
            'Developer reset access tokens: |%s| Invalid addon_id' % addon_id)
        return
    params = {'addon_id': addon_id}
    context = Context(params=params, plugin_id='plugin.video.youtube')

    access_manager = context.get_access_manager()
    access_manager.update_dev_access_token(addon_id,
                                           access_token='',
                                           refresh_token='')
Exemplo n.º 12
0
__author__ = 'bromix'

from datetime import datetime
import time

from youtube_plugin.kodion.impl import Context
from youtube_plugin.kodion.constants import setting
from youtube_plugin.kodion.utils import YouTubeMonitor, YouTubePlayer

context = Context(plugin_id='plugin.video.youtube')

context.log_debug('YouTube settings startup initialization...')
version = context.get_system_version().get_version()
settings = context.get_settings()

mpd_addon = False

if version >= (17, 0):
    mpd_addon = True
else:
    settings.set_bool(setting.USE_DASH, False)

settings.set_bool(setting.DASH_SUPPORT_ADDON, mpd_addon)
context.log_notice('Startup: detected {0}, DASH_SUPPORT_ADDON = {1}'.format(
    context.get_system_version(), mpd_addon))


def strptime(stamp, stamp_fmt):
    import _strptime
    try:
        time.strptime('01 01 2012', '%d %m %Y')  # dummy call
Exemplo n.º 13
0
def _get_core_components():
    provider = Provider()
    context = Context(plugin_id='plugin.video.youtube')
    client = provider.get_client(context=context)

    return provider, context, client
Exemplo n.º 14
0
__author__ = 'bromix'

from datetime import datetime
import time

from youtube_plugin.kodion.impl import Context
from youtube_plugin.kodion.utils import YouTubeMonitor, YouTubePlayer

context = Context(plugin_id='plugin.video.youtube')

context.log_debug('YouTube settings startup initialization...')
version = context.get_system_version().get_version()
settings = context.get_settings()


def strptime(stamp, stamp_fmt):
    import _strptime
    try:
        time.strptime('01 01 2012', '%d %m %Y')  # dummy call
    except:
        pass
    return time.strptime(stamp, stamp_fmt)


def get_stamp_diff(current_stamp):
    stamp_format = '%Y-%m-%d %H:%M:%S.%f'
    current_datetime = datetime.now()
    if not current_stamp: return 86400  # 24 hrs
    try:
        stamp_datetime = datetime(
            *(strptime(current_stamp, stamp_format)[0:6]))
Exemplo n.º 15
0
__author__ = 'bromix'

from youtube_plugin.kodion.impl import Context
from youtube_plugin.kodion.constants import setting

if __name__ == '__main__':
    context = Context(plugin_id='plugin.video.youtube')

    context.log_debug('YouTube settings startup initialization...')
    version = context.get_system_version().get_version()
    application = context.get_system_version().get_app_name()
    settings = context.get_settings()

    mpd_addon = False
    mpd_builtin = False

    if version >= (17, 0):
        mpd_addon = True
    elif version >= (16, 5) and application == 'SPMC':
        mpd_builtin = True
    else:
        settings.set_bool(setting.USE_DASH, False)

    settings.set_bool(setting.DASH_SUPPORT_BUILTIN, mpd_builtin)
    settings.set_bool(setting.DASH_SUPPORT_ADDON, mpd_addon)
    context.log_notice(
        'Startup: detected %s, setting DASH_SUPPORT_BUILTIN = %s, DASH_SUPPORT_ADDON = %s'
        % (context.get_system_version(), mpd_builtin, mpd_addon))