Exemplo n.º 1
0
    def downloadPlaying(self):
        title = BBTagRemove(xbmc.getInfoLabel('Player.Title'))
        # xbmc.getInfoLabel('Player.Filenameandpath')
        url = xbmc.Player().getPlayingFile()
        thumbnail = xbmc.getInfoLabel('Player.Art(thumb)')
        extra = None
        if '|' in url:
            url, extra = url.rsplit('|', 1)
            url = url.rstrip('?')
        import time
        info = {'url': url, 'title': title, 'thumbnail': thumbnail,
                'id': int(time.time()), 'media_type': 'video'}
        if extra:
            try:
                import urlparse
                for k, v in urlparse.parse_qsl(extra):
                    if k.lower() == 'user-agent':
                        info['user_agent'] = v
                        break
            except:
                util.ERROR(hide_tb=True)

        util.LOG(repr(info), debug=True)

        import YDStreamExtractor
        YDStreamExtractor.handleDownload(info, bg=True)
Exemplo n.º 2
0
 def progressCallback(self, info):
     global _DOWNLOAD_CANCEL
     if self._monitor.abortRequested() or _DOWNLOAD_CANCEL:
         _DOWNLOAD_CANCEL = False
         raise DownloadCanceledException('abortRequested')
     if _DOWNLOAD_DURATION:
         if time.time() - _DOWNLOAD_START > _DOWNLOAD_DURATION:
             raise DownloadCanceledException('duration_reached')
     if not _CALLBACK:
         return
     # 'downloaded_bytes': byte_counter,
     # 'total_bytes': data_len,
     # 'tmpfilename': tmpfilename,
     # 'filename': filename,
     # 'status': 'downloading',
     # 'eta': eta,
     # 'speed': speed
     sofar = info.get('downloaded_bytes')
     total = info.get('total_bytes') or info.get('total_bytes_estimate')
     if info.get('filename'):
         self._lastDownloadedFilePath = info.get('filename')
     pct = ''
     pct_val = 0
     eta = None
     if sofar is not None and total:
         pct_val = int((float(sofar) / total) * 100)
         pct = ' (%s%%)' % pct_val
     elif _DOWNLOAD_DURATION:
         sofar = time.time() - _DOWNLOAD_START
         eta = _DOWNLOAD_DURATION - sofar
         pct_val = int((float(sofar) / _DOWNLOAD_DURATION) * 100)
     eta = eta or info.get('eta') or ''
     eta_str = ''
     if eta:
         eta_str = StreamUtils.durationToShortText(eta)
         eta = '  ETA: ' + eta_str
     speed = info.get('speed') or ''
     speed_str = ''
     if speed:
         speed_str = StreamUtils.simpleSize(speed) + 's'
         speed = '  ' + speed_str
     status = '%s%s:' % (info.get('status', '?').title(), pct)
     text = CallbackMessage(status + eta + speed, pct_val, eta_str,
                            speed_str, info)
     ok = self.showMessage(text)
     if not ok:
         util.LOG('Download canceled')
         raise DownloadCanceledException()
Exemplo n.º 3
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.º 4
0
try:
    import _subprocess
except ImportError:
    from yd_private_libs import _subprocess

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

try:
    import youtube_dl
except Exception:
    util.ERROR('Failed to import youtube-dl')
    youtube_dl = None

coreVersion = youtube_dl.version.__version__
updater.saveVersion(coreVersion)
util.LOG('youtube_dl core version: {0}'.format(coreVersion))

###############################################################################
# FIXES: datetime.datetime.strptime evaluating as None in Kodi
###############################################################################

try:
    datetime.datetime.strptime('0', '%H')
except TypeError:
    # Fix for datetime issues with XBMC/Kodi
    def redefine_datetime(orig):
        class datetime(orig):
            @classmethod
            def strptime(cls, dstring, dformat):
                try:
                    return datetime.datetime(