Beispiel #1
0
 def getVideo(self, url):
     cacheresponse = self.cache.get(ADDON_NAME + '.getVideo, url = %s'%url)
     if not cacheresponse:
         info = getVideoInfo(url,QUALITY,True)
         if info is not None: info = info.streams()
         self.cache.set(ADDON_NAME + '.getVideo, url = %s'%url, json.dumps(info), expiration=datetime.timedelta(days=14))
     return json.loads(self.cache.get(ADDON_NAME + '.getVideo, url = %s'%url))
Beispiel #2
0
 def playVideo(self, name, url):
     log('playVideo')
     from YDStreamExtractor import getVideoInfo
     info = getVideoInfo(url, QUALITY, True)
     if info is None: return
     info = info.streams()
     plst = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
     plst.clear()
     for videos in info:
         vidIDX = videos['idx']
         url = videos['xbmc_url']
         liz = xbmcgui.ListItem(videos['title'], path=url)
         if 'm3u8' in url.lower():
             liz.setProperty('inputstreamaddon', 'inputstream.adaptive')
             liz.setProperty('inputstream.adaptive.manifest_type', 'hls')
         if 'subtitles' in videos['ytdl_format']:
             liz.setSubtitles([
                 x['url']
                 for x in videos['ytdl_format']['subtitles'].get('en', '')
                 if 'url' in x
             ])
         plst.add(url, liz, vidIDX)
         if vidIDX == 0:
             xbmcplugin.setResolvedUrl(int(self.sysARG[1]), True, liz)
     plst.unshuffle()
Beispiel #3
0
 def playVideo(self, name, url, liz=None):
     log('playVideo')
     info = getVideoInfo(url, QUALITY, True)
     if info is None: return
     info = info.streams()
     if len(info) > 1:
         if PTVL_RUNNING:
             return xbmcgui.Dialog().notification(ADDON_NAME,
                                                  LANGUAGE(30007), ICON,
                                                  4000)
         info = sorted(info, key=lambda x: x['idx'])
         plst = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
         plst.clear()
         xbmc.sleep(200)
         for videos in info:
             vidIDX = videos['idx']
             url = videos['xbmc_url']
             liz = xbmcgui.ListItem(videos['title'], path=url)
             try:
                 if 'subtitles' in videos['ytdl_format']:
                     liz.setSubtitles([
                         x['url']
                         for x in videos['ytdl_format']['subtitles'].get(
                             'en', '') if 'url' in x
                     ])
             except:
                 pass
             plst.add(url, liz, vidIDX)
             if vidIDX == 0:
                 xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
         plst.unshuffle()
     else:
         liz = xbmcgui.ListItem(info[0]['title'], path=info[0]['xbmc_url'])
         xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
Beispiel #4
0
def play_video(eid, server):
    html = fetch_html('/vids/play/%s/%s' % (eid, server))
    urls = joonmedia.extract_video_link(html)
    if len(urls) > 0:
        # select first video
        plugin.log.debug(urls[0])
        quality = plugin.get_setting('qualityPref', int)
        info = getVideoInfo(urls[0], quality=quality, resolve_redirects=True)
        if info is None:
            plugin.log.warning('Fail to extract')
            return None
        streams = info.streams()
        plugin.log.debug("num of streams: %d" % len(streams))

        from xbmcswift2 import xbmc, xbmcgui
        pl = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
        pl.clear()
        for stream in streams:
            li = xbmcgui.ListItem(stream['title'], iconImage="DefaultVideo.png")
            li.setInfo( 'video', { "Title": stream['title'] } )
            pl.add(stream['xbmc_url'], li)
        xbmc.Player().play(pl)
    else:
        plugin.log.warning('Unsupported')
    return plugin.finish(None, succeeded=False) # immediate return
Beispiel #5
0
 def playVideo(self, name, url, liz=None):
     log('playVideo')
     if PTVL_RUNNING: return
     info = getVideoInfo(url, QUALITY, True)
     if info is None: return
     info = info.streams()
     info = sorted(info, key=lambda x: x['idx'])
     plst = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
     plst.clear()
     xbmc.sleep(200)
     idxLST = []
     for videos in info:
         vidIDX = videos['idx']
         url = videos['xbmc_url']
         liz = xbmcgui.ListItem(videos['title'], path=url)
         if 'subtitles' in videos['ytdl_format']:
             liz.setSubtitles([
                 x['url']
                 for x in videos['ytdl_format']['subtitles'].get('en', '')
                 if 'url' in x
             ])
         plst.add(url, liz, vidIDX)
         if vidIDX == 0:
             xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
     plst.unshuffle()
Beispiel #6
0
 def resolveURL(self, name, url):
     try:
         data = json.loads(re.findall('"drupal-settings-json">(.+?)</script>',self.openURL(url), flags=re.DOTALL)[0])['dtv_video']
         provider = data['provider']
         log('resolveURL, provider = ' + provider)
         url = re.findall('src="(.+?)"',(data['player_code']), flags=re.DOTALL)[0].split('?')[0]
         if provider == 'youtube':
             if len(re.findall('http[s]?://www.youtube.com/embed', url)) > 0: url = YTURL + url.split('/embed/')[1]
             elif len(re.findall('http[s]?://www.youtube.com/watch', url)) > 0: url = YTURL + url.split('/watch?v=')[1]
             elif len(re.findall('http[s]?://youtu.be/', url)) > 0: url = YTURL + url.split('/youtu.be/')[1]
         elif provider == 'vimeo':
             if len(re.findall('http[s]?://vimeo.com/', url)) > 0: url = VMURL + url.split('/vimeo.com/')[1]
         else: raise Exception('resolveURL, unknown provider; data =' + json.dumps(data))
         log('resolveURL, url = ' + url)
         return xbmcgui.ListItem(name, path=url)
     except Exception as e: log("resolveURL Failed! " + str(e), xbmc.LOGERROR)
     if isUWP(): return ''
     from YDStreamExtractor import getVideoInfo
     info = getVideoInfo(url,QUALITY,True)
     if info is None: return
     info = info.streams()
     url  = info[0]['xbmc_url']
     liz  = xbmcgui.ListItem(name, path=url)
     try: 
         if 'subtitles' in info[0]['ytdl_format']: liz.setSubtitles([x['url'] for x in info[0]['ytdl_format']['subtitles'].get('en','') if 'url' in x])
     except: pass
     return liz
Beispiel #7
0
def play_video(url):
    if url_root not in url:
        url = url_root + url
    url = kshows.extract_video_url(url)
    info = None

    if not url.startswith("plugin://"):
        info = getVideoInfo(url, quality=3, resolve_redirects=True)
    if info:
        streams = info.streams()
        plugin.log.debug("num of streams: %d" % len(streams))
        from xbmcswift2 import xbmc, xbmcgui
        pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
        pl.clear()
        for stream in streams:
            li = xbmcgui.ListItem(stream['title'],
                                  iconImage="DefaultVideo.png")
            li.setInfo('video', {"Title": stream['title']})
            pl.add(stream['xbmc_url'], li)
        xbmc.Player().play(pl)
    else:
        plugin.log.warning('Fallback to ' + url)
        plugin.play_video({'path': url, 'is_playable': True})
    return plugin.finish(None,
                         succeeded=False)  # trick not to enter directory mode
Beispiel #8
0
 def playVideo(self, name, url, liz=None):
     log('playVideo')
     info = getVideoInfo(url,QUALITY,True)
     if info is None: return
     info = info.streams()
     url  = info[0]['xbmc_url']
     liz  = xbmcgui.ListItem(name, path=url)
     if 'subtitles' in info[0]['ytdl_format']: liz.setSubtitles([x['url'] for x in info[0]['ytdl_format']['subtitles'].get('en','') if 'url' in x])
     xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
Beispiel #9
0
 def playVideo(self, name, url, liz=None):
     log('playVideo')
     info = getVideoInfo(url,QUALITY,True)
     if info is None: return
     info = info.streams()
     url  = info[0]['xbmc_url']
     liz  = xbmcgui.ListItem(name, path=url)
     if 'subtitles' in info[0]['ytdl_format']: liz.setSubtitles([x['url'] for x in info[0]['ytdl_format']['subtitles'].get('en','') if 'url' in x])
     xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
Beispiel #10
0
def download(urlvideo):
    try:
        from YDStreamExtractor import getVideoInfo
        from YDStreamExtractor import handleDownload
        info = getVideoInfo(urlvideo, resolve_redirects=True)
        dlpath = plugin.get_setting('downloadpath')
        if not os.path.exists(dlpath):
            dlpath = xbmc.translatePath("home://")
        handleDownload(info, bg=True, path=dlpath)
    except:
        plugin.notify(urlvideo, "Download Failed")
Beispiel #11
0
 def playVideo(self, name, url):
     log('playVideo')
     info = getVideoInfo(url,QUALITY,True)
     if info is None: return
     info = info.streams()
     url  = info[0]['xbmc_url']
     liz  = xbmcgui.ListItem(name, path=url)
     if 'm3u8' in url.lower():
         liz.setProperty('inputstreamaddon','inputstream.adaptive')
         liz.setProperty('inputstream.adaptive.manifest_type','hls')
     if 'subtitles' in info[0]['ytdl_format']: liz.setSubtitles([x['url'] for x in info[0]['ytdl_format']['subtitles'].get('en','') if 'url' in x])
     xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
Beispiel #12
0
def play(vtitle="", vurl=""):
    playurl = ''
    if vurl is None or vurl == "":
        return []
    if vurl.find("%20") != -1 or vurl.find("+") != -1:
        vurl = Unquote(vurl)
    plugin.notify(msg=vurl)
    try:
        from YDStreamExtractor import getVideoInfo
        from YDStreamExtractor import handleDownload
        info = getVideoInfo(vurl, resolve_redirects=True)
        playurl = info.streamURL()
        plugin.log.info(msg="** PLAY VIDEO AT {0} **".format(vurl))
        plugin.log.info(msg=playurl)
        plugin.log.info(msg=str(repr(info)))
    except:
        plugin.notify(vurl, "Play Failed")
    if len(playurl) < 2:
        try:
            import urlresolver
            resolved = urlresolver.HostedMediaFile(vurl).resolve()
            if not resolved or resolved == False or len(resolved) < 1:
                resolved = urlresolver.resolve(vurl)
                if resolved is None or len(resolved) < 1:
                    resolved = urlresolver.resolve(Unquote(vurl))
            if len(resolved) > 1:
                playurl = resolved
        except:
            plugin.log.error(msg="** URL Resolver also failed **")
        playurl = vurl
        msg = "** Failed to resolve video at {0} to playable stream. **".format(
            vurl)
        plugin.log.error(msg=msg)
        plugin.notify(msg=msg, title="Play Failed")
        playurl = "plugin://plugin.video.wsonline/play/" + Quote(vurl)
        plugin.set_resolved_url(None)
        return None
    pitem = plugin._listitemify(item={
        'label': vtitle,
        'label2': vurl,
        'path': playurl
    })
    pitem.playable = True
    pitem.set_info(info_labels={
        'Title': vtitle,
        'Plot': vurl + playurl
    },
                   info_type='video')
    pitem.add_stream_info('video', stream_values={})
    pitem.is_folder = False
    plugin.set_resolved_url(item=pitem)
    return pitem
def single_YD(page_data):
    info = getVideoInfo(page_data,quality=2,resolve_redirects=True)
    if info is None:
        print 'Fail to extract'
        return None    
    
    else:
        for s in info.streams():
            try:
                stream_url = s['xbmc_url'].encode('utf-8','ignore')
                return stream_url
            except Exception:
                return None             
Beispiel #14
0
 def resolve_url(self, raw_url):
     from YDStreamExtractor import getVideoInfo
     info = getVideoInfo(raw_url, 3, True)
     if info is None: return ''
     info = info.streams()
     if len(info) > 1:
         streams = []
         info = sorted(info, key=lambda x: x['idx'])
         for video in info:
             streams.append(video['xbmc_url'])
         return 'playlist://' + str(streams)
     else:
         return info[0]['xbmc_url']
     return ''
Beispiel #15
0
 def playVideo(self, name, url):
     log('playVideo, name = ' + name)
     if url.endswith('m3u8'): 
         liz = xbmcgui.ListItem(name, path=url)
         liz.setProperty('inputstreamaddon','inputstream.adaptive')
         liz.setProperty('inputstream.adaptive.manifest_type','hls') 
     else:
         info = getVideoInfo(url,QUALITY,True)
         if info is None: return
         info = info.streams()
         url  = info[0]['xbmc_url']
         liz  = xbmcgui.ListItem(name, path=url)
         if 'subtitles' in info[0]['ytdl_format']: liz.setSubtitles([x['url'] for x in info[0]['ytdl_format']['subtitles'].get('en','') if 'url' in x])  
     xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
Beispiel #16
0
    def extract_source(self, url, quality=None):
        """
        Extract video url using YoutubeDL.

        The YoutubeDL module provides access to youtube-dl video stream extractor
        witch gives access to hundreds of sites.

        Quality is 0=SD, 1=720p, 2=1080p, 3=Highest Available

        .. seealso:: https://rg3.github.io/youtube-dl/supportedsites.html

        :param url: Url to fetch video for.
        :type url: str or unicode
        :param int quality: [opt] Override youtubeDL's quality setting.

        :returns: The extracted video url
        :rtype: str

        .. note::

            Unfortunately the kodi YoutubeDL module is python2 only.
            Hopefully it will be ported to python3 when kodi gets upgraded.
        """
        def ytdl_logger(record):
            if record.startswith("ERROR:"):
                # Save error rocord for raising later, outside of the callback
                # YoutubeDL ignores errors inside callbacks
                stored_errors.append(record[7:])

            self.log(record)
            return True

        # Setup YoutubeDL module
        from YDStreamExtractor import getVideoInfo, setOutputCallback
        setOutputCallback(ytdl_logger)
        stored_errors = []

        # Atempt to extract video source
        video_info = getVideoInfo(url, quality)
        if video_info:
            if video_info.hasMultipleStreams():
                # More than one stream found, Ask the user to select a stream
                return self.__source_selection(video_info)
            else:
                return video_info.streamURL()

        # Raise any stored errors
        elif stored_errors:
            raise RuntimeError(stored_errors[0])
Beispiel #17
0
def download(params):
    vurl = ''
    if params.video is not None:
        vurl = params.video
    else:
        return None
    try:
        from YDStreamExtractor import getVideoInfo
        from YDStreamExtractor import handleDownload
        info = getVideoInfo(vurl, resolve_redirects=True)
        dlpath = plugin.get_setting('downloadpath')
        if not path.exists(dlpath):
            dlpath = xbmc.translatePath("home://")
        handleDownload(info, bg=True, path=dlpath)
    except:
        showMessage(msg=vurl, header="Download Failed")
Beispiel #18
0
 def playVideo(self, name, url, liz=None):
     log('playVideo')
     if PTVL_RUNNING: return 
     info = getVideoInfo(url,QUALITY,True)
     if info is None: return
     info = info.streams()
     info = sorted(info, key=lambda x: x['idx'])
     plst = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
     plst.clear()
     for videos in info:
         vidIDX = videos['idx']
         url = videos['xbmc_url']
         liz = xbmcgui.ListItem(videos['title'], path=url)
         if 'subtitles' in videos['ytdl_format']: liz.setSubtitles([x['url'] for x in videos['ytdl_format']['subtitles'].get('en','') if 'url' in x])
         plst.add(url, liz, vidIDX)
         if vidIDX == 0: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz) 
     plst.unshuffle()
Beispiel #19
0
    def resolveURL(self, name, url):
        log('resolveURL, url = %s' % url)
        soup = BeautifulSoup(self.openURL(url), "html.parser")
        vid_url = url
        for element in soup('iframe'):
            video = element.get('data-src', '')
            if video:
                vid_url = video
                break
        if vid_url == url:
            for element in soup('embed'):
                video = element.get('data-src', '')
                if video:
                    vid_url = video
                    break
        print vid_url

        if 'youtube' in vid_url:
            yt_id = re.search('embed\/([-\w]+)', vid_url).group(1)
            if not yt_id:
                yt_id = re.search('youtube.com\/watch\?v=([-\w]+)',
                                  vid_url).group(1)
            elif not yt_id:
                yt_id = re.search('youtube.be\/watch\?v=([-\w]+)',
                                  vid_url).group(1)
            if yt_id: vid_url = YTURL % (yt_id)

        if vid_url == url and not isUWP():
            from YDStreamExtractor import getVideoInfo
            info = getVideoInfo(url, QUALITY, True)
            if info is None: return
            info = info.streams()
            url = info[0]['xbmc_url']
        else:
            url = vid_url
        liz = xbmcgui.ListItem(name, path=url)
        try:
            if 'subtitles' in info[0]['ytdl_format']:
                liz.setSubtitles([
                    x['url']
                    for x in info[0]['ytdl_format']['subtitles'].get('en', '')
                    if 'url' in x
                ])
        except:
            pass
        return liz
Beispiel #20
0
 def resolveURL(self, provider, url):
     log('resolveURL, provider = ' + str(provider) + ', url = ' + url)
     if provider == 'jwplatform' or 'm3u8' in url.lower() or url is None: return url
     elif provider == 'youtube':
         url = url.replace('feature=player_embedded&','')
         if len(re.findall('http[s]?://www.youtube.com/watch', url)) > 0: return YTURL + url.split('/watch?v=')[1]
         elif len(re.findall('http[s]?://youtu.be/', url)) > 0: return YTURL + url.split('/youtu.be/')[1]
     elif provider == 'vimeo':
         if len(re.findall('http[s]?://vimeo.com/', url)) > 0: return VMURL + url.split('/vimeo.com/')[1]
     else:
         info = None
         if isUWP() == False: 
             from YDStreamExtractor import getVideoInfo
             info = getVideoInfo(url,3,True)
         if info is None: return YTURL + 'W6FjQgmtt0k'
         info = info.streams()
         return info[0]['xbmc_url']
Beispiel #21
0
 def resolveURL(self, provider, url):
     log('resolveURL, provider = ' + str(provider) + ', url = ' + url)
     if provider == 'jwplatform' or 'm3u8' in url.lower() or url is None: return url
     elif provider == 'youtube':
         url = url.replace('feature=player_embedded&','')
         if len(re.findall('http[s]?://www.youtube.com/watch', url)) > 0: return YTURL + url.split('/watch?v=')[1]
         elif len(re.findall('http[s]?://youtu.be/', url)) > 0: return YTURL + url.split('/youtu.be/')[1]
     elif provider == 'vimeo':
         if len(re.findall('http[s]?://vimeo.com/', url)) > 0: return VMURL + url.split('/vimeo.com/')[1]
     else:
         info = None
         if isUWP() == False: 
             from YDStreamExtractor import getVideoInfo
             info = getVideoInfo(url,3,True)
         if info is None: return YTURL + 'W6FjQgmtt0k'
         info = info.streams()
         return info[0]['xbmc_url']
Beispiel #22
0
 def playVideo(self, name, url, liz=None):
     log('playVideo')
     subs = []
     info = getVideoInfo(url, QUALITY, True)
     if info is None and not url.endswith('m3u8'):
         url = self.resolveURL(url)
     else:
         info = info.streams()
         url = info[0]['xbmc_url']
         if 'subtitles' in info[0]['ytdl_format']:
             subs = ([
                 x['url']
                 for x in info[0]['ytdl_format']['subtitles'].get('en', '')
                 if 'url' in x
             ])
     liz = xbmcgui.ListItem(name, path=url)
     liz.setSubtitles(subs)
     xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
Beispiel #23
0
 def playVideo(self, name, url):
     log('playVideo')
     info = getVideoInfo(url, QUALITY, True)
     if info is None: return
     info = info.streams()
     url = info[0]['xbmc_url']
     liz = xbmcgui.ListItem(name, path=url)
     if 'm3u8' in url.lower() and inputstreamhelper.Helper(
             'hls').check_inputstream() and not DEBUG:
         liz.setProperty('inputstreamaddon', 'inputstream.adaptive')
         liz.setProperty('inputstream.adaptive.manifest_type', 'hls')
     if 'subtitles' in info[0]['ytdl_format']:
         liz.setSubtitles([
             x['url']
             for x in info[0]['ytdl_format']['subtitles'].get('en', '')
             if 'url' in x
         ])
     xbmcplugin.setResolvedUrl(int(self.sysARG[1]), True, liz)
Beispiel #24
0
def download(vurl=None):
    if vurl is None:
        return []
    if vurl.find("%20") != -1 or vurl.find("+") != -1:
        vurl = Unquote(vurl)
    try:
        from YDStreamExtractor import getVideoInfo
        from YDStreamExtractor import handleDownload
        info = getVideoInfo(vurl, resolve_redirects=True)
        playurl = info.streamURL
        dlpath = plugin.get_setting('downloadPath')
        if not os.path.exists(dlpath):
            dlpath = xbmc.translatePath("home://")
        handleDownload(info, bg=True, path=dlpath)
        plugin.log.info(msg="** DOWNLOAD VIDEO AT {0} **".format(vurl))
        plugin.log.info(msg=playurl)
        plugin.log.info(msg=str(repr(info)))
    except:
        plugin.notify(vurl, "Download Failed")
Beispiel #25
0
def download(vurl=None):
    if vurl is None:
        return []
    if vurl.find("%20") != -1 or vurl.find("+") != -1:
        vurl = Unquote(vurl)
    try:
        from YDStreamExtractor import getVideoInfo
        from YDStreamExtractor import handleDownload
        info = getVideoInfo(vurl, resolve_redirects=True)
        playurl = info.streamURL
        dlpath = plugin.get_setting('downloadPath')
        if not os.path.exists(dlpath):
            dlpath = xbmc.translatePath("home://")
        handleDownload(info, bg=True, path=dlpath)
        plugin.log.info(msg="** DOWNLOAD VIDEO AT {0} **".format(vurl))
        plugin.log.info(msg=playurl)
        plugin.log.info(msg=str(repr(info)))
    except:
        plugin.notify(vurl, "Download Failed")
Beispiel #26
0
def play(vtitle="", vurl=""):
    playurl = ''
    if vurl is None or vurl == "":
        return []
    if vurl.find("%20") != -1 or vurl.find("+") != -1:
        vurl = Unquote(vurl)
    plugin.notify(msg=vurl)
    try:
        from YDStreamExtractor import getVideoInfo
        from YDStreamExtractor import handleDownload
        info = getVideoInfo(vurl, resolve_redirects=True)
        playurl = info.streamURL()
        plugin.log.info(msg="** PLAY VIDEO AT {0} **".format(vurl))
        plugin.log.info(msg=playurl)
        plugin.log.info(msg=str(repr(info)))
    except:
        plugin.notify(vurl, "Play Failed")
    if len(playurl) < 2:
        try:
            import urlresolver
            resolved = urlresolver.HostedMediaFile(vurl).resolve()
            if not resolved or resolved == False or len(resolved) < 1:
                resolved = urlresolver.resolve(vurl)
                if resolved is None or len(resolved) < 1:
                    resolved = urlresolver.resolve(Unquote(vurl))
            if len(resolved) > 1:
                playurl = resolved
        except:
            plugin.log.error(msg="** URL Resolver also failed **")
        playurl = vurl
        msg = "** Failed to resolve video at {0} to playable stream. **".format(vurl)
        plugin.log.error(msg=msg)
        plugin.notify(msg=msg, title="Play Failed")
        playurl = "plugin://plugin.video.wsonline/play/" + Quote(vurl)
        plugin.set_resolved_url(None)
        return None
    pitem = plugin._listitemify(item={'label': vtitle, 'label2': vurl, 'path': playurl})
    pitem.playable = True
    pitem.set_info(info_labels={'Title': vtitle, 'Plot': vurl + playurl}, info_type='video')
    pitem.add_stream_info('video', stream_values={})
    pitem.is_folder = False
    plugin.set_resolved_url(item=pitem)
    return pitem
Beispiel #27
0
def play_video(url):
    plugin.log.debug(url)
    quality = plugin.get_setting('qualityPref', int)
    info = getVideoInfo(url, quality=quality, resolve_redirects=True)
    if info:
        streams = info.streams()
        plugin.log.debug("num of streams: %d" % len(streams))
        from xbmcswift2 import xbmc, xbmcgui
        pl = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
        pl.clear()
        for stream in streams:
            li = xbmcgui.ListItem(stream['title'], iconImage="DefaultVideo.png")
            li.setInfo( 'video', { "Title": stream['title'] } )
            pl.add(stream['xbmc_url'], li)
        xbmc.Player().play(pl)
    else:
        plugin.log.warning('Fail to extract')
        plugin.play_video({'path':url, 'is_playable':True})
    return plugin.finish(None, succeeded=False)
Beispiel #28
0
def single_YD(url, download=False, dl_info=False, audio=False):
    if dl_info:
        handleDownload(dl_info, bg=True)
        return
    else:
        info = getVideoInfo(url, quality=3, resolve_redirects=True)
    if info is None:
        print 'Fail to extract'
        return None
    elif info and download:
        if audio:
            try:
                for s in info.streams():
                    print 'len(s[', len(s['ytdl_format']['formats'])
                    for i in range(len(s['ytdl_format']['formats'])):
                        if s['ytdl_format']['formats'][i][
                                'format_id'] == '140':
                            print 'm4a found'
                            audio_url = s['ytdl_format']['formats'][i][
                                'url'].encode('utf-8', 'ignore')
                            title = s['title'].encode('utf-8', 'ignore')
                            info = {
                                'url': audio_url,
                                'title': title,
                                'media_type': 'audio'
                            }
                            break

            except Exception:
                print 'audio download failed'
                return

        handleDownload(info, bg=True)
    else:

        for s in info.streams():
            try:
                stream_url = s['xbmc_url'].encode('utf-8', 'ignore')
                print stream_url
                return stream_url
            except Exception:
                return None
Beispiel #29
0
def single_YD(url, download=False, dl_info=False):
    if dl_info:
        handleDownload(dl_info, bg=True)
        return
    else:
        info = getVideoInfo(url, quality=3, resolve_redirects=True)
    if info is None:
        print 'Fail to extract'
        return None
    elif info and download:  ##handleDownload(info,duration=None,bg=False):
        handleDownload(info, bg=True)
    else:

        for s in info.streams():
            try:
                stream_url = s['xbmc_url'].encode('utf-8', 'ignore')
                print stream_url
                return stream_url
            except Exception:
                return None
def single_YD(url, download=False, dl_info=False):
    if dl_info:
        handleDownload(dl_info, bg=True)
        return
    else:
        info = getVideoInfo(url, quality=3, resolve_redirects=True)
    if info is None:
        print "Fail to extract"
        return None
    elif info and download:  ##handleDownload(info,duration=None,bg=False):
        handleDownload(info, bg=True)
    else:

        for s in info.streams():
            try:
                stream_url = s["xbmc_url"].encode("utf-8", "ignore")
                print stream_url
                return stream_url
            except Exception:
                return None
Beispiel #31
0
def play_video(url):
    plugin.log.debug(url)
    quality = plugin.get_setting('qualityPref', int)
    info = getVideoInfo(url, quality=quality, resolve_redirects=True)
    if info:
        streams = info.streams()
        plugin.log.debug("num of streams: %d" % len(streams))
        from xbmcswift2 import xbmc, xbmcgui
        pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
        pl.clear()
        for stream in streams:
            li = xbmcgui.ListItem(stream['title'],
                                  iconImage="DefaultVideo.png")
            li.setInfo('video', {"Title": stream['title']})
            pl.add(stream['xbmc_url'], li)
        xbmc.Player().play(pl)
    else:
        plugin.log.warning('Fail to extract')
        plugin.play_video({'path': url, 'is_playable': True})
    return plugin.finish(None, succeeded=False)
Beispiel #32
0
def download(params):
    try:
        urlvideo = params.vidurl
        plugin.log(message=str("** download: " + str(repr(params))), level=xbmc.LOGINFO) 
        try:
            import YDStreamExtractor
            from YDStreamExtractor import getVideoInfo
            from YDStreamExtractor import handleDownload
        except:
            notify("Couldn't load YouTubeDL Addon")
        info = getVideoInfo(urlvideo, resolve_redirects=True)
        dlpath = plugin.get_setting('downloadpath')
        if not os.path.exists(dlpath):
            dlpath = xbmc.translatePath("home://")
        handleDownload(info, bg=True, path=dlpath)
    except:
        if urlvideo is not None:
            notify("Failed " + urlvideo)
        else:
            notify("No video URL was found to download")
    return None
Beispiel #33
0
def download(params):
    try:
        urlvideo = params.vidurl
        plugin.log(message=str("** download: " + str(repr(params))), level=xbmc.LOGINFO) 
        try:
            import YDStreamExtractor
            from YDStreamExtractor import getVideoInfo
            from YDStreamExtractor import handleDownload
        except:
            notify("Couldn't load YouTubeDL Addon")
        info = getVideoInfo(urlvideo, resolve_redirects=True)
        dlpath = plugin.get_setting('downloadpath')
        if not os.path.exists(dlpath):
            dlpath = xbmc.translatePath("home://")
        handleDownload(info, bg=True, path=dlpath)
    except:
        if urlvideo is not None:
            notify("Failed " + urlvideo)
        else:
            notify("No video URL was found to download")
    return None
Beispiel #34
0
def download(params):
    vurl = ''
    allok = False
    if params.video is not None:
        vurl = params.video
    else:
        return None
    try:
        from YDStreamExtractor import getVideoInfo
        from YDStreamExtractor import handleDownload
        info = getVideoInfo(vurl, resolve_redirects=True)
        dlpath = plugin.get_setting('downloadpath')
        if not path.exists(dlpath):
            dlpath = xbmc.translatePath("home://")
        handleDownload(info, bg=True, path=dlpath)
        allok = True
    except:
        allok = False
        xbmc.executebuiltin('Notification({0},{1})'.format(
            "FAILED to Download", vurl))
    if allok:
        xbmc.executebuiltin('Notification({0},{1})'.format(
            "OK! Download Started", vurl))
Beispiel #35
0
 def playVideo(self, name, url, liz=None):
     log('playVideo')
     info = getVideoInfo(url,QUALITY,True)
     if info is None: return
     info = info.streams()
     if len(info) > 1:
         if PTVL_RUNNING: return xbmcgui.Dialog().notification(ADDON_NAME, LANGUAGE(30007), ICON, 4000)
         info = sorted(info, key=lambda x: x['idx'])
         plst = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
         plst.clear()
         xbmc.sleep(200)
         for videos in info:
             vidIDX = videos['idx']
             url = videos['xbmc_url']
             liz = xbmcgui.ListItem(videos['title'], path=url)
             try: 
                 if 'subtitles' in videos['ytdl_format']: liz.setSubtitles([x['url'] for x in videos['ytdl_format']['subtitles'].get('en','') if 'url' in x])
             except: pass
             plst.add(url, liz, vidIDX)
             if vidIDX == 0: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz) 
         plst.unshuffle()
     else:
         liz = xbmcgui.ListItem(info[0]['title'], path=info[0]['xbmc_url'])
         xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz) 
Beispiel #36
0
def single_YD(url, download=False, dl_info=False, audio=False):
    if dl_info:
        handleDownload(dl_info, bg=True)
        return
    else:
        info = getVideoInfo(url, quality=3, resolve_redirects=True)
    if info is None:
        print "Fail to extract"
        return None
    elif info and download:
        if audio:
            try:
                for s in info.streams():
                    print "len(s[", len(s["ytdl_format"]["formats"])
                    for i in range(len(s["ytdl_format"]["formats"])):
                        if s["ytdl_format"]["formats"][i]["format_id"] == "140":
                            print "m4a found"
                            audio_url = s["ytdl_format"]["formats"][i]["url"].encode("utf-8", "ignore")
                            title = s["title"].encode("utf-8", "ignore")
                            info = {"url": audio_url, "title": title, "media_type": "audio"}
                            break

            except Exception:
                print "audio download failed"
                return

        handleDownload(info, bg=True)
    else:

        for s in info.streams():
            try:
                stream_url = s["xbmc_url"].encode("utf-8", "ignore")
                print stream_url
                return stream_url
            except Exception:
                return None
Beispiel #37
0
def single_YD(url,download=False,dl_info=False,audio=False):
    if dl_info:
        handleDownload(dl_info,bg=True)
        return
    else:
        info = getVideoInfo(url,quality=3,resolve_redirects=True)
    if info is None:
        print 'Fail to extract'
        return None    
    elif info and download : 
        if audio:
                try:
                    for s in info.streams():
                        print 'len(s[',len(s['ytdl_format']['formats'])
                        for i in range(len(s['ytdl_format']['formats'])):
                            if s['ytdl_format']['formats'][i]['format_id'] == '140':
                                print 'm4a found'
                                audio_url = s['ytdl_format']['formats'][i]['url'].encode('utf-8','ignore')                
                                title = s['title'].encode('utf-8','ignore')
                                info = {'url':audio_url,'title':title,'media_type':'audio'}
                                break
        
                except Exception:
                    print 'audio download failed'
                    return        
        
        handleDownload(info,bg=True)
    else:
    
        for s in info.streams():
            try:
                stream_url = s['xbmc_url'].encode('utf-8','ignore')
                print stream_url
                return stream_url
            except Exception:
                return None 
Beispiel #38
0
 def resolveURL(self, url):
     log('resolveURL')
     return getVideoInfo(url, QUALITY, True).streams()
Beispiel #39
0
# -- coding utf-8 --
import xbmc,xbmcgui
try
    from YDStreamExtractor import getVideoInfo
    from YDStreamExtractor import handleDownload
    
except Exception
    print 'importing Error. You need youtubedl module which is in official xbmc.org'
    xbmc.executebuiltin(XBMC.Notification(LiveStreamsPro,Please [COLOR yellow]install Youtube-dl[COLOR] module ,10000,))
    
def single_YD(url,download=False,dl_info=False,audio=False)
    if dl_info
        handleDownload(dl_info,bg=True)
        return
    else
        info = getVideoInfo(url,quality=3,resolve_redirects=True)
    if info is None
        print 'Fail to extract'
        return None    
    elif info and download  
        if audio
                try
                    for s in info.streams()
                        print 'len(s[',len(s['ytdl_format']['formats'])
                        for i in range(len(s['ytdl_format']['formats']))
                            if s['ytdl_format']['formats'][i]['format_id'] == '140'
                                print 'm4a found'
                                audio_url = s['ytdl_format']['formats'][i]['url'].encode('utf-8','ignore')                
                                title = s['title'].encode('utf-8','ignore')
                                info = {'url'audio_url,'title'title,'media_type''audio'}
                                break
    def extract_source(self, url, quality=None, **params):
        """
        Extract video url using YoutubeDL.

        YoutubeDL provides access to hundreds of sites.

        Quality options are.
            * 0 = SD,
            * 1 = 720p,
            * 2 = 1080p,
            * 3 = Highest Available

        :param url: Url of the video source to extract the playable video from.
        :type url: str or unicode
        :param int quality: [opt] Override youtubeDL's quality setting.
        :param params: Optional Keyword arguments of youtube_dl parameters.

        :returns: The playable video url
        :rtype: str

        .. seealso::

            The list of supported sites can be found at:

            https://rg3.github.io/youtube-dl/supportedsites.html

        .. seealso::

            The list of available parameters can be found at.

            https://github.com/rg3/youtube-dl#options

        .. note::

            Unfortunately the kodi Youtube-DL module is python2 only.
            It should be ported to python3 when kodi switches to python 3 for version 19.
        """
        def ytdl_logger(record):
            if record.startswith("ERROR:"):
                # Save error rocord for raising later, outside of the callback
                # YoutubeDL ignores errors inside callbacks
                stored_errors.append("Youtube-DL: " + record[7:])

            self.log(record)
            return True

        # Setup YoutubeDL module
        from YDStreamExtractor import getVideoInfo, setOutputCallback, overrideParam
        setOutputCallback(ytdl_logger)
        stored_errors = []

        # Override youtube_dl parmeters
        for key, value in params.items():
            overrideParam(key, value)

        # Atempt to extract video source
        video_info = getVideoInfo(url, quality)
        if video_info:
            if video_info.hasMultipleStreams():
                # More than one stream found, Ask the user to select a stream
                return self._source_selection(video_info)
            else:
                return video_info.streamURL()

        # Raise any stored errors
        elif stored_errors:
            raise RuntimeError(stored_errors[0])
Beispiel #41
0
    def extract_source(self, url, quality=None, **params):
        """
        Extract video URL using "YouTube.DL".

        YouTube.DL provides access to hundreds of sites.

        .. seealso::

            The list of supported sites can be found at:

            https://rg3.github.io/youtube-dl/supportedsites.html

        Quality options are.
            * 0 = SD,
            * 1 = 720p,
            * 2 = 1080p,
            * 3 = Highest Available

        :param str url: URL of the video source, where the playable video can be extracted from.
        :param int quality: [opt] Override YouTube.DL's quality setting.
        :param params: Optional "Keyword" arguments of YouTube.DL parameters.

        :returns: The playable video url
        :rtype: str

        .. seealso::

            The list of available parameters can be found at.

            https://github.com/rg3/youtube-dl#options

        .. note::

            Unfortunately the Kodi YouTube.DL module is Python 2 only. It should be
            ported to Python 3 when Kodi switches to Python 3 for version 19.
        """

        def ytdl_logger(record):
            if record.startswith("ERROR:"):
                # Save error rocord for raising later, outside of the callback
                # YoutubeDL ignores errors inside callbacks
                stored_errors.append("Youtube-DL: " + record[7:])

            self.log(record)
            return True

        # Setup YoutubeDL module
        # noinspection PyUnresolvedReferences
        from YDStreamExtractor import getVideoInfo, setOutputCallback, overrideParam
        setOutputCallback(ytdl_logger)
        stored_errors = []

        # Override youtube_dl parmeters
        for key, value in params.items():
            overrideParam(key, value)

        # Atempt to extract video source
        video_info = getVideoInfo(url, quality)
        if video_info:
            if video_info.hasMultipleStreams():
                # More than one stream found, Ask the user to select a stream
                video_info = self._source_selection(video_info)

            if video_info:
                # Content Lookup needs to be disabled for dailymotion videos to work
                if video_info.sourceName == "dailymotion":
                    self._extra_commands["setContentLookup"] = False

                return video_info.streamURL()

        # Raise any stored errors
        elif stored_errors:
            raise RuntimeError(stored_errors[0])