def send_to_transmission(self, url):
        transmission_rpc_url = self.get_config('rpc_url')
        client_request_id = self.classname + "".join(random.choice('0123456789ABCDEF') for _i in xrange(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)
 def api_response(self, **kwargs):
     """
     Dispatch a call to the api, see megacrypter.com/api_doc
     """
     self.log_debug("JSON request: " + json.dumps(kwargs))
     res = self.load(self.API_URL, post=json.dumps(kwargs))
     self.log_debug("API Response: " + res)
     return json.loads(res)
    def api_response(self, **kwargs):
        """
        Dispatch a call to the api, see https://mega.co.nz/#developers
        """
        #: Generate a session id, no idea where to obtain elsewhere
        uid = random.randint(10 << 9, 10 ** 10)

        res = self.load(self.API_URL, get={'id': uid}, post=json.dumps([kwargs]))
        self.log_debug("Api Response: " + res)
        return json.loads(res)
    def handle_premium(self, pyfile):
        premium_key = self.account.get_login("password")

        json_data = [self.account.user, ["download/direct_links", {"pass": premium_key, "link": pyfile.url}]]
        api_rep = self.load("http://api.letitbit.net/json", post={"r": json.dumps(json_data)})
        self.log_debug("API Data: " + api_rep)
        api_rep = json.loads(api_rep)

        if api_rep["status"] == "FAIL":
            self.fail(api_rep["data"])

        self.link = api_rep["data"][0][0]
    def handle_premium(self, pyfile):
        host        = self._get_host(pyfile.url)
        json_params = json.dumps({'link'    : pyfile.url,
                                  'type'    : host,
                                  'username': self.account.user,
                                  'password': self.account.get_login('password')})

        r = self.load("http://linksnappy.com/api/linkgen",
                      post={'genLinks': json_params})

        self.log_debug("JSON data: " + r)

        j = json.loads(r)['links'][0]

        if j['error']:
            self.error(_("Error converting the link"))

        pyfile.name = j['filename']
        self.link   = j['generated']
def api_response(url):
    json_data = ["yw7XQy2v9", ["download/info", {"link": url}]]
    api_rep = get_url("http://api.letitbit.net/json", post={"r": json.dumps(json_data)})
    return json.loads(api_rep)