Exemplo n.º 1
0
def getDownloadPath(use_default=None):
    if use_default == None: use_default = not util.getSetting('confirm_download_path',True)
    path = util.getSetting('last_download_path','')
    if path:
        if not use_default:
            new = xbmcgui.Dialog().yesno(T(32005),T(32006),path,T(32007),T(32008),T(32009))
            if new: path = ''
    if not path: path = xbmcgui.Dialog().browse(3,T(32010),'files','',False,True)
    if not path: return
    util.setSetting('last_download_path',path)
    return path
Exemplo n.º 2
0
def _getYTDL():
    global _YTDL
    if _YTDL: return _YTDL
    if util.DEBUG and util.getSetting('ytdl_debug',False):
        _YTDL = YoutubeDLWrapper({'verbose':True})
    else:
        _YTDL = YoutubeDLWrapper()
    _YTDL.add_progress_hook(_YTDL.progressCallback)
    _YTDL.add_default_info_extractors()
    return _YTDL
Exemplo n.º 3
0
def _getYTDL():
    global _YTDL
    if _YTDL: return _YTDL
    if util.DEBUG and util.getSetting('ytdl_debug', False):
        _YTDL = YoutubeDLWrapper({'verbose': True})
    else:
        _YTDL = YoutubeDLWrapper()
    _YTDL.add_progress_hook(_YTDL.progressCallback)
    _YTDL.add_default_info_extractors()
    return _YTDL
Exemplo n.º 4
0
def _selectVideoQuality(r, quality=None):
    if quality is None:
        quality = util.getSetting('video_quality', 1)
    disable_dash = util.getSetting('disable_dash_video', True)

    entries = r.get('entries') or [r]

    minHeight, maxHeight = _getQualityLimits(quality)

    util.LOG('Quality: {0}'.format(quality), debug=True)
    urls = []
    idx = 0
    for entry in entries:
        defFormat = None
        defMax = 0
        defPref = -1000
        prefFormat = None
        prefMax = 0
        prefPref = -1000

        index = {}
        formats = entry.get('formats') or [entry]

        for i in range(len(formats)):
            index[formats[i]['format_id']] = i

        keys = sorted(index.keys())
        fallback = formats[index[keys[0]]]
        for fmt in keys:
            fdata = formats[index[fmt]]
            if 'height' not in fdata:
                continue
            if disable_dash and 'dash' in fdata.get('format_note', '').lower():
                continue
            h = fdata['height']
            p = fdata.get('preference', 1)
            if h >= minHeight and h <= maxHeight:
                if (h >= prefMax and p > prefPref) or (h > prefMax
                                                       and p >= prefPref):
                    prefMax = h
                    prefPref = p
                    prefFormat = fdata
            elif (h >= defMax and h <= maxHeight
                  and p > defPref) or (h > defMax and h <= maxHeight
                                       and p >= defPref):
                defMax = h
                defFormat = fdata
                defPref = p
        formatID = None
        if prefFormat:
            info = prefFormat
            logBase = '[{3}] Using Preferred Format: {0} ({1}x{2})'
        elif defFormat:
            info = defFormat
            logBase = '[{3}] Using Default Format: {0} ({1}x{2})'
        else:
            info = fallback
            logBase = '[{3}] Using Fallback Format: {0} ({1}x{2})'
        url = info['url']
        formatID = info['format_id']
        util.LOG(logBase.format(
            formatID, info.get('width', '?'), info.get('height', '?'),
            entry.get('title', '').encode('ascii', 'replace')),
                 debug=True)
        if url.find("rtmp") == -1:
            url += '|' + urllib.urlencode({
                'User-Agent':
                entry.get('user_agent')
                or YoutubeDLWrapper.std_headers['User-Agent']
            })
        else:
            url += ' playpath=' + fdata['play_path']
        new_info = dict(entry)
        new_info.update(info)
        urls.append({
            'xbmc_url': url,
            'url': info['url'],
            'title': entry.get('title', ''),
            'thumbnail': entry.get('thumbnail', ''),
            'formatID': formatID,
            'idx': idx,
            'ytdl_format': new_info
        })
        idx += 1
    return urls
Exemplo n.º 5
0
#         return _utils_unified_strdate(date_str)
#     except:
#         return '00000000'
# youtube_dl.utils.unified_strdate = _unified_strdate_wrap

# def _date_from_str_wrap(date_str):
#     try:
#         return _utils_date_from_str(date_str)
#     except:
#         return datetime.datetime.now().date()
# youtube_dl.utils.date_from_str = _date_from_str_wrap

###############################################################################

_YTDL = None
_DISABLE_DASH_VIDEO = util.getSetting('disable_dash_video', True)
_CALLBACK = None
# BLACKLIST = ['youtube:playlist', 'youtube:toplist', 'youtube:channel', 'youtube:user', 'youtube:search', 'youtube:show', 'youtube:favorites', 'youtube:truncated_url','vimeo:channel', 'vimeo:user', 'vimeo:album', 'vimeo:group', 'vimeo:review','dailymotion:playlist', 'dailymotion:user','generic'] # noqa E501
_BLACKLIST = []
_OVERRIDE_PARAMS = {}
_DOWNLOAD_CANCEL = False
_DOWNLOAD_START = None
_DOWNLOAD_DURATION = None


class VideoInfo:
    """
    Represents resolved site video
    Has the properties title, description, thumbnail and webpage
    The info property contains the original youtube-dl info
    """
Exemplo n.º 6
0
def _selectVideoQuality(r, quality=None):
        if quality is None:
            quality = util.getSetting('video_quality', 1)
        disable_dash = util.getSetting('disable_dash_video', True)

        entries = r.get('entries') or [r]

        minHeight, maxHeight = _getQualityLimits(quality)

        util.LOG('Quality: {0}'.format(quality), debug=True)
        urls = []
        idx = 0
        for entry in entries:
            defFormat = None
            defMax = 0
            defPref = -1000
            prefFormat = None
            prefMax = 0
            prefPref = -1000

            index = {}
            formats = entry.get('formats') or [entry]

            for i in range(len(formats)):
                index[formats[i]['format_id']] = i

            keys = sorted(index.keys())

            if u'18' in keys:
                cindex = keys.index(u'18')
                keys.insert(0, keys.pop(cindex))

            fallback = formats[index[keys[0]]]
            for fmt in keys:
                fdata = formats[index[fmt]]
                if 'height' not in fdata:
                    continue
                if disable_dash and 'dash' in fdata.get('format_note', '').lower():
                    continue
                h = fdata['height']
                p = fdata.get('preference', 1)
                if h >= minHeight and h <= maxHeight:
                    if (h >= prefMax and p > prefPref) or (h > prefMax and p >= prefPref):
                        prefMax = h
                        prefPref = p
                        prefFormat = fdata
                elif(h >= defMax and h <= maxHeight and p > defPref) or (h > defMax and h <= maxHeight and p >= defPref):
                        defMax = h
                        defFormat = fdata
                        defPref = p
            formatID = None
            if prefFormat:
                info = prefFormat
                logBase = '[{3}] Using Preferred Format: {0} ({1}x{2})'
            elif defFormat:
                info = defFormat
                logBase = '[{3}] Using Default Format: {0} ({1}x{2})'
            else:
                info = fallback
                logBase = '[{3}] Using Fallback Format: {0} ({1}x{2})'
            url = info['url']
            formatID = info['format_id']
            util.LOG(logBase.format(formatID, info.get('width', '?'), info.get('height', '?'), entry.get('title', '').encode('ascii', 'replace')), debug=True)
            if url.find("rtmp") == -1:
                url += '|' + urllib.urlencode({'User-Agent': entry.get('user_agent') or YoutubeDLWrapper.std_headers['User-Agent']})
            else:
                url += ' playpath='+fdata['play_path']
            new_info = dict(entry)
            new_info.update(info)
            urls.append(
                {
                    'xbmc_url': url,
                    'url': info['url'],
                    'title': entry.get('title', ''),
                    'thumbnail': entry.get('thumbnail', ''),
                    'formatID': formatID,
                    'idx': idx,
                    'ytdl_format': new_info
                }
            )
            idx += 1
        return urls
Exemplo n.º 7
0
    except:
        return '00000000'
youtube_dl.utils.unified_strdate = _unified_strdate_wrap

import datetime
_utils_date_from_str = youtube_dl.utils.date_from_str
def _date_from_str_wrap(date_str):
    try:
        return _utils_date_from_str(date_str)
    except:
        return datetime.datetime.now().date()
youtube_dl.utils.date_from_str = _date_from_str_wrap
###############################################################################

_YTDL = None
_DISABLE_DASH_VIDEO = util.getSetting('disable_dash_video',True)
_CALLBACK = None
#_BLACKLIST = ['youtube:playlist', 'youtube:toplist', 'youtube:channel', 'youtube:user', 'youtube:search', 'youtube:show', 'youtube:favorites', 'youtube:truncated_url','vimeo:channel', 'vimeo:user', 'vimeo:album', 'vimeo:group', 'vimeo:review','dailymotion:playlist', 'dailymotion:user','generic']
_BLACKLIST = []
_OVERRIDE_PARAMS = {}
_DOWNLOAD_CANCEL = False
_DOWNLOAD_START = None
_DOWNLOAD_DURATION = None
class VideoInfo:
    """
    Represents resolved site video
    Has the properties title, description, thumbnail and webpage
    The info property contains the original youtube-dl info
    """
    def __init__(self,ID=None):
        self.ID = ID
def _selectVideoQuality(r, quality=None):
    if quality is None:
        quality = util.getSetting("video_quality", 1)
    disable_dash = util.getSetting("disable_dash_video", True)

    entries = r.get("entries") or [r]

    minHeight, maxHeight = _getQualityLimits(quality)

    util.LOG("Quality: {0}".format(quality), debug=True)
    urls = []
    idx = 0
    for entry in entries:
        defFormat = None
        defMax = 0
        defPref = -1000
        prefFormat = None
        prefMax = 0
        prefPref = -1000

        index = {}
        formats = entry.get("formats") or [entry]

        for i in range(len(formats)):
            index[formats[i]["format_id"]] = i

        keys = sorted(index.keys())
        fallback = formats[index[keys[0]]]
        for fmt in keys:
            fdata = formats[index[fmt]]
            if "height" not in fdata:
                continue
            if disable_dash and "dash" in fdata.get("format_note", "").lower():
                continue
            h = fdata["height"]
            p = fdata.get("preference", 1)
            if h >= minHeight and h <= maxHeight:
                if (h >= prefMax and p > prefPref) or (h > prefMax and p >= prefPref):
                    prefMax = h
                    prefPref = p
                    prefFormat = fdata
            elif (h >= defMax and h <= maxHeight and p > defPref) or (h > defMax and h <= maxHeight and p >= defPref):
                defMax = h
                defFormat = fdata
                defPref = p
        formatID = None
        if prefFormat:
            info = prefFormat
            logBase = "[{3}] Using Preferred Format: {0} ({1}x{2})"
        elif defFormat:
            info = defFormat
            logBase = "[{3}] Using Default Format: {0} ({1}x{2})"
        else:
            info = fallback
            logBase = "[{3}] Using Fallback Format: {0} ({1}x{2})"
        url = info["url"]
        formatID = info["format_id"]
        util.LOG(
            logBase.format(
                formatID,
                info.get("width", "?"),
                info.get("height", "?"),
                entry.get("title", "").encode("ascii", "replace"),
            ),
            debug=True,
        )
        if url.find("rtmp") == -1:
            url += "|" + urllib.urlencode(
                {"User-Agent": entry.get("user_agent") or YoutubeDLWrapper.std_headers["User-Agent"]}
            )
        else:
            url += " playpath=" + fdata["play_path"]
        new_info = dict(entry)
        new_info.update(info)
        urls.append(
            {
                "xbmc_url": url,
                "url": info["url"],
                "title": entry.get("title", ""),
                "thumbnail": entry.get("thumbnail", ""),
                "formatID": formatID,
                "idx": idx,
                "ytdl_format": new_info,
            }
        )
        idx += 1
    return urls