def download(self, dload_url, torrent_name, load):
"""
Torrent download method.
Used to download .torrent file.
Torrent is downloaded in ~/Downloads/torrench/
"""
try:
mod = inspect.getmodulename(inspect.stack()[1][1])
modules_to_exclude = ['linuxtracker', 'distrowatch']
self.logger.debug("Download begins...")
home = os.path.expanduser(os.path.join('~', 'Downloads'))
downloads_dir = os.path.join(home, 'torrench')
self.logger.debug("Default download directory: %s", (downloads_dir))
if mod not in modules_to_exclude:
downloads_dir = os.path.join(downloads_dir, mod)
if not os.path.exists(downloads_dir):
self.logger.debug("download directory does not exist.")
os.makedirs(downloads_dir)
self.logger.debug("created directory: %s", (downloads_dir))
torrent_file = os.path.join(downloads_dir, torrent_name)
with open(torrent_file, "wb") as file:
print("Downloading torrent...")
response = requests.get(dload_url)
file.write(response.content)
self.logger.debug("Download complete!")
print("Download complete!")
print("\nSaved in %s\n" % (downloads_dir))
self.logger.debug("Saved in %s", (downloads_dir))
# Load torrent to client
if load == 1:
self.load_torrent(torrent_file)
except KeyboardInterrupt as e:
self.logger.exception(e)
print("\nAborted!\n")
评论列表
文章目录