コード例 #1
0
 def resolve(self):
     '''
     Resolves this :class:`HostedMediaFile` to a media URL.
     
     Example::
         
         stream_url = HostedMediaFile(host='youtube.com', media_id='ABC123XYZ').resolve()
     
     .. note::
     
         This method currently uses just the highest priority resolver to
         attempt to resolve to a media URL and if that fails it will return
         False. In future perhaps we should be more clever and check to make
         sure that there are no more resolvers capable of attempting to
         resolve the URL first.
     
     Returns:
         A direct URL to the media file that is playable by XBMC, or False
         if this was not possible.
     '''
     for resolver in self.__resolvers:
         try:
             common.addon.log_debug('resolving using %s plugin' % resolver.name)
             if resolver.valid_url(self._url, self._host):
                 if SiteAuth in resolver.implements:
                     common.addon.log_debug('logging in')
                     resolver.login()
                 self._host, self._media_id = resolver.get_host_and_id(self._url)
                 try:
                     stream_url = resolver.get_media_url(self._host, self._media_id)
                     if stream_url and self.__test_stream(stream_url):
                         self.__resolvers = [resolver]  # Found a valid resolver, ignore the others
                         self._valid_url = True
                         return stream_url
                 except UrlResolver.ResolverError as e:
                     common.addon.log_error('Resolver Error - From: %s Link: %s: %s' % (resolver.name, self._url, e))
                     if resolver == self.__resolvers[-1]:
                         common.addon.log_debug(traceback.format_exc())
                         return UrlResolver.unresolvable(code=0, msg=e)
                 except urllib2.HTTPError as e:
                     common.addon.log_error('HTTP Error - From: %s Link: %s: %s' % (resolver.name, self._url, e))
                     if resolver == self.__resolvers[-1]:
                         common.addon.log_debug(traceback.format_exc())
                         return UrlResolver.unresolvable(code=3, msg=e)
                 except Exception as e:
                     common.addon.log_error('Unknown Error - From: %s Link: %s: %s' % (resolver.name, self._url, e))
                     if resolver == self.__resolvers[-1]:
                         common.addon.log_error(traceback.format_exc())
                         return UrlResolver.unresolvable(code=0, msg=e)
         except Exception as e:
             common.addon.log_notice("Resolver '%s' crashed: %s. Ignoring" % (resolver.name, e))
             common.addon.log_debug(traceback.format_exc())
             continue
     self.__resolvers = []  # No resolvers.
     return False
コード例 #2
0
 def resolve(self):
     '''
     Resolves this :class:`HostedMediaFile` to a media URL.
     
     Example::
         
         stream_url = HostedMediaFile(host='youtube.com', media_id='ABC123XYZ').resolve()
     
     .. note::
     
         This method currently uses just the highest priority resolver to
         attempt to resolve to a media URL and if that fails it will return
         False. In future perhaps we should be more clever and check to make
         sure that there are no more resolvers capable of attempting to
         resolve the URL first.
     
     Returns:
         A direct URL to the media file that is playable by XBMC, or False
         if this was not possible.
     '''
     for resolver in self.__resolvers:
         try:
             common.addon.log_debug('resolving using %s plugin' % resolver.name)
             if resolver.valid_url(self._url, self._host):
                 if SiteAuth in resolver.implements:
                     common.addon.log_debug('logging in')
                     resolver.login()
                 self._host, self._media_id = resolver.get_host_and_id(self._url)
                 try:
                     stream_url = resolver.get_media_url(self._host, self._media_id)
                     if stream_url and self.__test_stream(stream_url):
                         self.__resolvers = [resolver]  # Found a valid resolver, ignore the others
                         self._valid_url = True
                         return stream_url
                 except UrlResolver.ResolverError as e:
                     common.addon.log_error('Resolver Error: %s - %s - %s' % (e, resolver.name, self._url))
                     common.addon.log_debug(traceback.format_exc())
                     return UrlResolver.unresolvable(code=0, msg=e)
                 except urllib2.HTTPError as e:
                     common.addon.log_error('HTTP Error: %s - %s - %s' % (e.code, resolver.name, self._url))
                     common.addon.log_debug(traceback.format_exc())
                     return UrlResolver.unresolvable(code=3, msg=e)
                 except Exception as e:
                     common.addon.log_error('Unknown Error: %s - %s - %s' % (e, resolver.name, self._url))
                     common.addon.log_error(traceback.format_exc())
                     return UrlResolver.unresolvable(code=0, msg=e)
         except Exception as e:
             common.addon.log_notice("Resolver '%s' crashed: %s. Ignoring" % (resolver.name, e))
             common.addon.log_debug(traceback.format_exc())
             continue
     self.__resolvers = []  # No resolvers.
     return False
コード例 #3
0
 def _find_resolvers(self):
     urlresolver.lazy_plugin_scan()
     imps = []
     for imp in UrlResolver.implementors():
         if imp.valid_url(self.get_url(), self.get_host()):
             imps.append(imp)
     return imps
コード例 #4
0
    def __find_resolvers(self, universal=False):
        urlresolver.lazy_plugin_scan()
        resolvers = []
        found = False
        for resolver in UrlResolver.implementors():
            if (self._domain in resolver.domains) or any(self._domain in domain for domain in resolver.domains):
                found = True
                resolvers.append(resolver)
            elif (universal and ('*' in resolver.domains)):
                resolvers.append(resolver)

        if not found: common.addon.log_debug('no resolver found for: %s' % (self._domain))
        else: common.addon.log_debug('resolvers for %s are %s' % (self._domain, [r.name for r in resolvers]))

        return resolvers
コード例 #5
0
    def __find_resolvers(self, universal=False):
        urlresolver.lazy_plugin_scan()
        resolvers = []
        found = False
        for resolver in UrlResolver.implementors():
            if (self._domain in resolver.domains) or any(self._domain in domain for domain in resolver.domains):
                found = True
                resolvers.append(resolver)
            elif (universal and ('*' in resolver.domains)):
                resolvers.append(resolver)

        if not found: common.addon.log_debug('no resolver found for: %s' % (self._domain))
        else: common.addon.log_debug('resolvers for %s are %s' % (self._domain, [r.name for r in resolvers]))

        return resolvers
コード例 #6
0
    def __find_resolvers(self, universal=False):
        urlresolver.lazy_plugin_scan()
        resolvers = []
        found = False
        for resolver in UrlResolver.implementors():
            if resolver.get_setting("enabled") != "true":
                continue
            if (self._domain in resolver.domains) or any(self._domain in domain for domain in resolver.domains):
                found = True
                resolvers.append(resolver)
            elif universal and ("*" in resolver.domains):
                resolvers.append(resolver)

        if not found:
            common.addon.log_debug("no resolver found for: %s" % (self._domain))
        else:
            common.addon.log_debug("resolvers for %s are %s" % (self._domain, [r.name for r in resolvers]))

        return resolvers
コード例 #7
0
def find_resolver(web_url):
    '''
    Finds the first resolver that says it can resolve the given URL to a media 
    file. Note that it might not actually be able to, but it advertises the
    fact that it can.
    
    .. note::
    
        You probably won't need to access this function for normal usage - just
        use :func:`urlresolver.resolve`.
        
    Args:
        web_url (str): A URL to a web page associated with a piece of media
        content.
        
    Returns:
        An instance of a class that implements 
        :class:`urlresolver.plugnplay.interfaces.UrlResolver` and advertises
        that it can resolve the given ``web_url``.
    '''
    for imp in UrlResolver.implementors():
        if imp.valid_url(web_url):
            return imp
    return False
コード例 #8
0
def find_resolver(web_url):
    '''
    Finds the first resolver that says it can resolve the given URL to a media 
    file. Note that it might not actually be able to, but it advertises the
    fact that it can.
    
    .. note::
    
        You probably won't need to access this function for normal usage - just
        use :func:`urlresolver.resolve`.
        
    Args:
        web_url (str): A URL to a web page associated with a piece of media
        content.
        
    Returns:
        An instance of a class that implements 
        :class:`urlresolver.plugnplay.interfaces.UrlResolver` and advertises
        that it can resolve the given ``web_url``.
    '''
    for imp in UrlResolver.implementors():
        if imp.valid_url(web_url):
            return imp
    return False
コード例 #9
0
 def _find_resolvers(self):
     imps = []
     for imp in UrlResolver.implementors():
         if imp.valid_url(self.get_url(), self.get_host()):
             imps.append(imp)
     return imps
コード例 #10
0
def lazy_plugin_scan():
    if not UrlResolver.implementors():
        plugnplay.scan_plugins(UrlWrapper)
コード例 #11
0
def lazy_plugin_scan():
    if not UrlResolver.implementors():
        plugnplay.scan_plugins(UrlWrapper)