Ejemplo n.º 1
0
def resolve(url, title=''):
    resolver_dirs = []
    for plugin_path in RESOLVER_DIRS:
        if kodi.vfs.exists(plugin_path):
            resolver_dirs.append(plugin_path)
    if resolver_dirs:
        add_plugin_dirs(resolver_dirs)

    log_utils.log('Attempting to resolve: |{0!s}|'.format(url),
                  log_utils.LOGDEBUG)
    source = HostedMediaFile(url=url, title=title, include_disabled=False)
    if not source:
        log_utils.log('Not supported by URLResolver: |{0!s}|'.format(url),
                      log_utils.LOGDEBUG)
        return None
    try:
        resolved = source.resolve()
    except:
        resolved = None
    if not resolved or not isinstance(resolved, basestring):
        log_utils.log('Unable to resolve: |{0!s}|'.format(url),
                      log_utils.LOGDEBUG)
        return None
    else:
        return resolved
Ejemplo n.º 2
0
def resolveURL(url, label, description=''):
    from urlresolver import HostedMediaFile

    if True:
        pass
    try:
        pass
        media_source = HostedMediaFile(url)
        xbmc.log("Resolving %s" % url, xbmc.LOGNOTICE)

        # Acquire lock
        # Be sure only one script runs at a time
        tmpfile = tempfile.gettempdir()+"/.anyurl.resolver.lock"
        counter = 0
        while (os.path.isfile(tmpfile) and counter < 2000):
            xbmc.log("%s Waiting for lock file %d - %s" % (addon_id, counter, url), xbmc.LOGDEBUG)
            xbmc.sleep(2000)
            counter = counter + 1
        if (os.path.isfile(tmpfile)):
            xbmc.log("%s Failed to lock %s" % (addon_id, url), xbmc.LOGNOTICE)
            os.remove(tmpfile) # Unlock after fail
            return (None, '') # Lock removed afer two minutes, but fail anyway
        xbmc.log("%s Locking %s" % (addon_id, url), xbmc.LOGDEBUG)
        open(tmpfile, 'a').close()

        file_url = media_source.resolve()

        if counter > 0: # Wait a bit if we had to wait before to be sure resolver is ready for the next one
            xbmc.sleep(3000)
        xbmc.log("%s Unlocking %s" % (addon_id, tmpfile), xbmc.LOGDEBUG)
        os.remove(tmpfile) # Unlock

        li = None
        if hasattr(media_source, "get_list_item"): li = media_source.get_list_item()

        if li: # Update labels with user provided ones (yt stopped working for no reason)
            infolabels={"Studio":"","ShowTitle":"","Title":label,
                        "plot":description, 'plotoutline': description}
            li.setInfo(type="video", infoLabels=infolabels)
            pass
        elif file_url: # Resolved, but not with metadata
            li = xbmcgui.ListItem(label = label, path = file_url)
            infolabels={"Studio":"","ShowTitle":"","Title":label,
                        "plot":description, 'plotoutline': description}
            li.setInfo(type="video", infoLabels=infolabels)
        else: # Unable to resolve
            xbmc.log("%s: Non resolvable URL: %s %s" % (addon_id, url, label), xbmc.LOGNOTICE)
            return (None, '')
        li.setProperty('IsPlayable', 'true')
        return (li, file_url)
    except KeyError:
        xbmc.log("%s: Missing URL" % (addon_id), xbmc.LOGNOTICE)
    except:
        xbmc.log("%s: Unhandled exception @resolveURL %s" % (addon_id, sys.exc_info()[0]), xbmc.LOGNOTICE)

    return (None, '')
Ejemplo n.º 3
0
 def get_media_url(self, host, media_id):
     web_url = self.get_url(host, media_id)
     self.headers['Referer'] = web_url
     html = self.net.http_GET(web_url, headers=self.headers).content
     r = re.search('file\s*:\s*"(.+?)"', html)
     if not r:
         r = re.search('playlist:.+?url:\s*\'(.+?)\'', html, re.DOTALL)
     if r:
         if 'google' in r.group(1):
             return HostedMediaFile(url=r.group(1)).resolve()
         else:
             return self.__add_headers_for_kodi(r.group(1))
     else:
         raise UrlResolver.ResolverError('File not found')
Ejemplo n.º 4
0
 def get_media_url(self, host, media_id):
     web_url = self.get_url(host, media_id)
     self.headers['Referer'] = web_url
     stream_url = ''
     new_host = urlparse(web_url).netloc
     html = self.net.http_GET(web_url, headers=self.headers).content
     if 'videozoo' not in new_host:
         r = re.search(
             '(?:playlist:|timer\s*=\s*null;).+?url\s*[:=]+\s*[\'"]+(.+?)[\'"]+',
             html, re.DOTALL)
     else:
         r = re.search('\*/\s+?(eval\(function\(p,a,c,k,e,d\).+)\s+?/\*',
                       html)
         if r:
             try:
                 r = jsunpack.unpack(r.group(1))
                 if r:
                     r = re.search('\[{"url":"(.+?)"', r.replace('\\', ''))
             except:
                 if r:
                     re_src = re.search('urlResolvers\|2F(.+?)\|',
                                        r.group(1))
                     re_url = re.search('php\|3D(.+?)\|', r.group(1))
                     r = None
                     if re_src and re_url:
                         stream_url = 'http://%s/%s.php?url=%s' % (
                             new_host, re_src.group(1), re_url.group(1))
                         stream_url = self._redirect_test(stream_url)
     if r:
         stream_url = urllib.unquote_plus(r.group(1))
         if 'http' not in stream_url:
             stream_url = 'http://' + host + '/' + stream_url.replace(
                 '/gplus.php', 'gplus.php').replace('/picasa.php',
                                                    'picasa.php')
         stream_url = self._redirect_test(stream_url)
         """ Rebuild stream_url with only st= and e= flags """
         s = re.search(
             '(http://.+/)(.+?)\?.*(st=[0-9a-zA-Z_\-]+).*?(e=[0-9]+).*',
             stream_url)
         if s:
             stream_url = str(s.group(1)) + str(s.group(2)) + '?' + str(
                 s.group(3)) + '&' + str(s.group(4))
     if stream_url:
         if 'google' in stream_url:
             return HostedMediaFile(url=stream_url).resolve()
         else:
             return self.__add_headers_for_kodi(stream_url)
     else:
         raise UrlResolver.ResolverError('File not found')
Ejemplo n.º 5
0
    def __resolveAlternate(self, url):
        """resolve one of the alternate links for a certain media target.
        will make the request to load the html page and pass it on to the LinkResolver to do the actual resolving
        @param url: the alternate target url to resolve
        @return: the resolved playable url
        @raise UnresolvableSourceException: if we found no links for this alternate url"""

        from urlresolver import HostedMediaFile

        log.debug("Resolving alternative link %s" % (url))
        links = HostedMediaFile(url).resolve()
        log.debug("resolved:  %s" % links)
        if links:
            log.debug("Found part items: %s" % links)
            return links
        raise UnresolvableSourceException(
            "No links found for '%s' on host '%s'" % (url, self.__sourceName))
Ejemplo n.º 6
0
    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        headers = {'User-Agent': common.IOS_USER_AGENT, 'Referer': web_url}
        stream_url = ''
        new_host = urlparse(web_url).netloc
        html = self.net.http_GET(web_url, headers=headers).content
        if 'videozoo' not in new_host:
            r = re.search(
                '(?:playlist:|timer\s*=\s*null;).+?url\s*[:=]+\s*[\'"]+(.+?)[\'"]+',
                html, re.DOTALL)
        else:
            r = re.search('\*/\s+?(eval\(function\(p,a,c,k,e,d\).+)\s+?/\*',
                          html)
            if r:
                try:
                    r = jsunpack.unpack(r.group(1))
                    if r:
                        r = re.search('\[{"url":"(.+?)"', r.replace('\\', ''))
                except:
                    if r:
                        re_src = re.search('urlResolvers\|2F(.+?)\|',
                                           r.group(1))
                        re_url = re.search('php\|3D(.+?)\|', r.group(1))
                        if re_src and re_url:
                            stream_url = 'http://%s/%s.php?url=%s' % (
                                new_host, re_src.group(1), re_url.group(1))
                            stream_url = self._redirect_test(stream_url)
                        else:
                            raise UrlResolver.ResolverError('File not found')
        if r:
            stream_url = urllib.unquote_plus(r.group(1))
            if 'http' not in stream_url:
                stream_url = 'http://' + host + '/' + stream_url.replace(
                    '/gplus.php', 'gplus.php').replace('/picasa.php',
                                                       'picasa.php')
            stream_url = self._redirect_test(stream_url)

        if stream_url:
            if 'google' in stream_url:
                return HostedMediaFile(url=stream_url).resolve()
            else:
                return stream_url
        else:
            raise UrlResolver.ResolverError('File not found')
Ejemplo n.º 7
0
def scrape_supported(url, html, regex):
    parsed_url = urlparse.urlparse(url)
    links = []
    _filter = [
        '.js', 'data:', 'blob:', 'tab=', 'usp=', '/pixel.', '/1x1.',
        'javascript:', 'rss.', 'blank.', '.rss'
    ]
    sources = []
    with kodi.ProgressDialog('%s...' %
                             kodi.i18n('scraping_for_potential_urls'),
                             '%s: %s' % (kodi.i18n('source'), url),
                             ' ',
                             timer=0.2) as progress_dialog:
        while not progress_dialog.is_canceled():
            new_iter = re.findall(regex, html, re.DOTALL)
            len_iter = len(new_iter)
            for index, match in enumerate(new_iter):
                if progress_dialog.is_canceled():
                    sys.exit(0)
                percent = int((float(index) / float(len_iter)) * 100)
                stream_url = match[0]
                if stream_url == '#' or stream_url == '//' or '/' not in stream_url or not re.match('^[hruf:/].+', stream_url) or \
                        any(item in stream_url for item in _filter) or any(stream_url == t[1] for t in links):
                    progress_dialog.update(
                        percent, kodi.i18n('preparing_results'),
                        '%s: %s' % (kodi.i18n('discarded'), '%s' % stream_url),
                        ' ')
                    continue
                stream_url = __check_for_new_url(stream_url).replace(r'\\', '')
                if stream_url.startswith('//'):
                    stream_url = '%s:%s' % (parsed_url.scheme, stream_url)
                elif stream_url.startswith('/'):
                    stream_url = '%s://%s%s' % (
                        parsed_url.scheme, parsed_url.hostname, stream_url)

                host = urlparse.urlparse(stream_url).hostname
                if host is None:
                    continue
                label = host
                if (len(match) > 2) and (match[2] is not None) and (
                        match[2].strip()) and (host not in match[2]):
                    label = match[2].strip()
                elif (len(match) > 1) and (match[1] is not None) and (
                        match[1].strip()) and (host not in match[1]):
                    label = match[1].strip()
                if not isinstance(label, unicode):
                    label = label.decode('utf-8', 'ignore')
                try:
                    parser = HTMLParser()
                    label = parser.unescape(label)
                    try:
                        label = parser.unescape(label)
                    except:
                        pass
                except:
                    pass
                progress_dialog.update(percent, kodi.i18n('preparing_results'),
                                       '%s: %s' % (kodi.i18n('added'), label),
                                       stream_url)
                sources.append((label, stream_url))
            if progress_dialog.is_canceled():
                sys.exit(0)
            break
        if progress_dialog.is_canceled():
            sys.exit(0)

    with kodi.ProgressDialog('%s...' %
                             kodi.i18n('scraping_for_potential_urls'),
                             '%s: %s' % (kodi.i18n('source'), url),
                             ' ',
                             timer=0.1) as progress_dialog:
        while not progress_dialog.is_canceled():
            len_iter = len(sources)
            for index, source in enumerate(sources):
                if progress_dialog.is_canceled():
                    sys.exit(0)
                percent = int((float(index) / float(len_iter)) * 100)
                label = source[0]
                stream_url = source[1]
                hmf = HostedMediaFile(url=stream_url, include_disabled=False)
                potential_type = __get_potential_type(stream_url)
                is_valid = hmf.valid_url()
                is_valid_type = (potential_type != 'audio') and (potential_type
                                                                 != 'image')

                if is_valid and is_valid_type:
                    progress_dialog.update(
                        percent, kodi.i18n('check_for_support'),
                        '%s [%s]: %s' % (kodi.i18n('support_potential'),
                                         'video', 'URLResolver'),
                        '[%s]: %s' % (label, stream_url))
                    links.append({
                        'label': label,
                        'url': stream_url,
                        'resolver': 'URLResolver',
                        'content_type': 'video'
                    })
                    continue
                else:
                    if potential_type == 'text':
                        if ytdl_supported(stream_url):
                            progress_dialog.update(
                                percent, kodi.i18n('check_for_support'),
                                '%s [%s]: %s' %
                                (kodi.i18n('support_potential'), 'video',
                                 'youtube-dl'),
                                '[%s]: %s' % (label, stream_url))
                            links.append({
                                'label': label,
                                'url': stream_url,
                                'resolver': 'youtube-dl',
                                'content_type': 'video'
                            })
                            continue
                        progress_dialog.update(
                            percent, kodi.i18n('check_for_support'),
                            '%s [%s]: %s' % (kodi.i18n('support_potential'),
                                             potential_type, 'None'),
                            '[%s]: %s' % (label, stream_url))
                    else:
                        progress_dialog.update(
                            percent, kodi.i18n('check_for_support'),
                            '%s [%s]: %s' % (kodi.i18n('support_potential'),
                                             potential_type, 'Kodi'),
                            '[%s]: %s' % (label, stream_url))
                    links.append({
                        'label': label,
                        'url': stream_url,
                        'resolver': None,
                        'content_type': potential_type
                    })
                    continue
            if progress_dialog.is_canceled():
                sys.exit(0)
            break
        if progress_dialog.is_canceled():
            sys.exit(0)
    return links
Ejemplo n.º 8
0
 def get_media_url(self, host, media_id):
     url = self.get_url(host, media_id)
     return HostedMediaFile(url=url).resolve()