コード例 #1
0
    def get_torrent(self, torrent_info):
        url = torrent_info["link"]
        site_cookies_dict = torrent_info.get("site_cookies_dict", None)
        download = None
        headers = {}
        user_agent = torrent_info.get("user_agent", None)

        if user_agent:
            headers["User-Agent"] = user_agent

        if url.startswith("magnet:"):
            self.log.info("Fetching magnet: '%s'" % url, gtkui=False)
            download = TorrentDownload({"is_magnet": True, "url": url})
        else:
            # Fix unicode URLs
            url = http.url_fix(url)
            self.log.info(
                "Downloading torrent: '%s' using cookies: '%s', headers: '%s'"
                % (url, str(site_cookies_dict), str(headers)),
                gtkui=True)
            download = self.download_torrent_file(url,
                                                  cookies=site_cookies_dict,
                                                  headers=headers)
            # Error occured
            if not download.success:
                return download
            # Get the torrent data from the torrent file
            try:
                torrentinfo.TorrentInfo(filedump=download.filedump)
            except Exception as e:
                download.set_error(
                    "Unable to open torrent file: %s. Error: %s" %
                    (url, str(e)))
                self.log.warning(download.error_msg)
        return download
コード例 #2
0
    def get_torrent(self, torrent_info):
        url = torrent_info["link"]
        site_cookies_dict = torrent_info["site_cookies_dict"]
        download = None

        if url.startswith("magnet:"):
            self.log.info("Fetching magnet: '%s'" % url, gtkui=False)
            download = TorrentDownload({"is_magnet": True, "url": url})
        else:
            # Fix unicode URLs
            url = http.url_fix(url)
            self.log.info("Downloading torrent: '%s' using cookies: %s" % (url, str(site_cookies_dict)), gtkui=False)
            download = self.download_torrent_file(url, site_cookies_dict)
            # Error occured
            if not download.success:
                return download
            # Get the torrent data from the torrent file
            try:
                info = torrentinfo.TorrentInfo(filedump=download.filedump)
            except Exception, e:
                download.set_error("Unable to open torrent file: %s. Error: %s" % (url, str(e)))
                self.log.warn(download.error_msg)
コード例 #3
0
 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
コード例 #4
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, 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
コード例 #5
0
        def add_torrent_callback(torrent_download):
            torrent_download = TorrentDownload(torrent_download)
            if torrent_download.success:
                return True
            if torrent_download.filedump is None:
                return

            readable_body = http.clean_html_body(torrent_download.filedump)
            textbuffer = self.get_object("textview_messages").get_buffer()
            textbuffer.set_text(readable_body)

            self.get_object("notebook_lower").set_current_page(1)

            # Quick hack to make sure the message is visible to the user.
            hpaned = self.get_object("hpaned_matching")
            max_pos = hpaned.get_property("max-position")
            hpaned.set_position(int(max_pos * 0.3))
            return False
コード例 #6
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