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)
def showMessage(self, msg): global _CALLBACK if _CALLBACK: try: return _CALLBACK(msg) except: util.ERROR('Error in callback. Removing.') _CALLBACK = None else: if xbmc.abortRequested: raise Exception('abortRequested') #print msg.encode('ascii','replace') return True
def getVideoInfo(url,quality=None,resolve_redirects=False): """ Returns a VideoInfo object or None. Quality is 0=SD, 1=720p, 2=1080p, 3=Highest Available and represents a maximum. """ try: info = _getYoutubeDLVideo(url,quality,resolve_redirects) if not info: return None except: util.ERROR('_getYoutubeDLVideo() failed',hide_tb=True) return None return info
def _actualGetExtension(info): url = info['url'] initialURLExt = url.rsplit('.', 1)[-1] resolvedURLExt = None contentTypeExt = None try: url = resolve_http_redirect(url) o = urlparse.urlparse(url, allow_fragments=True) conn = httplib.HTTPConnection(o.netloc) conn.request( "HEAD", o.path, headers={'User-Agent': YoutubeDLWrapper.std_headers['User-Agent']}) res = conn.getresponse() headers = dict(res.getheaders()) contentDisposition = headers.get('content-disposition') if contentDisposition: n, e = os.path.splitext(contentDisposition) if e: return e.strip('.') # If we get this we're lucky else: n, e = os.path.splitext(url) # Check the resolved url resolvedURLExt = e.strip('.') contentType = headers['content-type'] import mimetypes ext = mimetypes.guess_extension(contentType) if ext: contentTypeExt = ext.strip('.') # This is probabaly wrong except: util.ERROR(hide_tb=True) extensions = [ ex for ex in (resolvedURLExt, initialURLExt, contentTypeExt) if ex ] if 'media_type' in info: for ext in extensions: return _validateExtension(ext, info) else: for ext in extensions: if _isValidMediaExtension(ext): return ext for ext in extensions: return ext return 'mp4'
def mightHaveVideo(url, resolve_redirects=False): """ Returns True if the url matches against one of the handled site URLs. """ if resolve_redirects: try: url = resolve_http_redirect(url) except: util.ERROR('mightHaveVideo(): Failed to resolve URL') return False ytdl = YoutubeDLWrapper._getYTDL() for ies in ytdl._ies: if ies.suitable(url): return True return False
def _getYoutubeDLVideo(url,quality=None,resolve_redirects=False): if resolve_redirects: try: url = resolve_http_redirect(url) except: util.ERROR('_getYoutubeDLVideo(): Failed to resolve URL') return None ytdl = YoutubeDLWrapper._getYTDL() ytdl.clearDownloadParams() try: r = ytdl.extract_info(url,download=False) except YoutubeDLWrapper.DownloadError: return None urls = _selectVideoQuality(r, quality) if not urls: return None info = YoutubeDLWrapper.VideoInfo(r.get('id','')) info._streams = urls info.title = r.get('title',urls[0]['title']) info.description = r.get('description','') info.thumbnail = r.get('thumbnail',urls[0]['thumbnail']) info.sourceName = r.get('extractor','') info.info = r return info
############################################################################### # FIX: _subprocess doesn't exist on Xbox One ############################################################################### 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):