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
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)
def test_url_fix(self): url = u"http://de.wikipedia.org/wiki/Elf (Begriffsklärung)" expected = "http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29" result = http.url_fix(url) self.assertEquals(expected, result)
def test_url_fix(self): url = u"http://de.wikipedia.org/wiki/Elf (Begriffsklärung)" expected = "http://de.wikipedia.org/wiki/Elf%20(Begriffskl%C3%A4rung)" result = http.url_fix(url) self.assertEquals(expected, result)