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


Python Net.get_cookies方法代码示例

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


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

示例1: OKResolver

# 需要导入模块: from t0mm0.common.net import Net [as 别名]
# 或者: from t0mm0.common.net.Net import get_cookies [as 别名]
class OKResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "ok.ru"
    domains = ["ok.ru", "www.ok.ru"]
    profile_path = common.profile_path
    cookie_file = os.path.join(profile_path, '%s.cookies' % name)
    id_file = os.path.join(profile_path, '%s.id' % name)
    useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"
    header = {"User-Agent":useragent}

    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()
        self.pattern = '//((?:www\.)?ok\.ru)/(?:videoembed|video)/(.+)'
        try:
            os.makedirs(os.path.dirname(self.cookie_file))
        except OSError:
            pass

    def get_media_url(self, host, media_id):
        vids = self.__get_Metadata(media_id)

        purged_jsonvars = {}
        lines = []
        best = '0'

        for entry in vids['urls']:
            quality = self.__replaceQuality(entry['name'])
            lines.append(quality)
            if vids['vdtkn'] is not None:
                purged_jsonvars[quality] = entry['url'] + "&vdsig=" + vids['vtkn'] + "|User-Agent=" + self.useragent + "&Cookie=vdtkn%3D" + vids['vdtkn']
            else:
                purged_jsonvars[quality] = entry['url'] + "&vdsig=" + vids['vtkn'] + "|User-Agent=" + self.useragent
            if int(quality) > int(best): best = quality

        if vids['vdtkn'] is not None:
            if vids['vdtkn'][0] == '^':
                vids['vdtkn'] = vids['vdtkn'][1:]

        if len(lines) == 1:
            return purged_jsonvars[lines[0]].encode('utf-8')
        else:
            if self.get_setting('auto_pick') == 'true':
                return purged_jsonvars[str(best)].encode('utf-8')
            else:
                result = xbmcgui.Dialog().select('Choose the link', lines)

        if result != -1:
            return purged_jsonvars[lines[result]].encode('utf-8')
        else:
            raise UrlResolver.ResolverError('No link selected')

        raise UrlResolver.ResolverError('No video found')

    def __replaceQuality(self, qual):
        if qual == "full":
            return "1080"
        if qual == "hd":
            return "720"
        if qual == "sd":
            return "480"
        if qual == "low":
            return "360"
        if qual == "lowest":
            return "240"
        if qual == "mobile":
            return "144"
        common.addon.log_debug('Unknown quality: %s' % (qual))
        return "000"

    def __get_Metadata(self, media_id):
        url = "http://www.ok.ru/dk?cmd=videoPlayerMetadata&mid=" + media_id
        html = self.net.http_GET(url, headers=self.header).content
        json_data = json.loads(html)
        info = self.__get_vdsig(json_data['security']['url'])
        info['urls'] = []
        for entry in json_data['videos']:
            info['urls'].append(entry)
        return info

    def __get_vdsig(self, url):
        info = dict()

        vdsig = self.__loadSig()

        if vdsig is not None:
            info['vtkn'] = vdsig
            info['vdtkn'] = None
        else:
            params = dict()
            params[''] = ""
            response = self.net.http_POST(url, params, headers=self.header)
            cookies = self.net.get_cookies()
            html = response.content
            json_data = json.loads(html)
            self.__saveSig(json_data['vtkn'], cookies['.mycdn.me']['/']['vdtkn'].expires)
            info['vtkn'] = json_data['vtkn']
            info['vdtkn'] = cookies['.mycdn.me']['/']['vdtkn'].value

#.........这里部分代码省略.........
开发者ID:SemperfidelisTV,项目名称:SemperFI-,代码行数:103,代码来源:ok.py


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