def get_stream_default(plugin,
                       video_url,
                       download_mode=False):
    if download_mode:
        return download.download_video(video_url)

    quality = get_quality_YTDL(download_mode=download_mode)
    return plugin.extract_source(video_url, quality)
def download_video(video_url):
    """Callback function of the 'Download' context menu

    Args:
        video_url (str): URL of the video to download
    """

    #  print('URL Video to download ' + video_url)

    #  Now that we have video URL we can try to download this one
    YDStreamUtils = __import__('YDStreamUtils')
    YDStreamExtractor = __import__('YDStreamExtractor')

    vid = YDStreamExtractor.getVideoInfo(
        video_url,
        quality=get_quality_YTDL(download_mode=True),
        resolve_redirects=True)

    if vid is None:
        Script.log(
            'YDStreamExtractor.getVideoInfo() failed for video URL: %s' %
            video_url)
        return False

    path = Script.setting.get_string('dl_folder')
    download_ok = False
    with YDStreamUtils.DownloadProgress() as prog:
        try:
            YDStreamExtractor.setOutputCallback(prog)
            result = YDStreamExtractor.handleDownload(
                vid, bg=Script.setting.get_boolean('dl_background'), path=path)
            if result:
                if result.status == 'canceled':
                    error_message = result.message
                    Script.log('Download failed: %s' % error_message)
                else:
                    full_path_to_file = result.filepath
                    Script.log('Download success: %s' % full_path_to_file)
                    download_ok = True

        finally:
            YDStreamExtractor.setOutputCallback(None)

    if path != '' and \
            Script.setting.get_boolean('dl_item_filename') and \
            download_ok:

        try:
            filename = os.path.basename(full_path_to_file)
            _, file_extension = os.path.splitext(full_path_to_file)
            current_filepath = os.path.join(path, filename)
            video_name = get_selected_item_label()
            final_filepath = os.path.join(path, video_name + file_extension)
            xbmcvfs.rename(current_filepath, final_filepath)
        except Exception:
            Script.log('Failed to rename video file')

    return False
def download_video(video_url):
    """Callback function of the 'Download' context menu

    Args:
        video_url (str): URL of the video to download
    """

    #  print('URL Video to download ' + video_url)

    #  Now that we have video URL we can try to download this one

    YDStreamExtractor = __import__('YDStreamExtractor')

    info = {'url': video_url, 'quality': get_quality_YTDL(download_mode=True)}

    path = ensure_unicode(Script.setting.get_string('dl_folder'))
    filename = ''
    if Script.setting.get_boolean('dl_item_filename'):
        filename = get_selected_item_label()
    bg = Script.setting.get_boolean('dl_background')
    YDStreamExtractor.handleDownload(info, bg=bg, path=path, filename=filename)

    return False