Ejemplo n.º 1
0
def play_video(provider, context, re_match):
    def _compare(item):
        vq = context.get_settings().get_video_quality()
        return vq - item['format'].get('video', {}).get('resolution', 0)

    try:
        video_id = context.get_param('video_id')
        client = provider.get_client(context)
        video_streams = client.get_video_streams(context, video_id)
        video_stream = kodion.utils.find_best_fit(video_streams, _compare)

        if video_stream['format'].get('rtmpe', False):
            message = context.localize(
                provider.LOCAL_MAP['youtube.error.rtmpe_not_supported'])
            context.get_ui().show_notification(message, time_milliseconds=5000)
            return False

        video_item = VideoItem(video_id, video_stream['url'])
        video_id_dict = {video_id: video_item}
        utils.update_video_infos(provider, context, video_id_dict)

        # Trigger post play events
        if provider.is_logged_in():
            command = 'RunPlugin(%s)' % context.create_uri(
                ['events', 'post_play'], {'video_id': video_id})
            context.execute(command)
            pass

        return video_item
    except YouTubeException, ex:
        message = ex.get_message()
        message = kodion.utils.strip_html_from_text(message)
        context.get_ui().show_notification(message, time_milliseconds=15000)
        pass
Ejemplo n.º 2
0
def play_video(provider, context, re_match):
    def _compare(item):
        vq = context.get_settings().get_video_quality()
        return vq - item['format'].get('video', {}).get('resolution', 0)

    try:
        video_id = context.get_param('video_id')
        client = provider.get_client(context)
        video_streams = client.get_video_streams(context, video_id)
        video_stream = kodion.utils.find_best_fit(video_streams, _compare)

        if video_stream['format'].get('rtmpe', False):
            message = context.localize(provider.LOCAL_MAP['youtube.error.rtmpe_not_supported'])
            context.get_ui().show_notification(message, time_milliseconds=5000)
            return False

        video_item = VideoItem(video_id, video_stream['url'])
        video_id_dict = {video_id: video_item}
        utils.update_video_infos(provider, context, video_id_dict)

        # Trigger post play events
        if provider.is_logged_in():
            command = 'RunPlugin(%s)' % context.create_uri(['events', 'post_play'], {'video_id': video_id})
            context.execute(command)
            pass

        return video_item
    except YouTubeException, ex:
        message = ex.get_message()
        message = kodion.utils.strip_html_from_text(message)
        context.get_ui().show_notification(message, time_milliseconds=15000)
        pass
Ejemplo n.º 3
0
def my_subscriptions_to_items(provider, context, json_data):
    result = []
    video_id_dict = {}

    items = json_data.get('items', [])
    for item in items:
        video_id = item['id']
        video_item = VideoItem(item['title'],
                               uri=context.create_uri(['play'], {'video_id': video_id}))
        result.append(video_item)

        video_id_dict[video_id] = video_item
        pass

    channel_item_dict = {}
    utils.update_video_infos(provider, context, video_id_dict, channel_items_dict=channel_item_dict)
    utils.update_fanarts(provider, context, channel_item_dict)

    # next page
    continuations = json_data.get('continuations', '')
    if continuations:
        new_params = {}
        new_params.update(context.get_params())
        new_params['continuations'] = continuations

        new_context = context.clone(new_params=new_params)

        current_page = int(new_context.get_param('page', 1))
        next_page_item = kodion.items.NextPageItem(new_context, current_page, fanart=provider.get_fanart(new_context))
        result.append(next_page_item)
        pass

    return result
Ejemplo n.º 4
0
def play_video(provider, context, re_match):
    try:
        video_id = context.get_param('video_id')
        client = provider.get_client(context)
        video_streams = client.get_video_streams(context, video_id)
        if len(video_streams) == 0:
            message = context.localize(provider.LOCAL_MAP['youtube.error.no_video_streams_found'])
            context.get_ui().show_notification(message, time_milliseconds=5000)
            return False

	video_stream = None
        for v in video_streams:
	  if v["container"] == "dash":
	    video_stream = v
	    break
	  pass
	
        if video_stream is None:
	  video_stream = kodion.utils.select_stream(context, video_streams)

        if video_stream is None:
            return False

        if video_stream['video'].get('rtmpe', False):
            message = context.localize(provider.LOCAL_MAP['youtube.error.rtmpe_not_supported'])
            context.get_ui().show_notification(message, time_milliseconds=5000)
            return False

        video_item = VideoItem(video_id, video_stream['url'])
        video_id_dict = {video_id: video_item}
        utils.update_video_infos(provider, context, video_id_dict)

        # Trigger post play events
        if provider.is_logged_in():
            command = 'RunPlugin(%s)' % context.create_uri(['events', 'post_play'], {'video_id': video_id})
            context.execute(command)
            pass

        return video_item
    except YouTubeException, ex:
        message = ex.get_message()
        message = kodion.utils.strip_html_from_text(message)
        context.get_ui().show_notification(message, time_milliseconds=15000)
        pass
Ejemplo n.º 5
0
def my_subscriptions_to_items(provider, context, json_data):
    result = []
    video_id_dict = {}

    items = json_data.get('items', [])
    for item in items:
        video_id = item['id']
        video_item = VideoItem(item['title'],
                               uri=context.create_uri(['play'],
                                                      {'video_id': video_id}))
        result.append(video_item)

        video_id_dict[video_id] = video_item
        pass

    channel_item_dict = {}
    utils.update_video_infos(provider,
                             context,
                             video_id_dict,
                             channel_items_dict=channel_item_dict)
    utils.update_fanarts(provider, context, channel_item_dict)

    # next page
    next_page_token = json_data.get('next_page_token', '')
    if next_page_token or json_data.get('continue', False):
        new_params = {}
        new_params.update(context.get_params())
        new_params['next_page_token'] = next_page_token
        new_params['offset'] = int(json_data.get('offset', 0))

        new_context = context.clone(new_params=new_params)

        current_page = int(new_context.get_param('page', 1))
        next_page_item = kodion.items.NextPageItem(
            new_context, current_page, fanart=provider.get_fanart(new_context))
        result.append(next_page_item)
        pass

    return result
Ejemplo n.º 6
0
def my_subscriptions_to_items(provider, context, json_data):
    result = []
    video_id_dict = {}

    items = json_data.get('items', [])
    for item in items:
        video_id = item['id']
        video_item = utils.make_video_item_from_json_data(
            context, provider, item)
        result.append(video_item)

        video_id_dict[video_id] = video_item
        pass

    channel_item_dict = {}
    utils.update_video_infos(provider,
                             context,
                             video_id_dict,
                             channel_items_dict=channel_item_dict)
    utils.update_fanarts(provider, context, channel_item_dict)

    # next page
    continuations = json_data.get('continuations', '')
    if continuations:
        new_params = {}
        new_params.update(context.get_params())
        new_params['continuations'] = continuations

        new_context = context.clone(new_params=new_params)

        current_page = int(new_context.get_param('page', 1))
        next_page_item = kodion.items.NextPageItem(
            new_context, current_page, fanart=provider.get_fanart(new_context))
        result.append(next_page_item)
        pass

    return result
Ejemplo n.º 7
0
def play_video(provider, context, re_match):
    try:
        video_id = context.get_param('video_id')
        client = provider.get_client(context)
        video_streams = client.get_video_streams(context, video_id)
        if len(video_streams) == 0:
            message = context.localize(
                provider.LOCAL_MAP['youtube.error.no_video_streams_found'])
            context.get_ui().show_notification(message, time_milliseconds=5000)
            return False

        video_stream = None
        if context.get_settings().use_debrid():
            import urlresolver
            resolver_url = 'http://youtube.com/watch?v=%s' % video_id
            hmf = urlresolver.HostedMediaFile(url=resolver_url)
            resolved = hmf.resolve()
            if not resolved or not isinstance(resolved, basestring):
                try:
                    message = resolved.msg
                except:
                    message = 'Reason unknown, refer to URLResolver debug logging.'
                context.log_warning('URLResolver unable to resolve: %s\n%s' %
                                    (resolver_url, message))
            elif resolved.startswith('plugin://'):
                context.log_warning(
                    'URLResolver unusable result: %s\nCheck the log above for debrid resolver errors, '
                    'confirm debrid resolver is enabled, and has a lower number set in the priority '
                    'setting than the YouTube(or offending) resolver.' %
                    resolved)
            else:
                video_stream = {
                    'container': 'URLResolver',
                    'title': video_streams[0]['title'],
                    'url': resolved,
                    'meta': video_streams[0]['meta'],
                    'video': {
                        'encoding': '',
                        'height': 0
                    },
                    'audio': {
                        'bitrate': 0,
                        'encoding': ''
                    }
                }
                context.log_debug(
                    'URLResolver resolved now using video_stream:\n%s' %
                    video_stream)

        if not video_stream:
            video_stream = kodion.utils.select_stream(context, video_streams)

            if video_stream is None:
                return False

            if video_stream['video'].get('rtmpe', False):
                message = context.localize(
                    provider.LOCAL_MAP['youtube.error.rtmpe_not_supported'])
                context.get_ui().show_notification(message,
                                                   time_milliseconds=5000)
                return False

        video_item = VideoItem(video_id, video_stream['url'])

        if video_stream.get('meta', None):
            video_item.set_subtitles(video_stream['meta'].get(
                'subtitles', None))

        video_id_dict = {video_id: video_item}
        utils.update_video_infos(provider, context, video_id_dict)

        # Trigger post play events
        if provider.is_logged_in():
            command = 'RunPlugin(%s)' % context.create_uri(
                ['events', 'post_play'], {'video_id': video_id})
            context.execute(command)
            pass

        return video_item
    except YouTubeException, ex:
        message = ex.get_message()
        message = kodion.utils.strip_html_from_text(message)
        context.get_ui().show_notification(message, time_milliseconds=15000)
        pass
Ejemplo n.º 8
0
def play_video(provider, context, re_match):
    try:
        video_id = context.get_param('video_id')
        client = provider.get_client(context)

        try:
            f = open(context._get_cache_path() + '/history.json', 'r')
            history = json.load(f)
        except:
            history = {}
        if not video_id in history:
            f = open(context._get_cache_path() + '/history.json', 'w')
            stamp = datetime.now().strftime('%s')
            history[video_id] = stamp
            json.dump(history, f)

        video_streams = client.get_video_streams(context, video_id)
        if len(video_streams) == 0:
            message = context.localize(
                provider.LOCAL_MAP['youtube.error.no_video_streams_found'])
            context.get_ui().show_notification(message, time_milliseconds=5000)
            return False

        video_stream = kodion.utils.select_stream(context, video_streams)

        if video_stream is None:
            return False

        if video_stream['video'].get('rtmpe', False):
            message = context.localize(
                provider.LOCAL_MAP['youtube.error.rtmpe_not_supported'])
            context.get_ui().show_notification(message, time_milliseconds=5000)
            return False

        video_item = VideoItem(video_id, video_stream['url'])

        if video_stream.get('meta', None):
            video_item.set_subtitles(video_stream['meta'].get(
                'subtitles', None))
        video_id_dict = {video_id: video_item}
        utils.update_video_infos(provider, context, video_id_dict)

        #get related video and set to queue
        videos = []
        json_data = client.get_related_videos(video_id)
        if not v3.handle_error(provider, context, json_data):
            return False
        result = v3.response_to_items(provider,
                                      context,
                                      json_data,
                                      process_next_page=False)
        videos.extend(result)
        context.log_debug('video: "%s' % videos[0].get_uri())
        playlist = context.get_video_playlist()
        for x in videos:
            r = re.compile("video_id=(.*)")
            m = r.search(x.get_uri())
            vid = m.group(1)
            if vid not in history:
                playlist.add(x)
                break

        # Trigger post play events
        if provider.is_logged_in():
            command = 'RunPlugin(%s)' % context.create_uri(
                ['events', 'post_play'], {'video_id': video_id})
            context.execute(command)
            pass

        return video_item
    except YouTubeException, ex:
        message = ex.get_message()
        message = kodion.utils.strip_html_from_text(message)
        context.get_ui().show_notification(message, time_milliseconds=15000)
        pass