示例#1
0
    def get_media_url(self, host, media_id):
        try:
            web_url = self.get_url(host, media_id)
            html = self.net.http_GET(web_url, headers=self.headers).content
            stream_map = urllib_parse.unquote(
                re.findall('url_encoded_fmt_stream_map=([^&]+)', html)[0])
            streams = stream_map.split(',')
            sources = []
            streams_mp4 = [item for item in streams if 'video%2Fmp4' in item]
            for stream in streams_mp4:
                quality = re.findall('quality=([^&]+)', stream)[0]
                url = re.findall('url=([^&]+)', stream)[0]
                sources.append((quality, urllib_parse.unquote(url)))
            if sources:
                return helpers.pick_source(sources)

        except:
            if youtube_resolver is None:
                return 'plugin://plugin.video.youtube/play/?video_id=' + media_id
            else:
                streams = youtube_resolver.resolve(media_id)
                streams_no_dash = [
                    item for item in streams if item['container'] != 'mpd'
                ]
                stream_tuples = [(item['title'], item['url'])
                                 for item in streams_no_dash]
                if stream_tuples:
                    return helpers.pick_source(stream_tuples)

        raise ResolverError('Video not found')
示例#2
0
 def get_media_url(self, host, media_id):
     if youtube_resolver is None:
         return 'plugin://plugin.video.youtube/play/?video_id=' + media_id
     else:
         streams = youtube_resolver.resolve(media_id)
         streams_no_dash = [item for item in streams if item['container'] != 'mpd']
         stream_tuples = [(item['title'], item['url']) for item in streams_no_dash]
         return helpers.pick_source(stream_tuples)
示例#3
0
 def get_media_url(self, host, media_id):
     if youtube_resolver is None:
         return 'plugin://plugin.video.youtube/play/?video_id=' + media_id
     else:
         streams = youtube_resolver.resolve(media_id)
         streams_no_dash = [item for item in streams if item['container'] != 'mpd']
         stream_tuples = [(item['title'], item['url']) for item in streams_no_dash]
         return helpers.pick_source(stream_tuples)
示例#4
0
def router(link):

    if link.startswith(('acestream://', 'sop://')):

        if 'acestream' in link:
            stream = 'plugin://program.plexus/?url={0}&mode=1'.format(
                link.partition('://')[2])
        else:
            stream = 'plugin://program.plexus/?url={0}&mode=2'.format(link)

        return stream

    elif 'youtu' in link:

        yt_mpd_enabled = control.addon(id='plugin.video.youtube').getSetting(
            'kodion.video.quality.mpd') == 'true'

        streams = youtube_resolver.resolve(link)

        if yt_mpd_enabled:
            urls = streams
        else:
            urls = [s for s in streams if 'dash' not in s['title'].lower()]

        resolved = urls[0]['url']

        return resolved

    elif 'v.redd.it' in link or 'reddit.com/video' in link:

        if 'reddit.com/video' in link:
            link = 'https://v.redd.it/' + link.partition('/')[2]

        try:

            dash_on = control.addon_details('inputstream.adaptive').get(
                'enabled')

        except KeyError:

            dash_on = False

        if dash_on:
            stream = link + '/DASHPlaylist.mpd'
        else:
            stream = link + '/HLSPlaylist.m3u8'

        return stream

    elif resolveurl.HostedMediaFile(link).valid_url():

        stream = resolveurl.resolve(link)

        return stream

    else:

        return link
示例#5
0
def wrapper(url):

    if url.endswith('/live'):

        url = generic(url)

        if not url:

            return

    streams = youtube_resolver.resolve(url)

    try:
        addon_enabled = control.addon_details('inputstream.adaptive').get(
            'enabled')
    except KeyError:
        addon_enabled = False

    if not addon_enabled:

        streams = [s for s in streams if 'dash' not in s['title'].lower()]

    if control.condVisibility('Window.IsVisible(music)') and control.setting(
            'audio_only') == 'true':

        audio_choices = [
            u for u in streams if 'dash/audio' in u and 'dash/video' not in u
        ]

        if control.setting('yt_quality_picker') == '0':
            resolved = audio_choices[0]['url']
        else:
            qualities = [i['title'] for i in audio_choices]
            urls = [i['url'] for i in audio_choices]

            links = list(zip(qualities, urls))

            resolved = stream_picker(links)

        return resolved

    elif control.setting('yt_quality_picker') == '1':

        qualities = [i['title'] for i in streams]
        urls = [i['url'] for i in streams]

        links = list(zip(qualities, urls))
        resolved = stream_picker(links)

        return resolved

    else:

        resolved = streams[0]['url']

        return resolved
示例#6
0
def wrapper(url):

    if replace_url:

        result = re.sub(
            r'''https?://(?:[0-9A-Z-]+\.)?(?:(youtu\.be|youtube(?:-nocookie)?\.com)/?\S*?[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|</a>))[?=&+%\w.-]*''',
            yt_prefix + r'\2', url, flags=re.I
        )

        if url != result:

            return result

    streams = youtube_resolver.resolve(url)

    try:
        addon_enabled = control.addon_details('inputstream.adaptive').get('enabled')
    except KeyError:
        addon_enabled = False

    if not addon_enabled:

        streams = [s for s in streams if 'dash' not in s['title'].lower()]

    if control.condVisibility('Window.IsVisible(music)') and control.setting('audio_only') == 'true':

        audio_choices = [u for u in streams if 'dash/audio' in u and 'dash/video' not in u]

        if control.setting('yt_quality_picker') == '0':
            resolved = audio_choices[0]['url']
        else:
            qualities = [i['title'] for i in audio_choices]
            urls = [i['url'] for i in audio_choices]

            resolved = stream_picker(qualities, urls)

        return resolved

    elif control.setting('yt_quality_picker') == '1':

        qualities = [i['title'] for i in streams]
        urls = [i['url'] for i in streams]

        resolved = stream_picker(qualities, urls)

        return resolved

    else:

        resolved = streams[0]['url']

        return resolved
def router(link):

    import urlresolver

    urlresolver.add_plugin_dirs(
        control.join(control.addonPath, 'resources', 'lib', 'resolvers',
                     'plugins'))

    # import resolveurl
    #
    # resolveurl.add_plugin_dirs(control.join(control.addonPath, 'resources', 'lib', 'resolvers', 'plugins'))

    if link.startswith(('acestream://', 'sop://')):

        if 'acestream' in link:
            stream = 'plugin://program.plexus/?url={0}&mode=1'.format(
                link.partition('://')[2])
        else:
            stream = 'plugin://program.plexus/?url={0}&mode=2'.format(link)

        return stream

    elif 'youtu' in link:

        yt_mpd_enabled = control.addon(id='plugin.video.youtube').getSetting(
            'kodion.video.quality.mpd') == 'true'

        streams = youtube_resolver.resolve(link)

        if yt_mpd_enabled:
            urls = streams
        else:
            urls = [s for s in streams if 'dash' not in s['title'].lower()]

        resolved = urls[0]['url']

        return resolved

    elif urlresolver.HostedMediaFile(link).valid_url():

        stream = urlresolver.resolve(link)

        # elif resolveurl.HostedMediaFile(link).valid_url():
        #
        #     stream = resolveurl.resolve(link)

        return stream

    else:

        return link
示例#8
0
def get_video_url(page_url,
                  premium=False,
                  user="",
                  password="",
                  video_password=""):
    import xbmc
    from xbmcaddon import Addon
    logger.debug("(page_url='%s')" % page_url)
    video_urls = []

    video_id = scrapertools.find_single_match(page_url,
                                              '(?:v=|embed/)([A-z0-9_-]{11})')
    inputstream = platformtools.install_inputstream()

    try:
        __settings__ = Addon(name)
        if inputstream:
            __settings__.setSetting('kodion.video.quality.mpd', 'true')
        else:
            __settings__.setSetting('kodion.video.quality.mpd', 'false')
        # video_urls = [['con YouTube', 'plugin://plugin.video.youtube/play/?video_id=' + video_id ]]
    except:
        path = xbmc.translatePath('special://home/addons/' + name)
        if filetools.exists(path):
            if platformtools.dialog_yesno(config.get_localized_string(70784),
                                          config.get_localized_string(70818)):
                xbmc.executeJSONRPC(
                    '{"jsonrpc": "2.0", "id":1, "method": "Addons.SetAddonEnabled", "params": { "addonid": "'
                    + name + '", "enabled": true }}')
            else:
                return [['', '']]
        else:
            xbmc.executebuiltin('InstallAddon(' + name + ')', wait=True)
            try:
                Addon(name)
            except:
                return [['', '']]
    my_addon = xbmcaddon.Addon('plugin.video.youtube')
    addon_dir = xbmc.translatePath(my_addon.getAddonInfo('path'))
    sys.path.append(filetools.join(addon_dir, 'resources', 'lib'))
    from youtube_resolver import resolve
    for stream in resolve(page_url):
        # title = scrapertools.find_single_match(stream['title'], '(\d+p)')
        if scrapertools.find_single_match(stream['title'], r'(\d+p)'):
            video_urls.append(
                [re.sub(r'(\[[^\]]+\])', '', stream['title']), stream['url']])
    video_urls.sort(key=lambda it: int(it[0].split("p", 1)[0]))

    return video_urls
    def TrailerList(self):
        content = []
        for i in self.traileritems:
            name = i.get('name')
            key = i.get('key')
            if i.get('site') == 'YouTube':
                stream_info = youtube_resolver.resolve(
                    key, addon_id=self.__addon_id__)[0]
                meta = stream_info.get('meta')
                content.append(
                    self.ListItemBuilder(name, stream_info.get('url'),
                                         meta.get('images').get('high')))
        return content


# u'name': u"Marvel's The Avengers- Trailer (OFFICIAL)", u'key': u'eOrNdBpGMv8', u'iso_3166_1': u'US', u'id': u'5794fd8bc3a3687605005cc9', u'size': 1080, u'type': u'Trailer', u'site': u'YouTube', u'iso_639_1': u'en'
 def VideoList(self):
     content = []
     for i in self.videos_dict:
         name = i.get('name')
         key = i.get('key')
         if i.get('site') == 'YouTube':
             stream_info = youtube_resolver.resolve(
                 key, addon_id=self.__addon_id__)[0]
             meta = stream_info.get('meta')
             content.append(
                 self.ListItemBuilder(name,
                                      meta.get('images').get('high'),
                                      'tmdb',
                                      self.tmdb_id,
                                      streamurl=stream_info.get('url')))
     return content
示例#11
0
def resolve_url(videoid):
    """
    Resolve the url in a playable stream using youtube_resolver from the youtube plugin
    """
    live = False
    try:
        streams = youtube_resolver.resolve(videoid)
    except Exception:
        dialog = xbmcgui.Dialog()
        dialog.notification(get_string(32002), get_string(32003), xbmcgui.NOTIFICATION_INFO, 10000)
        quit()
    if streams:
        if streams[0].get('Live'):
            if xbmc.getCondVisibility('System.HasAddon(%s)' % 'inputstream.adaptive') == 1:
                streams = [stream for stream in streams if (stream.get('container') == 'mpd' and stream.get('Live') is True)]
                live = True
            else:
                dialog = xbmcgui.Dialog()
                dialog.notification(get_string(32004), get_string(32005), xbmcgui.NOTIFICATION_INFO, 7500)
                return False
        if streams:
            stream = streams[0]
        title = get_string(32006) + stream.get('meta', {}).get('video', {}).get('title', '').encode('latin1')
        thumbnail = stream.get('meta', {}).get('images', {}).get('high', '')
        stream_url = stream.get('url', '')
        stream_headers = stream.get('headers', '')
        if stream_headers:
            stream_url += '|' + stream_headers
        play_item = xbmcgui.ListItem(label=title, path=stream_url)
        play_item.setInfo('video', {'Genre': 'Video', 'plot': get_string(32000)})
        play_item.setArt({'poster': thumbnail, 'thumb': thumbnail})
        play_item.setContentLookup(False)
        if live:
            play_item.setMimeType('application/xml+dash')
            play_item.setProperty('inputstreamaddon', 'inputstream.adaptive')
            play_item.setProperty('inputstream.adaptive.manifest_type', 'mpd')
            if stream_headers:
                play_item.setProperty('inputstream.adaptive.stream_headers', stream_headers)
        return play_item
    else:
        dialog = xbmcgui.Dialog()
        dialog.notification(get_string(32007), get_string(32005), xbmcgui.NOTIFICATION_INFO, 7500)
        return False
示例#12
0
 def get_media_url(self, host, media_id):
     try:
         web_url = self.get_url(host, media_id)
         html = self.net.http_GET(web_url, headers=self.headers).content
         stream_map = urllib.unquote(re.findall('url_encoded_fmt_stream_map=([^&]+)',html)[0])
         streams = stream_map.split(',')
         sources = []
         streams_mp4 = [item for item in streams if 'video%2Fmp4' in item]
         for stream in streams_mp4:
             quality = re.findall('quality=([^&]+)',stream)[0]
             url=re.findall('url=([^&]+)',stream)[0]
             sources.append((quality,urllib.unquote(url)))
         return helpers.pick_source(sources)
         
     except:
         if youtube_resolver is None:
             return 'plugin://plugin.video.youtube/play/?video_id=' + media_id
         else:
             streams = youtube_resolver.resolve(media_id)
             streams_no_dash = [item for item in streams if item['container'] != 'mpd']
             stream_tuples = [(item['title'], item['url']) for item in streams_no_dash]
             return helpers.pick_source(stream_tuples)
def resolve_yt_addon(url):
    label = None
    stream_url = None
    headers = None
    thumbnail = None
    content_type = 'video'

    sources = youtube_resolver.resolve(url, sort=True)
    if isinstance(sources, list):
        src = sources[0]
        if src.get('container') == 'mpd' and not dash_supported:
            src = sources[1]

        stream_url = src.get('url')

        hdr = src.get('headers')
        if hdr:
            headers = parse_qsl(hdr)

        lbl = src.get('meta', {}).get('video', {}).get('title')
        if lbl:
            label = lbl

        thmb = src.get('meta', {}).get('images', {}).get(
            'high',
            src.get('meta', {}).get('images', {}).get('medium'))
        if thmb:
            thumbnail = thmb

    return {
        'label': label,
        'resolved_url': stream_url,
        'content_type': content_type,
        'thumbnail': thumbnail,
        'headers': headers
    }
示例#14
0
import xbmc
import xbmcgui
import youtube_resolver

stream = youtube_resolver.resolve("n7kYOhiMFiI")
if stream:
    xbmc.log("----------------TEST STREAM ---------------------------------")
    xbmc.log("{url}|{headers}".format(url=stream[0]["url"],
                                      headers=stream[0]["headers"]))
    xbmc.log("----------------TEST STREAM ---------------------------------")
    xbmcgui.Dialog().ok(
        "TestStream",
        "Stream url printed to xbmc log. Make sure you enable debug logging.")
else:
    xbmcgui.Dialog().ok("TestStream", "Unable to resolve URL")
示例#15
0
 def ResolveVideo(self, video_id):
     return youtube_resolver.resolve(video_id, addon_id='script.thfczone')