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 handlePush(data, from_gui=False): if not from_gui and checkForWindow(): # Do nothing if the window is open return False if data.get("type") == "link": url = data.get("url", "") if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info["title"] or "?") idx = xbmcgui.Dialog().select(util.T(32091), vlist) if idx < 0: return vid.selectStream(idx) util.LOG(vid.streamURL()) # TODO: REMOVE StreamUtils.play(vid.streamURL()) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == "video" or media == "music": StreamUtils.play(url) return True elif media == "image": import gui gui.showImage(url) return True elif data.get("type") == "file": if data.get("file_type", "").startswith("image/"): import gui gui.showImage(data.get("file_url", "")) return True elif data.get("file_type", "").startswith("video/") or data.get("file_type", "").startswith("audio/"): StreamUtils.play(data.get("file_url", "")) return True elif data.get("type") == "note": import gui gui.showNote(data.get("body", "")) return True elif data.get("type") == "list": import gui gui.showList(data) return True elif data.get("type") == "address": import urllib xbmc.executebuiltin( "XBMC.RunScript(special://home/addons/service.pushbullet.com/lib/maps.py,service.pushbullet.com,%s,None,)" % urllib.quote(data.get("address", "")) ) return True return False
def download_video(self): selection = xbmcgui.Dialog().select(heading=LANG(22080), list=[LANG(33003)]) if selection == 0: import YDStreamExtractor vid = YDStreamExtractor.getVideoInfo(self.listitem.getProperty("youtube_id"), quality=1) YDStreamExtractor.handleDownload(vid)
def showVideo(url): if url: import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) vid = YDStreamExtractor.getVideoInfo(url, quality=1) url = vid.streamURL() plugin.set_resolved_url({'path':url, 'info': {'type': 'Video'}})
def PlayTrailer(youtube_id): import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if vid: stream_url = vid.streamURL() log("Youtube Trailer:" + stream_url) xbmc.executebuiltin("PlayMedia(%s)" % stream_url)
def download_video(self): selection = xbmcgui.Dialog().select(heading=LANG(22080), list=[LANG(33003)]) if selection == 0: youtube_id = self.listitem.getProperty("youtube_id") import YDStreamExtractor vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) YDStreamExtractor.handleDownload(vid)
def handlePush(data, from_gui=False): if not from_gui and checkForWindow(): #Do nothing if the window is open return False if data.get('type') == 'link': url = data.get('url', '') if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info['title'] or '?') idx = xbmcgui.Dialog().select(common.localise(32091), vlist) if idx < 0: return vid.selectStream(idx) playMedia(vid.streamURL(), vid.title, vid.thumbnail, vid.description) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == 'video' or media == 'audio': url += '|' + urllib.urlencode({'User-Agent': getURLUserAgent(url)}) playMedia(url, playlist_type='video' and xbmc.PLAYLIST_VIDEO or xbmc.PLAYLIST_MUSIC) return True elif media == 'image': import gui gui.showImage(url) return True elif data.get('type') == 'file': if data.get('file_type', '').startswith('image/'): import gui gui.showImage(data.get('file_url', '')) return True elif data.get('file_type', '').startswith('video/') or data.get( 'file_type', '').startswith('audio/'): playMedia(data.get('file_url', '')) return True elif data.get('type') == 'note': import gui gui.showNote(data.get('body', '')) return True elif data.get('type') == 'list': import gui gui.showList(data) return True elif data.get('type') == 'address': cmd = 'XBMC.RunScript({0},MAP,{1},None,)'.format( common.__addonid__, urllib.quote(data.get('address', ''))) xbmc.executebuiltin(cmd) return True return False
def handlePush(data, from_gui=False): if not from_gui and checkForWindow(): # Do nothing if the window is open return False if data.get("type") == "link": url = data.get("url", "") if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info["title"] or "?") idx = xbmcgui.Dialog().select(common.localise(32091), vlist) if idx < 0: return vid.selectStream(idx) playMedia(vid.streamURL(), vid.title, vid.thumbnail, vid.description) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == "video" or media == "audio": url += "|" + urllib.urlencode({"User-Agent": getURLUserAgent(url)}) playMedia(url, playlist_type="video" and xbmc.PLAYLIST_VIDEO or xbmc.PLAYLIST_MUSIC) return True elif media == "image": import gui gui.showImage(url) return True elif data.get("type") == "file": if data.get("file_type", "").startswith("image/"): import gui gui.showImage(data.get("file_url", "")) return True elif data.get("file_type", "").startswith("video/") or data.get("file_type", "").startswith("audio/"): playMedia(data.get("file_url", "")) return True elif data.get("type") == "note": import gui gui.showNote(data.get("body", "")) return True elif data.get("type") == "list": import gui gui.showList(data) return True elif data.get("type") == "address": cmd = "XBMC.RunScript({0},MAP,{1},None,)".format(common.__addonid__, urllib.quote(data.get("address", ""))) xbmc.executebuiltin(cmd) return True return False
def getVideo(self, episodePagePath): videoUrlRegex = re.compile( r"<iframe (?:.+?)\s+src=\"(?P<video_page>https*://www.youtube.com[-_a-zA-Z0-9\/]+)?") videoPageSource = super(Swarnavahini, self).getSource(episodePagePath) # print "video page source="+videoPageSource YDStreamExtractor.disableDASHVideo(True) video_urls = videoUrlRegex.findall(videoPageSource) url = video_urls[0] vid = YDStreamExtractor.getVideoInfo(url, quality=1) return vid.streamURL()
def play_trailer(youtube_id="", listitem=None, popstack=False): if not listitem: listitem = xbmcgui.ListItem(xbmc.getLocalizedString(20410)) listitem.setInfo('video', {'Title': xbmc.getLocalizedString(20410), 'Genre': 'Youtube Video'}) import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if vid: stream_url = vid.streamURL() PlayMedia(stream_url, listitem, popstack)
def PlayTrailer(youtube_id="", listitem=None, popstack=False): if not listitem: listitem =xbmcgui.ListItem ('Trailer') listitem.setInfo('video', {'Title': 'Trailer', 'Genre': 'Youtube Video'}) import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if vid: stream_url = vid.streamURL() log("Youtube Trailer:" + stream_url) PlayMedia(stream_url, listitem, popstack)
def PlayTrailer(youtube_id="", listitem=None, popstack=False): if not listitem: listitem = xbmcgui.ListItem(xbmc.getLocalizedString(20410)) listitem.setInfo('video', {'Title': xbmc.getLocalizedString(20410), 'Genre': 'Youtube Video'}) import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if vid: stream_url = vid.streamURL() log("Youtube Trailer:" + stream_url) PlayMedia(stream_url, listitem, popstack)
def handlePush(data, from_gui=False): if not from_gui and checkForWindow(): #Do nothing if the window is open return False if data.get('type') == 'link': url = data.get('url', '') if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info['title'] or '?') idx = xbmcgui.Dialog().select(util.T(32091), vlist) if idx < 0: return vid.selectStream(idx) util.LOG(vid.streamURL()) #TODO: REMOVE StreamUtils.play(vid.streamURL()) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == 'video' or media == 'music': StreamUtils.play(url) return True elif media == 'image': import gui gui.showImage(url) return True elif data.get('type') == 'file': if data.get('file_type', '').startswith('image/'): import gui gui.showImage(data.get('file_url', '')) return True elif data.get('file_type', '').startswith('video/') or data.get( 'file_type', '').startswith('audio/'): StreamUtils.play(data.get('file_url', '')) return True elif data.get('type') == 'note': import gui gui.showNote(data.get('body', '')) return True elif data.get('type') == 'list': import gui gui.showList(data) return True elif data.get('type') == 'address': import urllib xbmc.executebuiltin( 'XBMC.RunScript(special://home/addons/service.pushbullet.com/lib/maps.py,service.pushbullet.com,%s,None,)' % urllib.quote(data.get('address', ''))) return True return False
def playVideo(name, url): import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) #Kodi (XBMC) only plays the video for DASH streams, so you don't want these normally. Of course these are the only 1080p streams on YouTube # url = "https://www.youtube.com/watch?v=" + url #a youtube ID will work as well and of course you could pass the url of another site vid = YDStreamExtractor.getVideoInfo(url,quality=1) #quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() #This is what Kodi (XBMC) will play print "stream_url =", stream_url img = " " listitem = xbmcgui.ListItem(name, iconImage=img, thumbnailImage=img) playfile = xbmc.Player() playfile.play(stream_url, listitem)
def _download(info, background=True): if background: YDStreamExtractor.handleDownload(info, bg=True) else: result = YDStreamExtractor.handleDownload(info, bg=False) if result: log_utils.log('Download complete: |%s|' % result.filepath) elif result.status != 'canceled': log_utils.log('Download failed: |%s|' % result.message, log_utils.LOGERROR) kodi.notify(msg=result.message, sound=True) else: log_utils.log('Download cancelled')
def play_video(path, isyoutube, isplayable): """ Play a video by the provided path. :param path: Fully-qualified video URL :type path: str :type isyoutube: bool :type isplayable: Number 0-4 """ if isplayable in ('0', '2', '3'): # unplayable item (unknown, coming soon, outdated) if isplayable == '2': if not dialogYesNo(LS(30000), LS(30067)): return elif isplayable == '3': if not dialogYesNo(LS(30000), LS(30066)): return else: return if strToBool(isyoutube): writeLog('Youtube video, invoke plugin.youtube.dl', xbmc.LOGINFO) writeLog('try to use quality factor {}'.format(yt_quality)) if YDStreamExtractor.mightHaveVideo(path, resolve_redirects=True): try: vid = YDStreamExtractor.getVideoInfo(path, quality=yt_quality, resolve_redirects=True) if vid is not None: if vid.hasMultipleStreams(): s_list = list() for stream in vid.streams(): s_list.append(stream['title']) writeLog( 'multiple streams detected: {}'.format( ', '.join(s_list)), xbmc.LOGINFO) path = vid.streamURL() else: notify(LS(30000), LS(30047), xbmcgui.NOTIFICATION_WARNING) writeLog('Could not extract video stream', xbmc.LOGERROR) except Exception as e: notify(LS(30000), LS(30047), xbmcgui.NOTIFICATION_WARNING) writeLog('youtube_dl has thrown an exception', xbmc.LOGERROR) writeLog(str(e), xbmc.LOGERROR) else: writeLog('Could not extract video stream', xbmc.LOGERROR) notify(LS(30000), LS(), xbmcgui.NOTIFICATION_WARNING) play_item = xbmcgui.ListItem(path=path) xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
def resolve(self,url): html = client.request(url) soup = webutils.bs(html) video=soup.find('iframe')['src'] if 'youtube' in video: yt_id = self.yt_video_id(video) l = 'http://www.youtube.com/watch?v=' + yt_id import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) vid = YDStreamExtractor.getVideoInfo(l,quality=1) resolved = vid.streamURL() return resolved
def resolve(self, url): html = client.request(url) soup = webutils.bs(html) video = soup.find('iframe')['src'] if 'youtube' in video: yt_id = self.yt_video_id(video) l = 'http://www.youtube.com/watch?v=' + yt_id import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) vid = YDStreamExtractor.getVideoInfo(l, quality=1) resolved = vid.streamURL() return resolved
def hasMedia(self, count_link_images=False): images = False video = False for l in self.links(): if l.isImage(): images = True if count_link_images and l.textIsImage(): images = True elif StreamExtractor.mightHaveVideo(l.url) or StreamExtractor.mightHaveVideo(l.text): video = True if not images: images = bool(self.imageURLs()) return images, video
def playYoutubeVideo(self, youtube_id="", listitem=None, popstack=True): if not listitem: listitem = xbmcgui.ListItem(xbmc.getLocalizedString(20410)) listitem.setInfo('video', {'Title': xbmc.getLocalizedString(20410), 'Genre': 'Youtube Video'}) import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) if youtube_id: vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if vid: stream_url = vid.streamURL() self.play(stream_url, listitem) else: Notify("no youtube id found")
def handlePush(data,from_gui=False): if not from_gui and checkForWindow(): #Do nothing if the window is open return False if data.get('type') == 'link': url = data.get('url','') if StreamExtractor.mightHaveVideo(url): vid = StreamExtractor.getVideoInfo(url) if vid: if vid.hasMultipleStreams(): vlist = [] for info in vid.streams(): vlist.append(info['title'] or '?') idx = xbmcgui.Dialog().select(common.localise(32091),vlist) if idx < 0: return vid.selectStream(idx) playMedia(vid.streamURL(),vid.title,vid.thumbnail,vid.description) return True if canPlayURL(url): handleURL(url) return True media = getURLMediaType(url) if media == 'video' or media == 'audio': url += '|' + urllib.urlencode({'User-Agent':getURLUserAgent(url)}) playMedia(url,playlist_type='video' and xbmc.PLAYLIST_VIDEO or xbmc.PLAYLIST_MUSIC) return True elif media == 'image': import gui gui.showImage(url) return True elif data.get('type') == 'file': if data.get('file_type','').startswith('image/'): import gui gui.showImage(data.get('file_url','')) return True elif data.get('file_type','').startswith('video/') or data.get('file_type','').startswith('audio/'): playMedia(data.get('file_url','')) return True elif data.get('type') == 'note': import gui gui.showNote(data.get('body','')) return True elif data.get('type') == 'list': import gui gui.showList(data) return True elif data.get('type') == 'address': cmd = 'XBMC.RunScript({0},MAP,{1},None,)'.format(common.__addonid__,urllib.quote(data.get('address',''))) xbmc.executebuiltin(cmd) return True return False
def playYoutubeVideo(self, youtube_id="", listitem=None, popstack=True): if not listitem: listitem = xbmcgui.ListItem ('Trailer') listitem.setInfo('video', {'Title': listitem.getProperty('Label'), 'Plot': listitem.getProperty('Description'), 'Genre': 'Youtube Video'}) import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) if youtube_id: vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if vid: stream_url = vid.streamURL() log("Youtube Trailer:" + stream_url) self.play(stream_url, listitem) else: Notify("no youtube id found")
def playVideo(name, url): pass#print"In playVideo url =", url import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) #Kodi (XBMC) only plays the video for DASH streams, so you don't want these normally. Of course these are the only 1080p streams on YouTube # url = "https://www.youtube.com/watch?v=" + url #a youtube ID will work as well and of course you could pass the url of another site vid = YDStreamExtractor.getVideoInfo(url,quality=1) #quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() #This is what Kodi (XBMC) will play pass#print"stream_url =", stream_url n1 = stream_url.find("|", 0) stream_url = stream_url[:n1] pass#print"stream_url 2=", stream_url img = " " playfile = xbmc.Player() playfile.play(stream_url)
def playYoutubeVideo(self, youtube_id="", listitem=None, popstack=True): if not listitem: listitem = xbmcgui.ListItem(xbmc.getLocalizedString(20410)) listitem.setInfo('video', {'Title': xbmc.getLocalizedString(20410), 'Genre': 'Youtube Video'}) import YDStreamExtractor YDStreamExtractor.disableDASHVideo(True) if youtube_id: vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if vid: stream_url = vid.streamURL() log("Youtube Trailer:" + stream_url) self.play(stream_url, listitem) else: Notify("no youtube id found")
def playVideo(name, url): import YDStreamExtractor YDStreamExtractor.disableDASHVideo( True ) #Kodi (XBMC) only plays the video for DASH streams, so you don't want these normally. Of course these are the only 1080p streams on YouTube # url = "https://www.youtube.com/watch?v=" + url #a youtube ID will work as well and of course you could pass the url of another site vid = YDStreamExtractor.getVideoInfo( url, quality=1) #quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() #This is what Kodi (XBMC) will play print "stream_url =", stream_url img = " " listitem = xbmcgui.ListItem(name, iconImage=img, thumbnailImage=img) playfile = xbmc.Player() playfile.play(stream_url, listitem)
def start_play(): kb = xbmc.Keyboard('default', 'heading', False) kb.setDefault('') kb.setHeading(enter0) kb.setHiddenInput(False) kb.doModal() if (kb.isConfirmed()): try: url = kb.getText(kb) vid = YDStreamExtractor.getVideoInfo(url, quality=1) stream_url = vid.streamURL() title = vid.selectedStream()['title'] thumbnail = vid.selectedStream()['thumbnail'] listitem = xbmcgui.ListItem(title) listitem.setInfo('video', {'Title': title}) listitem.setArt({'thumb': thumbnail, 'icon': thumbnail}) xbmc.Player().play(stream_url, listitem) except: xbmc.executebuiltin('Notification(%s, %s, %d, %s)' % (addonname, errorline2, time, infoicon)) start_menu() else: xbmc.executebuiltin('Notification(%s, %s, %d, %s)' % (addonname, errorline1, time, infoicon)) start_menu()
def fullInfo(videoId): fullUrl = "https://www.youtube.com/watch?v=" + videoId vid = YDStreamExtractor.getVideoInfo(fullUrl,quality=1) streamurl = vid.streamURL() title = vid.title description = vid.description thumb = vid.thumbnail return streamurl, title, description, thumb # def batchResolve(collection): # for video in collection.videoList: # thread = ResolveThread(video) # thread.start() # # # import threading # class ResolveThread(threading.Thread): # def __init__(self, video): # threading.Thread.__init__(self) # self.video = video # # def run(self): # print 'starting thread' # vid = YDStreamExtractor.getVideoInfo(self.video.fullUrl(),quality=1) # print vid.streamURL()
def get_video(self, productID): if 'yt_' in productID: yt_url = 'http://www.youtube.com/watch?v=' + productID.split( 'yt_', 1)[1] yt_video = YDStreamExtractor.getVideoInfo(yt_url, quality=3) return Item(yt_video.title, yt_video.streamURL(), yt_video.thumbnail) else: content = self.ua.get(self.get_player_init_url(productID)) link_re = re.compile("'?src'?\s*:\s+'(https?://[^']+\\.m3u8.*)'") title_re = re.compile("programName: '(.*?)',") thumb_re = re.compile("thumbnails: {[\s\n]*url: '(.*?)\$") sd_link = link_re.search(content) if sd_link is None: return None hd_link = None if self.hd_enabled: hd_link = self.try_get_hd_link(sd_link.group(1)) if hd_link: return hd_link title = title_re.search(content).group(1) thumb = None thumb_result = thumb_re.search(content) if thumb_result: thumb = thumb_result.group(1) + '010.jpg' return Item(title, sd_link.group(1), thumb)
def playYoutubeVid(id, meta=None, poster=None): if meta is None: #Create an empty meta, so we can fill it with the information grabbed from youtube meta = {} if 'title' not in meta: meta['title'] = v.title #Store the youtube title in the meta if poster is None: poster = 'Default.png' #YDStreamExtractor.disableDASHVideo(True) #Kodi (XBMC) only plays the video for DASH streams, so you don't want these normally. Of course these are the only 1080p streams on YouTube try: #url = id #a youtube ID will work as well and of course you could pass the url of another site vid = YDStreamExtractor.getVideoInfo( id, quality=1) #quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() #This is what Kodi (XBMC) will play except: dev.log('Failed to get a valid stream_url!') return False #Failed to grab a video title #xbmc.Player().play(v.getbest().url) #Play this video liz = xbmcgui.ListItem(meta['title'], iconImage=poster, thumbnailImage=poster) liz.setInfo(type="Video", infoLabels=meta) liz.setPath(stream_url) return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
def playVideo(url): vid = YDStreamExtractor.getVideoInfo( url, quality=2) # quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() # This is what Kodi (XBMC) will play stream_url = stream_url.split('|')[0] xbmcplugin.setResolvedUrl(pluginhandle, True, xbmcgui.ListItem(path=stream_url))
def application(environ, start_response): d = parse_qs(environ['QUERY_STRING']) url = d.get('url', [''])[0] usevfs = d.get('vfs', ['0'])[0] qual = d.get('qual', [0])[0] if not url: start_response('400 Bad Request') return [""] #url = "http://www.youtube.com/watch?v=DBvv2_0EV54" #a youtube ID will work as well and of course you could pass the url of another site vid = YDStreamExtractor.getVideoInfo( url, quality=qual) #quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() #This is what Kodi (XBMC) will play if not stream_url: start_response('500 Internal server error') return [""] prot_options = stream_url.find('|') if prot_options != -1: stream_url = stream_url[:prot_options] if usevfs == '1': vfs_stream_url = "http://" + environ['SERVER_NAME'] + ":" + environ[ 'SERVER_PORT'] + "/vfs/" + urllib.quote_plus(stream_url) start_response('302 Temporary Redirect', [('Location', vfs_stream_url)]) else: start_response('302 Temporary Redirect', [('Location', stream_url)]) return [""]
def playYoutubeVid(id, meta=None, poster=None): dev.log('poster: '+poster) #Poster URL that hickups the addon: image://C%3a%5cKodi%5cportable_data%5cuserdata%5caddon_data%5cplugin.video.youtubelibrary%5cStreams%5cTV%5cSleuteltje%20-%20Bios%20Intros%5cfolder.jpg/ #poster = None if meta is None: #Create an empty meta, so we can fill it with the information grabbed from youtube meta = {} if poster is None: poster = 'Default.png' elif poster.startswith('image://'): poster = poster[8:-1] poster = urllib.unquote(urllib.unquote(poster)) dev.log('poster cleaned: '+poster) #YDStreamExtractor.disableDASHVideo(True) #Kodi (XBMC) only plays the video for DASH streams, so you don't want these normally. Of course these are the only 1080p streams on YouTube try: #url = id #a youtube ID will work as well and of course you could pass the url of another site vid = YDStreamExtractor.getVideoInfo(id,quality=1) #quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() #This is what Kodi (XBMC) will play except: dev.log('Failed to get a valid stream_url!') return False #Failed to grab a video title if 'title' not in meta: meta['title'] = vid.title #Store the youtube title in the meta #xbmc.Player().play(v.getbest().url) #Play this video liz = xbmcgui.ListItem(meta['title'], iconImage=poster, thumbnailImage=poster) liz.setInfo( type="Video", infoLabels=meta ) liz.setPath(stream_url) return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
def playYoutubeVid(id, meta=None, poster=None): ''' from resources.lib import pafy pafy.set_api_key(vars.API_KEY) #Resolve the youtube video url for ourselves v = pafy.new(id) stream_url = v.getbest().url ''' if meta is None: #Create an empty meta, so we can fill it with the information grabbed from youtube meta = {} if 'title' not in meta: meta['title'] = v.title #Store the youtube title in the meta if poster is None: poster = 'Default.png' #YDStreamExtractor.disableDASHVideo(True) #Kodi (XBMC) only plays the video for DASH streams, so you don't want these normally. Of course these are the only 1080p streams on YouTube try: #url = id #a youtube ID will work as well and of course you could pass the url of another site vid = YDStreamExtractor.getVideoInfo(id,quality=1) #quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() #This is what Kodi (XBMC) will play except: dev.log('Failed to get a valid stream_url!') return False #Failed to grab a video title #xbmc.Player().play(v.getbest().url) #Play this video liz = xbmcgui.ListItem(meta['title'], iconImage=poster, thumbnailImage=poster) liz.setInfo( type="Video", infoLabels=meta ) liz.setPath(stream_url) return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
def downloadYoutubeVid(name, fold, videoid, settings, type='', season=None): #youtube-dl command to download best quality: -f bestvideo[ext!=webm]+bestaudio[ext!=webm]/best[ext!=webm] #YDStreamExtractor.disableDASHVideo(True) movieLibrary = vars.tv_folder #The path we should save in is the vars.tv_folder setting from the addon settings if type == 'musicvideo': movieLibrary = vars.musicvideo_folder if type == 'movies': movieLibrary = vars.movies_folder folder = os.path.join(movieLibrary, fold) #Set the folder to the maindir/dir enc_name = dev.legal_filename( name) #Encode the filename to a legal filename xbmcvfs.mkdir( movieLibrary) #Create the maindirectory if it does not exist yet xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet if type == '' or type == 'tv': folder = os.path.join(folder, 'Season ' + season) #Set the folder to the maindir/dir xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet full_file_path = os.path.join(folder, enc_name) #Set the file to maindir/name/name dev.log('Downloading ' + videoid, 1) #vid = YDStreamExtractor.getVideoInfo(videoid,quality=1) path = os.path.join(movieLibrary, fold) #Set the folder to the maindir/dir #url = "https://www.youtube.com/watch?v=YKSU82afy1w" #ducktales intro to test url = "https://www.youtube.com/watch?v=" + videoid vid = YDStreamExtractor.getVideoInfo(url, quality=1) if vid == None: dev.log('Failed to retrieve video from url: ' + url) return False if settings.find('download_videos').text == '720p': dev.log('%%%%%%% QUALITY: 720p quality selected') format = 'bestvideo[height<=?720]+bestaudio/best[height<=?720]' elif settings.find('download_videos').text == '1080p': dev.log('%%%%%%% QUALITY: 1080p quality selected') format = 'bestvideo[height<=?1080]+bestaudio/best[height<=?1080]' else: dev.log('%%%%%%% QUALITY: best quality selected') format = 'bestvideo+bestaudio/best' ydl_opts = { 'format': format, 'logger': MyLogger(), 'progress_hooks': [my_hook], 'outtmpl': full_file_path + '.%(ext)s', #'-o' : enc_name+'.%(ext)s', } with youtube_dl.YoutubeDL(ydl_opts) as ydl: return ydl.download(['https://www.youtube.com/watch?v=' + videoid]) """
def fullInfo(videoId): fullUrl = "https://www.youtube.com/watch?v=" + videoId vid = YDStreamExtractor.getVideoInfo(fullUrl, quality=1) streamurl = vid.streamURL() title = vid.title description = vid.description thumb = vid.thumbnail return streamurl, title, description, thumb # def batchResolve(collection): # for video in collection.videoList: # thread = ResolveThread(video) # thread.start() # # # import threading # class ResolveThread(threading.Thread): # def __init__(self, video): # threading.Thread.__init__(self) # self.video = video # # def run(self): # vid = YDStreamExtractor.getVideoInfo(self.video.fullUrl(),quality=1)
def getExtURL(urlPage): print 'YoutubeDL decoding ' + urlPage vid = YDStreamExtractor.getVideoInfo(urlPage,quality=2) #quality is 0=SD, 1=720p, 2=1080p and is a maximum stream_url = vid.streamURL() #This is what Kodi (XBMC) will play return stream_url
def resolve(self, url): resolved = '' stream_url = '' item = None try: import urlresolver resolved = urlresolver.HostedMediaFile(url).resolve() if not resolved or resolved == False or len(resolved) < 1: resolved = urlresolver.resolve(url) if resolved is None or len(resolved) < 1: resolved = urlresolver.resolve(urlquick.unquote(url)) if len(resolved) > 1: return resolved except: resolved = '' try: import YDStreamExtractor info = YDStreamExtractor.getVideoInfo(url, resolve_redirects=True) resolved = info.streamURL() for s in info.streams(): try: stream_url = s['xbmc_url'].encode('utf-8', 'ignore') except: pass if len(stream_url) > 1: resolved = stream_url if len(resolved) > 1: return resolved except: resolved = None return resolved
def get_video_info(url): info = YDStreamExtractor.getVideoInfo(url) if hasattr(info, '_streams'): return info else: log_utils.log('Stream not available: |%s|' % url, log_utils.LOGERROR) kodi.notify(msg=kodi.i18n('stream_not_available'), sound=False) return None
def play_video(path): url = final_link vid = YDStreamExtractor.getVideoInfo(url, quality=1) play_item = xbmcgui.ListItem(path=path) stream_url = vid.streamURL() if stream_url: play_item.setPath(stream_url) xbmcplugin.setResolvedUrl(addon_handle, True, listitem=play_item)
def playvideo(url): debug(url) vid = YDStreamExtractor.getVideoInfo(url,quality=2) #quality is 0=SD, 1=720p, 2=1080p and is a maximum debug(vid) stream_url = vid.streamURL() stream_url=stream_url.split("|")[0] listitem = xbmcgui.ListItem(path=stream_url) addon_handle = int(sys.argv[1]) xbmcplugin.setResolvedUrl(addon_handle, True, listitem)
def downloadYoutubeVid(name, fold, videoid, settings, type='', season=None): #youtube-dl command to download best quality: -f bestvideo[ext!=webm]+bestaudio[ext!=webm]/best[ext!=webm] #YDStreamExtractor.disableDASHVideo(True) movieLibrary = vars.tv_folder #The path we should save in is the vars.tv_folder setting from the addon settings if type=='musicvideo': movieLibrary = vars.musicvideo_folder if type=='movies': movieLibrary = vars.movies_folder folder = os.path.join(movieLibrary, fold) #Set the folder to the maindir/dir enc_name = dev.legal_filename(name) #Encode the filename to a legal filename xbmcvfs.mkdir(movieLibrary) #Create the maindirectory if it does not exist yet xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet if type == '' or type == 'tv': folder = os.path.join(folder, 'Season '+season) #Set the folder to the maindir/dir xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet full_file_path = os.path.join(folder, enc_name) #Set the file to maindir/name/name dev.log('Downloading '+videoid, 1) #vid = YDStreamExtractor.getVideoInfo(videoid,quality=1) path = os.path.join(movieLibrary, fold) #Set the folder to the maindir/dir #url = "https://www.youtube.com/watch?v=YKSU82afy1w" #ducktales intro to test url = "https://www.youtube.com/watch?v="+videoid vid = YDStreamExtractor.getVideoInfo(url,quality=1) if vid == None: dev.log('Failed to retrieve video from url: '+url) return False if settings.find('download_videos').text == '720p': dev.log('%%%%%%% QUALITY: 720p quality selected') format = 'bestvideo[height<=?720]+bestaudio/best[height<=?720]' elif settings.find('download_videos').text == '1080p': dev.log('%%%%%%% QUALITY: 1080p quality selected') format = 'bestvideo[height<=?1080]+bestaudio/best[height<=?1080]' else: dev.log('%%%%%%% QUALITY: best quality selected') format = 'bestvideo+bestaudio/best' ydl_opts = { 'format': format, 'logger': MyLogger(), 'progress_hooks': [my_hook], 'outtmpl' : full_file_path+'.%(ext)s', #'-o' : enc_name+'.%(ext)s', } with youtube_dl.YoutubeDL(ydl_opts) as ydl: return ydl.download(['https://www.youtube.com/watch?v='+videoid]) """
def play(url): if url.find('linkOut') != -1: urlout = url.split('?id=')[-1] url = base64.b64decode(urlout) plugin.notify(msg=urlout, title=url) resolved = '' stream_url = '' item = None try: import urlresolver resolved = urlresolver.HostedMediaFile(url).resolve() if not resolved or resolved == False or len(resolved) < 1: resolved = urlresolver.resolve(url) if resolved is None or len(resolved) < 1: resolved = urlresolver.resolve(urllib.unquote(url)) if len(resolved) > 1: plugin.notify(msg="PLAY {0}".format(resolved.partition('.')[-1]), title="URLRESOLVER", delay=1000) plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) item.add_stream_info('video', stream_values={}) item.set_is_playable(True) plugin.play_video(item) return None except: resolved = '' plugin.notify(msg="FAILED {0}".format(url.partition('.')[-1]), title="URLRESOLVER", delay=1000) try: import YDStreamExtractor info = YDStreamExtractor.getVideoInfo(url, resolve_redirects=True) resolved = info.streamURL() for s in info.streams(): try: stream_url = s['xbmc_url'].encode('utf-8', 'ignore') xbmc.log(msg="**YOUTUBE-DL Stream found: {0}".format(stream_url)) except: pass if len(stream_url) > 1: resolved = stream_url if len(resolved) > 1: plugin.notify(msg="Playing: {0}".format(resolved.partition('.')[-1]), title="YOUTUBE-DL", delay=1000) plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) item.add_stream_info('video', stream_values={}) item.set_is_playable(True) plugin.play_video(item) return None except: plugin.notify(msg="Failed: {0}".format(resolved.partition('.')[-1]), title="YOUTUBE-DL", delay=1000) if len(resolved) > 1: plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) plugin.play_video(item) return None else: plugin.set_resolved_url(url) plugin.play_video(url) return None
def play(url): resolved = '' stream_url = '' item = None try: import urlresolver resolved = urlresolver.HostedMediaFile(url).resolve() if not resolved or resolved == False or len(resolved) < 1: resolved = urlresolver.resolve(url) if resolved is None or len(resolved) < 1: resolved = urlresolver.resolve(urllib.unquote(url)) if len(resolved) > 1: plugin.notify(msg="PLAY {0}".format(resolved.partition('.')[-1]), title="URLRESOLVER", delay=1000) plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) item.add_stream_info('video', stream_values={}) item.set_is_playable(True) return item except: resolved = '' plugin.notify(msg="FAILED {0}".format(url.partition('.')[-1]), title="URLRESOLVER", delay=1000) try: import YDStreamExtractor info = YDStreamExtractor.getVideoInfo(url, resolve_redirects=True) resolved = info.streamURL() for s in info.streams(): try: stream_url = s['xbmc_url'].encode('utf-8', 'ignore') xbmc.log(msg="**YOUTUBE-DL Stream found: {0}".format(stream_url)) except: pass if len(stream_url) > 1: resolved = stream_url if len(resolved) > 1: plugin.notify(msg="Playing: {0}".format(resolved.partition('.')[-1]), title="YOUTUBE-DL", delay=1000) plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) item.add_stream_info('video', stream_values={}) item.set_is_playable(True) return item except: plugin.notify(msg="Failed: {0}".format(resolved.partition('.')[-1]), title="YOUTUBE-DL", delay=1000) if len(resolved) > 1: plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) return item else: plugin.set_resolved_url(url) #url) #plugurl = 'plugin://plugin.video.live.streamspro/?url={0}'.format(urllib.quote_plus(url)) #item = ListItem.from_dict(path=plugurl) #item.add_stream_info('video', stream_values={}) #item.set_is_playable(True) #plugin.notify(msg="RESOLVE FAIL: {0}".format(url.split('.', 1)[-1]),title="Trying {0}".format(item.path.split('.', 1)[-1]), delay=2000) return None
def youtube_info_by_id(self, youtube_id): vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if not vid: return None, None listitem = xbmcgui.ListItem(label=vid.title, thumbnailImage=vid.thumbnail) listitem.setInfo(type='video', infoLabels={"genre": vid.sourceName, "plot": vid.description}) return vid.streamURL(), listitem
def playVideo(url): debug( "(playVideo) ------------------------------------------------ START = playVideo -----------------------------------------------" ) vid = YDStreamExtractor.getVideoInfo( url, quality=prefQUALITY) # quality is 0=SD, 1=720p, 2=1080p and is max stream_url = vid.streamURL() # This is what Kodi will play stream_url = stream_url.split('|')[0] xbmcplugin.setResolvedUrl(pluginhandle, True, xbmcgui.ListItem(path=stream_url))
def downloadyoutube(file, ffdir=""): debug("Start downloadyoutube") # if FFmpeg is defined use it also at youtube-dl if not ffdir == "": YDStreamExtractor.overrideParam('ffmpeg_location', ffdir) # download video YDStreamExtractor.overrideParam('preferedformat', "avi") vid = YDStreamExtractor.getVideoInfo(file, quality=2) with YDStreamUtils.DownloadProgress( ) as prog: # this creates a progress dialog interface ready to use try: YDStreamExtractor.setOutputCallback(prog) result = YDStreamExtractor.downloadVideo(vid, folder) if result: full_path_to_file = result.filepath elif result.status != 'canceled': error_message = result.message finally: YDStreamExtractor.setOutputCallback(None)
def youtube_info_by_id(self, youtube_id): vid = YDStreamExtractor.getVideoInfo(youtube_id, quality=1) if not vid: return None, None listitem = xbmcgui.ListItem(label=vid.title, thumbnailImage=vid.thumbnail) listitem.setInfo(type='video', infoLabels={ "genre": vid.sourceName, "plot": vid.description }) return vid.streamURL(), listitem
def start_download(): kb = xbmc.Keyboard('default', 'heading', False) kb.setDefault('') kb.setHeading(enter0) kb.setHiddenInput(False) kb.doModal() if (kb.isConfirmed()): try: url = kb.getText(kb) info = YDStreamExtractor.getVideoInfo(url) YDStreamExtractor.handleDownload(info, bg=True) except: xbmc.executebuiltin('Notification(%s, %s, %d, %s)' % (addonname, errorline2, time, infoicon)) start_menu() else: xbmc.executebuiltin('Notification(%s, %s, %d, %s)' % (addonname, errorline1, time, infoicon)) start_menu() xbmc.executebuiltin('xbmc.activatewindow(home)') sys.exit(0)
def play(url): if plugin.get_setting('debugon', converter=bool): web_pdb.set_trace() resolved = '' stream_url = '' item = None try: import urlresolver resolved = urlresolver.HostedMediaFile(url).resolve() if not resolved or resolved == False or len(resolved) < 1: resolved = urlresolver.resolve(url) if resolved is None or len(resolved) < 1: resolved = urlresolver.resolve(WebUtils.unescape(url)) if len(resolved) > 1: plugin.notify(msg="PLAY {0}".format(resolved.partition('.')[-1]), title="URLRESOLVER", delay=1000) plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) item.add_stream_info('video', stream_values={}) item.set_is_playable(True) return item except: resolved = '' plugin.notify(msg="FAILED {0}".format(url.partition('.')[-1]), title="URLRESOLVER", delay=1000) try: import YDStreamExtractor info = YDStreamExtractor.getVideoInfo(url, resolve_redirects=True) resolved = info.streamURL() for s in info.streams(): try: stream_url = s['xbmc_url'].encode('utf-8', 'ignore') xbmc.log(msg="**YOUTUBE-DL Stream found: {0}".format(stream_url)) except: pass if len(stream_url) > 1: resolved = stream_url if len(resolved) > 1: plugin.notify(msg="Playing: {0}".format(resolved.partition('.')[-1]), title="YOUTUBE-DL", delay=1000) plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) item.add_stream_info('video', stream_values={}) item.set_is_playable(True) return item except: plugin.notify(msg="Failed: {0}".format(resolved.partition('.')[-1]), title="YOUTUBE-DL", delay=1000) if len(resolved) > 1: plugin.set_resolved_url(resolved) item = ListItem.from_dict(path=resolved) return item else: plugin.set_resolved_url(url) # url) return None
def resolveURLFile(path): import YDStreamExtractor as StreamExtractor StreamExtractor.overrideParam('noplaylist', True) StreamExtractor.generateBlacklist(('.*:(?:user|channel|search)$', '(?i)generic.*')) import xbmcvfs f = xbmcvfs.File(path, 'r') try: url = f.read().strip() except: kodiutil.ERROR() return finally: f.close() vid = StreamExtractor.getVideoInfo(url) if not vid: return None return vid.streamURL()
def get_YTD(url): import YDStreamExtractor vid = YDStreamExtractor.getVideoInfo(url,resolve_redirects=True) dbg_log('- YTD: \n') if vid: dbg_log('- YTD: Try\n') stream_url = vid.streamURL() # stream_url = vid.streamURL().split('|')[0] dbg_log('- surl:'+ stream_url + '\n') else: dbg_log('- YTD: None\n') return None
def canHandle(data): if data.get('type') == 'link': url = data.get('url','') if StreamExtractor.mightHaveVideo(url): return 'video' mediaType = getURLMediaType(url) if mediaType: return mediaType return canPlayURL(url) and 'video' or None elif data.get('type') == 'file': fType = data.get('file_type','')[:5] if fType in ('image','video','audio'): return fType elif data.get('type') == 'note': return 'note' elif data.get('type') == 'list': return 'list' elif data.get('type') == 'address': return 'address' return None
def Playvid(url, name): import YDStreamExtractor vid = YDStreamExtractor.getVideoInfo(url,quality=1) stream_url = vid.streamURL() if stream_url: iconimage = xbmc.getInfoImage("ListItem.Thumb") listitem = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage) listitem.setInfo('video', {'Title': name, 'Genre': 'Sport'}) listitem.setProperty("IsPlayable","true") if int(sys.argv[1]) == -1: pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) pl.clear() pl.add(stream_url, listitem) xbmc.Player().play(pl) else: listitem.setPath(str(stream_url)) xbmcplugin.setResolvedUrl(utils.addon_handle, True, listitem)
def retrieveVideoInfo(video_id): video_info = VideoInfo() video_info.set_video_hosting_info(getVideoHostingInfo()) video_info.set_video_id(video_id) try: video_url = 'https://www.youtube.com/watch?v=' + video_id yd_video_info = YDStreamExtractor.getVideoInfo(video_url, quality=1) if yd_video_info is not None: video_info.set_video_name(yd_video_info.title) video_info.set_video_image(yd_video_info.thumbnail) video_info.add_video_link(VIDEO_QUAL_HD_720, yd_video_info.streamURL()) video_info.set_video_stopped(False) else: video_info.set_video_stopped(True) except Exception, e: Logger.logError(e) video_info.set_video_stopped(True)
def canHandle(data): if data.get("type") == "link": url = data.get("url", "") if StreamExtractor.mightHaveVideo(url): return "video" mediaType = getURLMediaType(url) if mediaType: return mediaType return canPlayURL(url) and "video" or None elif data.get("type") == "file": fType = data.get("file_type", "")[:5] if fType in ("image", "video", "audio"): return fType elif data.get("type") == "note": return "note" elif data.get("type") == "list": return "list" elif data.get("type") == "address": return "address" return None