TransmissionRPC.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:download-manager 作者: thispc 项目源码 文件源码
def send_to_transmission(self, url):
        transmission_rpc_url = self.config.get('rpc_url')
        client_request_id = self.classname + \
            "".join(random.choice('0123456789ABCDEF') for _i in range(4))
        req = get_request()

        try:
            response = self.load(transmission_rpc_url,
                                 post=json.dumps({'arguments': {'filename': url},
                                                  'method': 'torrent-add',
                                                  'tag': client_request_id}),
                                 req=req)

        except Exception, e:
            if isinstance(e, BadHeader) and e.code == 409:
                headers = dict(
                    re.findall(
                        r'(?P<name>.+?): (?P<value>.+?)\r?\n',
                        req.header))
                session_id = headers['X-Transmission-Session-Id']
                req.c.setopt(
                    pycurl.HTTPHEADER, [
                        "X-Transmission-Session-Id: %s" %
                        session_id])
                try:
                    response = self.load(transmission_rpc_url,
                                         post=json.dumps({'arguments': {'filename': url},
                                                          'method': 'torrent-add',
                                                          'tag': client_request_id}),
                                         req=req)

                    res = json.loads(response)
                    if "result" in res:
                        self.log_debug("Result: %s" % res['result'])

                except Exception, e:
                    self.log_error(e)

            else:
                self.log_error(e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号