当前位置: 首页>>代码示例>>Python>>正文


Python Net.http_HEAD方法代码示例

本文整理汇总了Python中t0mm0.common.net.Net.http_HEAD方法的典型用法代码示例。如果您正苦于以下问题:Python Net.http_HEAD方法的具体用法?Python Net.http_HEAD怎么用?Python Net.http_HEAD使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在t0mm0.common.net.Net的用法示例。


在下文中一共展示了Net.http_HEAD方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MovshareResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class MovshareResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "movshare"
    domains = ["movshare.net"]
    pattern = "//((?:www\.|embed\.)?movshare\.net)/(?:mobile/video\.php\?id=|video/|embed\.php\?v=)([0-9a-z]+)"

    def __init__(self):
        p = self.get_setting("priority") or 100
        self.priority = int(p)
        self.net = Net()

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        self.net.http_HEAD(web_url)
        html = self.net.http_GET(web_url).content
        """movshare can do both flv and avi. There is no way I know before hand
        if the url going to be a flv or avi. So the first regex tries to find
        the avi file, if nothing is present, it will check for the flv file.
        "param name="src" is for avi
        "flashvars.file=" is for flv
        """
        r = re.search('<param name="src" value="(.+?)"', html)
        if not r:
            match = re.search('flashvars.filekey="(.+?)";', html)
            if match:
                # get stream url from api
                filekey = match.group(0)
                api = "http://www.movshare.net/api/player.api.php?key=%s&file=%s" % (filekey, media_id)
                html = self.net.http_GET(api).content
                r = re.search("url=(.+?)&title", html)
        if r:
            stream_url = r.group(1)
        else:
            raise UrlResolver.ResolverError("File Not Found or removed")

        return stream_url

    def get_url(self, host, media_id):
        return "http://www.movshare.net/video/%s" % media_id

    def get_host_and_id(self, url):
        r = re.search(self.pattern, url)
        if r:
            return r.groups()
        else:
            return False

    def valid_url(self, url, host):
        if self.get_setting("enabled") == "false":
            return False
        return re.search(self.pattern, url) or "movshare" in host
开发者ID:schmidthans,项目名称:script.module.urlresolver,代码行数:53,代码来源:movshare.py

示例2: MovshareResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class MovshareResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "movshare"

    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        """ Human Verification """
        try:
            self.net.http_HEAD(web_url)
            html = self.net.http_GET(web_url).content
            """movshare can do both flv and avi. There is no way I know before hand
            if the url going to be a flv or avi. So the first regex tries to find 
            the avi file, if nothing is present, it will check for the flv file.
            "param name="src" is for avi
            "flashvars.file=" is for flv
            """
            r = re.search('<param name="src" value="(.+?)"', html)
            if not r:
                html = unwise.unwise_process(html)
                html = re.compile(r'eval\(function\(p,a,c,k,e,(?:d|r)\).+?\.split\(\'\|\'\).*?\)\)').search(html).group()
                html = jsunpack.unpack(html)
                filekey = unwise.resolve_var(html, "flashvars.filekey")
                
                #get stream url from api
                api = 'http://www.movshare.net/api/player.api.php?key=%s&file=%s' % (filekey, media_id)
                html = self.net.http_GET(api).content
                r = re.search('url=(.+?)&title', html)
            if r:
                stream_url = r.group(1)
            else:
                raise Exception ('File Not Found or removed')
            
            return stream_url
        except urllib2.URLError, e:
            common.addon.log_error(self.name + ': got http error %d fetching %s' %
                                   (e.code, web_url))
            common.addon.show_small_popup('Error','Http error: '+str(e), 5000, error_logo)
            return self.unresolvable(code=3, msg=e)
        except Exception, e:
            common.addon.log_error('**** Movshare Error occured: %s' % e)
            common.addon.show_small_popup(title='[B][COLOR white]MOVSHARE[/COLOR][/B]', msg='[COLOR red]%s[/COLOR]' % e, delay=5000, image=error_logo)
            return self.unresolvable(code=0, msg=e)
开发者ID:BagiraHun,项目名称:script.module.urlresolver,代码行数:49,代码来源:movshare.py

示例3: MovshareResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class MovshareResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "movshare"
    domains = ["movshare.net"]

    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        print web_url
        """ Human Verification """
        try:
            self.net.http_HEAD(web_url)
            html = self.net.http_GET(web_url).content
            """movshare can do both flv and avi. There is no way I know before hand
            if the url going to be a flv or avi. So the first regex tries to find
            the avi file, if nothing is present, it will check for the flv file.
            "param name="src" is for avi
            "flashvars.file=" is for flv
            """
            r = re.search('<param name="src" value="(.+?)"', html)
            if not r:
                match = re.search('flashvars.filekey="(.+?)";', html)
                if match:
                    #get stream url from api
                    filekey = match.group(0)
                    api = 'http://www.movshare.net/api/player.api.php?key=%s&file=%s' % (filekey, media_id)
                    html = self.net.http_GET(api).content
                    r = re.search('url=(.+?)&title', html)
            if r:
                stream_url = r.group(1)
            else:
                raise Exception('File Not Found or removed')
            
            return stream_url
        except urllib2.HTTPError, e:
            common.addon.log_error(self.name + ': got http error %d fetching %s' %
                                   (e.code, web_url))
            return self.unresolvable(code=3, msg=e)
        except Exception, e:
            common.addon.log_error('**** Movshare Error occured: %s' % e)
            return self.unresolvable(code=0, msg=e)
开发者ID:VioletRed,项目名称:script.module.urlresolver,代码行数:47,代码来源:movshare.py

示例4: NowvideoResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class NowvideoResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "nowvideo"
    domains = [ "nowvideo.eu","nowvideo.ch","nowvideo.sx" ]

    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        try:
            html = self.net.http_GET(web_url).content
            key = re.compile('flashvars.filekey=(.+?);').findall(html)
            ip_key = key[0]
            pattern = 'var %s="(.+?)".+?flashvars.file="(.+?)"'% str(ip_key)
            r = re.search(pattern,html, re.DOTALL)
            if r:
                filekey, filename= r.groups()
            else:
                r = re.search('file no longer exists',html)
                if r:
                    raise Exception ('File Not Found or removed')
            
            #get stream url from api
            api = 'http://www.nowvideo.sx/api/player.api.php?key=%s&file=%s' % (filekey, filename)
            html = self.net.http_GET(api).content
            r = re.search('url=(.+?)&title', html)
            if r:
                stream_url = urllib.unquote(r.group(1))
            else:
                r = re.search('no longer exists',html)
                if r:
                    raise Exception ('File Not Found or removed')
                raise Exception ('Failed to parse url')
            
            try:
                # test the url, should throw 404
                nv_header = self.net.http_HEAD(stream_url)
            except urllib2.HTTPError, e:
                # if error 404, redirect it back (two pass authentification)
                api = 'http://www.nowvideo.sx/api/player.api.php?pass=undefined&cid3=undefined&key=%s&user=undefined&numOfErrors=1&errorUrl=%s&cid=1&file=%s&cid2=undefined&errorCode=404' % (filekey, urllib.quote_plus(stream_url), filename)
                html = self.net.http_GET(api).content
                r = re.search('url=(.+?)&title', html)
                if r:
                    stream_url = urllib.unquote(r.group(1))
                
            return stream_url
        except urllib2.HTTPError, e:
            common.addon.log_error('Nowvideo: got http error %d fetching %s' %
                                    (e.code, web_url))
            return self.unresolvable(code=3, msg=e)
开发者ID:VioletRed,项目名称:script.module.urlresolver,代码行数:55,代码来源:nowvideo.py

示例5: MovshareResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class MovshareResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "movshare"

    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()
        

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        """ Human Verification """
        try:
            self.net.http_HEAD(web_url)
            html = self.net.http_GET(web_url).content
            """movshare can do both flv and avi. There is no way I know before hand
            if the url going to be a flv or avi. So the first regex tries to find 
            the avi file, if nothing is present, it will check for the flv file.
            "param name="src" is for avi
            "flashvars.file=" is for flv
            """
            r = re.search('<param name="src" value="(.+?)"', html)
            if not r:
                r = re.search('flashvars.file="(.+?)"', html)
            if r:
                stream_url = r.group(1)
            else:
                raise Exception ('File Not Found or removed')
                                    
            return stream_url
        except urllib2.URLError, e:
            common.addon.log_error(self.name + ': got http error %d fetching %s' %
                                   (e.code, web_url))
            common.addon.show_small_popup('Error','Http error: '+str(e), 5000, error_logo)
            return False
        except Exception, e:
            common.addon.log_error('**** Movshare Error occured: %s' % e)
            common.addon.show_small_popup(title='[B][COLOR white]MOVSHARE[/COLOR][/B]', msg='[COLOR red]%s[/COLOR]' % e, delay=5000, image=error_logo)
            return False
开发者ID:Hinnak321,项目名称:script.module.urlresolver,代码行数:42,代码来源:movshare.py

示例6: MovshareResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class MovshareResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "movshare"

    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()
        

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        """ Human Verification """
        try:
            self.net.http_HEAD(web_url)
            html = self.net.http_GET(web_url).content
        except urllib2.URLError, e:
            common.addon.log_error('movshare: got http error %d fetching %s' %
                                  (e.code, web_url))
            return False
               
        """movshare can do both flv and avi. There is no way I know before hand
        if the url going to be a flv or avi. So the first regex tries to find 
        the avi file, if nothing is present, it will check for the flv file.
        "param name="src" is for avi
        "flashvars.file=" is for flv
        """
        r = re.search('<param name="src" value="(.+?)"', html)
        if not r:
            r = re.search('flashvars.file="(.+?)"', html)
        if r:
            stream_url = r.group(1)
        else:
            common.addon.log_error('movshare: stream url not found')
            return False
                                    
        return stream_url
开发者ID:CelticShady,项目名称:script.module.urlresolver,代码行数:39,代码来源:movshare.py

示例7: FlashstreamResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class FlashstreamResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "flashstream"

    def __init__(self):
        p = self.get_setting("priority") or 100
        self.priority = int(p)
        self.net = Net()
        self.resolver_host = "flashstream.in"

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)

        """ Human Verification """
        try:
            self.net.http_HEAD(web_url)
            html = self.net.http_GET(web_url).content
        except urllib2.URLError, e:
            common.addon.log_error(self.name + ": got http error %d fetching %s" % (e.code, web_url))
            return False

        """ Parsing HTML """
        sPattern = "<div id=\"player_code\">.*?<script type='text/javascript'>eval.*?return p}\((.*?)</script>"
        r = re.search(sPattern, html, re.DOTALL + re.IGNORECASE)
        if r:
            sJavascript = r.group(1)
            sUnpacked = jsunpack.unpack(sJavascript)
            # sPattern = '\'file\',\'([^\']+?)\''
            sPattern = '<param name="src"0="(.*?)"'
            r = re.search(sPattern, sUnpacked)
            if r:
                return r.group(1)
            else:
                common.addon.log_error(self.name + ": no video url found in %s" % sUnpacked)
        else:
            common.addon.log_error(self.name + ": no javascript pattern found")
        return False
开发者ID:BagiraHun,项目名称:script.module.urlresolver,代码行数:39,代码来源:flashstream.py

示例8: MyViRuResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class MyViRuResolver(Plugin,UrlResolver,PluginSettings):
    implements=[UrlResolver,PluginSettings]
    name="myviru"
    domains=[ "myvi.ru" ]
    pattern = '//((?:www\.)?myvi\.ru)/player/embed/html/([0-9a-zA-Z\-_]+)'

    def __init__(self):
        p=self.get_setting('priority') or 100
        self.priority=int(p)
        self.net=Net()

    def get_media_url(self,host,media_id):
        full_url=self.get_url(host, media_id)
        src=self.net.http_GET(full_url).content
        p=re.findall("dataUrl:'([^']+)'",src)[0]
        js=json.loads(self.net.http_GET("http://%s%s" % (host, p)).content)
        videos=js["sprutoData"]["playlist"]
        opts=[]
        for video in videos:
            opts.append((video["title"], self.__resolve_url(video["video"][0]["url"], full_url)))
        return sorted(opts, key=lambda x:x[0])[0][1]

    def __resolve_url(self, url, ref_url):
        headers={'Referer':ref_url}
        return self.net.http_HEAD(url, headers=headers).get_url()

    def get_url(self,host,media_id):
        return 'http://%s/player/embed/html/%s'%(host, media_id)
     
    def get_host_and_id(self, url):
        r = re.search(self.pattern, url)
        if r: return r.groups()
        else: return False
        return('host','media_id')
    
    def valid_url(self, url, host):
        if self.get_setting('enabled') == 'false': return False
        return re.search(self.pattern, url) or 'myvi.ru' in host
开发者ID:DxCx,项目名称:script.module.urlresolver,代码行数:40,代码来源:myviru.py

示例9: VideoHutResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class VideoHutResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "videohut.to"
    
    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()
        self.pattern = 'http://www.(videohut.to)/(?:v\/|embed.php\?id=)([0-9a-z]+)'
    
    def get_url(self, host, media_id):
            return 'http://www.videohut.to/embed.php?id=%s' % (media_id)
    
    def get_host_and_id(self, url):
        r = re.search(self.pattern, url)
        if r: return r.groups()
        else: return False
    
    def valid_url(self, url, host):
        if self.get_setting('enabled') == 'false': return False
        return re.match(self.pattern, url) or self.name in host
    
    def __get_stream_url(self, media_id, filekey, error_num=0, error_url=None):
        '''
        Get stream url. 

        If previously found stream url is a dead link, add error params and try again
        '''

        if error_num > 0 and error_url:
            _error_params = '&numOfErrors={0}&errorCode=404&errorUrl={1}'.format(
                                error_num, 
                                urllib.quote_plus(error_url).replace('.', '%2E')
                            )
        else:
            _error_params = ''

        #use api to find stream address
        api_call = 'http://www.videohut.to/api/player.api.php?{0}&file={1}&key={2}{3}'.format(
                        'user=undefined&pass=undefined',
                        media_id,
                        urllib.quote_plus(filekey).replace('.', '%2E'),
                        _error_params
                    )

        api_html = self.net.http_GET(api_call).content
        rapi = re.search('url=(.+?)&title=', api_html)
        if rapi:
            return urllib.unquote(rapi.group(1))

        return None

    def __is_stream_url_active(self, web_url):
        try:
            header = self.net.http_HEAD(web_url)
            if header.get_headers():
                return True

            return False
        except:
            return False

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        dialog = xbmcgui.Dialog()
        #grab stream details
        try:
            html = self.net.http_GET(web_url).content
            html = unwise.unwise_process(html)
            filekey = unwise.resolve_var(html, "flashvars.filekey")

            error_url = None
            stream_url = None
            # try to resolve 3 times then give up
            for x in range(0, 2):
                link = self.__get_stream_url(media_id, filekey, 
                                        error_num=x,
                                        error_url=error_url)

                if link:
                    active = self.__is_stream_url_active(link)

                    if active:
                        stream_url = urllib.unquote(link)
                        break;
                    else:
                        # link inactive
                        error_url = link
                else:
                    # no link found
                    raise Exception ('File Not Found or removed')

            if stream_url:
                return stream_url
            else:
                raise Exception ('File Not Found or removed')

        except urllib2.URLError, e:
            common.addon.log_error(self.name + ': got http error %d fetching %s' %
                                   (e.code, web_url))
#.........这里部分代码省略.........
开发者ID:SNAPflix,项目名称:script.module.urlresolver,代码行数:103,代码来源:videohut.py

示例10: NowvideoResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class NowvideoResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "nowvideo"
    domains = ["nowvideo.eu", "nowvideo.ch", "nowvideo.sx", "nowvideo.co", "nowvideo.li"]
    pattern = '((?:http://|www.|embed.)?nowvideo.(?:eu|sx|ch|co|li))/(?:mobile/video\.php\?id=|video/|embed\.php\?.*?v=)([0-9a-z]+)'

    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        html = self.net.http_GET(web_url).content
        key = re.compile('flashvars.filekey=(.+?);').findall(html)
        ip_key = key[0]
        pattern = 'var %s="(.+?)".+?flashvars.file="(.+?)"' % str(ip_key)
        r = re.search(pattern, html, re.DOTALL)
        if r:
            filekey, filename = r.groups()
        else:
            r = re.search('file no longer exists', html)
            if r:
                raise UrlResolver.ResolverError('File Not Found or removed')
        
        #get stream url from api
        api = 'http://www.nowvideo.sx/api/player.api.php?key=%s&file=%s' % (filekey, filename)
        html = self.net.http_GET(api).content
        r = re.search('url=(.+?)&title', html)
        if r:
            stream_url = urllib.unquote(r.group(1))
        else:
            r = re.search('no longer exists', html)
            if r:
                raise UrlResolver.ResolverError('File Not Found or removed')
            raise UrlResolver.ResolverError('Failed to parse url')
        
        try:
            # test the url, should throw 404
            self.net.http_HEAD(stream_url)
        except urllib2.HTTPError:
            # if error 404, redirect it back (two pass authentification)
            api = 'http://www.nowvideo.sx/api/player.api.php?pass=undefined&cid3=undefined&key=%s&user=undefined&numOfErrors=1&errorUrl=%s&cid=1&file=%s&cid2=undefined&errorCode=404' % (filekey, urllib.quote_plus(stream_url), filename)
            html = self.net.http_GET(api).content
            r = re.search('url=(.+?)&title', html)
            if r:
                stream_url = urllib.unquote(r.group(1))
            
        return stream_url

    def get_url(self, host, media_id):
        return 'http://embed.nowvideo.sx/embed.php?v=%s' % media_id

    def get_host_and_id(self, url):
        r = re.search(self.pattern, url)
        if r:
            return r.groups()
        else:
            return False

    def valid_url(self, url, host):
        if self.get_setting('enabled') == 'false': return False
        return re.search(self.pattern, url) or 'nowvideo' in host
开发者ID:Vodzo,项目名称:script.module.urlresolver,代码行数:65,代码来源:nowvideo.py

示例11: VideoHutResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class VideoHutResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "videohut.to"
    domains = [ "videohut.to" ]
    
    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()
        self.pattern = 'http://www.(videohut.to)/(?:v\/|embed.php\?id=)([0-9a-z]+)'
    
    def get_url(self, host, media_id):
            return 'http://www.videohut.to/embed.php?id=%s' % (media_id)
    
    def get_host_and_id(self, url):
        r = re.search(self.pattern, url)
        if r: return r.groups()
        else: return False
    
    def valid_url(self, url, host):
        return re.match(self.pattern, url) or self.name in host
    
    def __get_stream_url(self, media_id, filekey, error_num=0, error_url=None):
        '''
        Get stream url. 

        If previously found stream url is a dead link, add error params and try again
        '''

        if error_num > 0 and error_url:
            _error_params = '&numOfErrors={0}&errorCode=404&errorUrl={1}'.format(
                                error_num, 
                                urllib.quote_plus(error_url).replace('.', '%2E')
                            )
        else:
            _error_params = ''

        #use api to find stream address
        api_call = 'http://www.videohut.to/api/player.api.php?{0}&file={1}&key={2}{3}'.format(
                        'user=undefined&pass=undefined',
                        media_id,
                        urllib.quote_plus(filekey).replace('.', '%2E'),
                        _error_params
                    )

        api_html = self.net.http_GET(api_call).content
        rapi = re.search('url=(.+?)&title=', api_html)
        if rapi:
            return urllib.unquote(rapi.group(1))

        return None

    def __is_stream_url_active(self, web_url):
        try:
            header = self.net.http_HEAD(web_url)
            if header.get_headers():
                return True

            return False
        except:
            return False

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        html = self.net.http_GET(web_url).content
        html = unwise.unwise_process(html)
        filekey = unwise.resolve_var(html, "flashvars.filekey")

        error_url = None
        stream_url = None
        # try to resolve 3 times then give up
        for x in range(0, 2):
            link = self.__get_stream_url(media_id, filekey, error_num=x, error_url=error_url)
            if link:
                active = self.__is_stream_url_active(link)
                if active:
                    stream_url = urllib.unquote(link)
                    break
                else:
                    # link inactive
                    error_url = link
            else:
                # no link found
                raise UrlResolver.ResolverError('File Not Found or removed')

        if stream_url:
            return stream_url
        else:
            raise UrlResolver.ResolverError('File Not Found or removed')
开发者ID:waggy162512,项目名称:script.module.urlresolver,代码行数:91,代码来源:videohut.py

示例12: VideorajResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import http_HEAD [as 别名]
class VideorajResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "videoraj.ch"
    domains = [ "videoraj.ec", "videoraj.eu", "videoraj.sx", "videoraj.ch", "videoraj.com" , "videoraj.to"]

    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()

    def __get_stream_url(self, host, media_id, filekey, error_num=0, error_url=None):
        '''
        Get stream url. 

        If previously found stream url is a dead link, add error params and try again
        '''

        if error_num > 0 and error_url:
            _error_params = '&numOfErrors={0}&errorCode=404&errorUrl={1}'.format(
                                error_num, 
                                urllib.quote_plus(error_url).replace('.', '%2E')
                            )
        else:
            _error_params = ''

        #use api to find stream address
        api_call = '%s/api/player.api.php?%s&file=%s&key=%s%s' % (host, 'user=undefined&pass=undefined', media_id, urllib.quote_plus(filekey).replace('.', '%2E'), _error_params)

        api_html = self.net.http_GET(api_call).content
        rapi = re.search('url=(.+?)&title=', api_html)
        if rapi:
            return urllib.unquote(rapi.group(1))

        return None

    def __is_stream_url_active(self, web_url):
        try:
            header = self.net.http_HEAD(web_url)
            if header.get_headers():
                return True

            return False
        except:
            return False

    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        #grab stream details
        html = self.net.http_GET(web_url).content
        html = unwise.unwise_process(html)
        filekey = unwise.resolve_var(html, "vars.key")
        error_url = None
        stream_url = None
        # try to resolve 3 times then give up
        for x in range(0, 2):
            link = self.__get_stream_url(host, media_id, filekey, 
                                    error_num=x,
                                    error_url=error_url)

            if link:
                active = self.__is_stream_url_active(link)

                if active:
                    stream_url = urllib.unquote(link)
                    break
                else:
                    # link inactive
                    error_url = link
            else:
                # no link found
                raise UrlResolver.ResolverError('File Not Found or removed')

        if stream_url:
            return stream_url
        else:
            raise UrlResolver.ResolverError('File Not Found or removed')

    def get_url(self, host, media_id):
        return '%s/embed.php?id=%s' % (host, media_id)

    def get_host_and_id(self, url):
        r = re.search('(https?://(?:www\.|embed\.)videoraj\.(?:ec|eu|sx|ch|com|to))/(?:v(?:ideo)*/|embed\.php\?id=)([0-9a-z]+)', url)
        if r:
            return r.groups()
        else:
            return False

    def valid_url(self, url, host):
        if self.get_setting('enabled') == 'false': return False
        return re.match('https?://(?:www\.|embed\.)videoraj\.(?:ec|eu|sx|ch|com|to)/(?:v(?:ideo)*/|embed\.php\?id=)([0-9a-z]+)', url) or 'videoraj' in host
开发者ID:DxCx,项目名称:script.module.urlresolver,代码行数:92,代码来源:videoraj.py


注:本文中的t0mm0.common.net.Net.http_HEAD方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。