def add_torrent(self, torrent_url, cookie_header, subscription_data=None): # Initialize options with default configurations options = TorrentOptions() if subscription_data is not None: if len(subscription_data["move_completed"]) > 0: options["move_completed"] = True options["move_completed_path"] = subscription_data[ "move_completed"] if len(subscription_data["download_location"]) > 0: options["download_location"] = subscription_data[ "download_location"] options["add_paused"] = subscription_data[ "add_torrents_in_paused_state"] if torrent_url.startswith("magnet:"): self.log.info("Adding magnet: '%s'" % torrent_url) torrent_id = component.get("TorrentManager").add( options=options, magnet=torrent_url) else: basename = os.path.basename(torrent_url) # Fix unicode URLs torrent_url = http.url_fix(torrent_url) self.log.info("Adding torrent: '%s'" % torrent_url) filedump = self.download_torrent_file(torrent_url, cookie_header) torrent_id = component.get("TorrentManager").add(filedump=filedump, filename=basename, options=options) return torrent_id
add_torrent_params = {} if filedump is not None: try: torrent_info = lt.torrent_info(lt.bdecode(filedump)) except Exception, e: log.error("Unable to decode torrent file!: %s", e) # XXX: Probably should raise an exception here.. return if torrent_info is None and state: # We have no torrent_info so we need to add the torrent with information # from the state object. # Populate the options dict from state options = TorrentOptions() options["max_connections"] = state.max_connections options["max_upload_slots"] = state.max_upload_slots options["max_upload_speed"] = state.max_upload_speed options["max_download_speed"] = state.max_download_speed options["prioritize_first_last_pieces"] = state.prioritize_first_last options["file_priorities"] = state.file_priorities options["compact_allocation"] = state.compact options["download_location"] = state.save_path options["auto_managed"] = state.auto_managed options["stop_at_ratio"] = state.stop_at_ratio options["stop_ratio"] = state.stop_ratio options["remove_at_ratio"] = state.remove_at_ratio options["move_completed"] = state.move_completed options["move_completed_path"] = state.move_completed_path options["add_paused"] = state.paused
def add_torrent(self, torrent_info): # Initialize options with default configurations options = TorrentOptions() torrent_url = torrent_info["link"] subscription_data = torrent_info.get("subscription_data", None) if "torrent_download" in torrent_info: download = torrent_info["torrent_download"] else: download = self.get_torrent(torrent_info) if subscription_data: if len(subscription_data["move_completed"]) > 0: options["move_completed"] = True options["move_completed_path"] = subscription_data[ "move_completed"] if len(subscription_data["download_location"]) > 0: options["download_location"] = subscription_data[ "download_location"] if subscription_data[ "add_torrents_in_paused_state"] != GeneralSubsConf.DEFAULT: options["add_paused"] = GeneralSubsConf().get_boolean( subscription_data["add_torrents_in_paused_state"]) if subscription_data["auto_managed"] != GeneralSubsConf.DEFAULT: options["auto_managed"] = GeneralSubsConf().get_boolean( subscription_data["auto_managed"]) if "sequential_download" in subscription_data and\ subscription_data["auto_managed"] != GeneralSubsConf.DEFAULT: options["sequential_download"] = GeneralSubsConf().get_boolean( subscription_data["sequential_download"]) if subscription_data[ "prioritize_first_last_pieces"] != GeneralSubsConf.DEFAULT: options["prioritize_first_last_pieces"] = GeneralSubsConf( ).get_boolean( subscription_data["prioritize_first_last_pieces"]) # -2 means to use the deluge default config value, so in that case just skip if subscription_data["max_download_speed"] != -2: options["max_download_speed"] = subscription_data[ "max_download_speed"] if subscription_data["max_upload_speed"] != -2: options["max_upload_speed"] = subscription_data[ "max_upload_speed"] if subscription_data["max_connections"] != -2: options["max_connections"] = subscription_data[ "max_connections"] if subscription_data["max_upload_slots"] != -2: options["max_upload_slots"] = subscription_data[ "max_upload_slots"] if download.is_magnet: self.log.info("Adding magnet: '%s'" % torrent_url) download.torrent_id = component.get("TorrentManager").add( options=options, magnet=download.url) else: # Error occured if not download.success: self.log.warning("Failed to add '%s'." % (torrent_url)) return download self.log.info("Adding torrent: '%s'." % (torrent_url)) # 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" % (torrent_url, str(e))) self.log.warning(download.error_msg) try: download.torrent_id = component.get("TorrentManager").add( filedump=download.filedump, filename=os.path.basename(torrent_url), options=options) except AddTorrentError as err: download.success = False download.set_error("Failed to add torrent to Deluge: %s" % (str(err))) self.log.warning(download.error_msg) else: if ("Label" in component.get("Core").get_enabled_plugins() and subscription_data and subscription_data.get("label", "")): component.get("CorePlugin.Label").set_torrent( download.torrent_id, subscription_data["label"]) return download
add_torrent_params = {} if filedump is not None: try: torrent_info = lt.torrent_info(lt.bdecode(filedump)) except Exception, e: log.error("Unable to decode torrent file!: %s", e) # XXX: Probably should raise an exception here.. return if torrent_info is None and state: # We have no torrent_info so we need to add the torrent with information # from the state object. # Populate the options dict from state options = TorrentOptions() options["max_connections"] = state.max_connections options["max_upload_slots"] = state.max_upload_slots options["max_upload_speed"] = state.max_upload_speed options["max_download_speed"] = state.max_download_speed options[ "prioritize_first_last_pieces"] = state.prioritize_first_last options["file_priorities"] = state.file_priorities options["compact_allocation"] = state.compact options["download_location"] = state.save_path options["auto_managed"] = state.auto_managed options["stop_at_ratio"] = state.stop_at_ratio options["stop_ratio"] = state.stop_ratio options["remove_at_ratio"] = state.remove_at_ratio options["move_completed"] = state.move_completed options["move_completed_path"] = state.move_completed_path