예제 #1
0
    def download_torrent_file(self, torrent_url, cookies=None, headers=None):
        download = TorrentDownload()
        download.url = torrent_url
        download.cookies = cookies
        args = {"verify": False}
        if cookies is not None:
            args["cookies"] = cookies
        if headers is not None:
            args["headers"] = headers
        download.headers = headers
        try:
            r = requests.get(torrent_url, **args)
            download.filedump = r.content
        except Exception as e:
            error_msg = "Failed to download torrent url: '%s'. Exception: %s" % (
                torrent_url, str(e))
            self.log.error(error_msg)
            download.set_error(error_msg)
            return download

        if download.filedump is None:
            error_msg = "Filedump is None"
            download.set_error(error_msg)
            self.log.warning(error_msg)
            return download

        try:
            # Get the info to see if any exceptions are raised
            lt.torrent_info(lt.bdecode(download.filedump))
        except Exception as e:
            error_msg = "Unable to decode torrent file! (%s) URL: '%s'" % (
                str(e), torrent_url)
            download.set_error(error_msg)
            self.log.error(error_msg)
        return download
 def download_torrent_file(self, torrent_url, cookies_dict):
     download = TorrentDownload()
     download.url = torrent_url
     download.cookies_dict = cookies_dict
     try:
         r = requests.get(torrent_url, cookies=cookies_dict, verify=False)
         download.filedump = r.content
     except Exception, e:
         error_msg = "Failed to download torrent url: '%s'. Exception: %s" % (torrent_url, str(e))
         self.log.error(error_msg)
         download.set_error(error_msg)
         return download
 def download_torrent_file(self, torrent_url, cookies=None, headers=None):
     download = TorrentDownload()
     download.url = torrent_url
     download.cookies = cookies
     args = {"verify": False}
     if cookies is not None:
         args["cookies"] = cookies
     if headers is not None:
         args["headers"] = headers
     download.headers = headers
     try:
         r = requests.get(torrent_url, **args)
         download.filedump = r.content
     except Exception, e:
         error_msg = "Failed to download torrent url: '%s'. Exception: %s" % (
             torrent_url, str(e))
         self.log.error(error_msg)
         download.set_error(error_msg)
         return download