Index: src/core.py =================================================================== --- src/core.py (revision 1045) +++ src/core.py (working copy) @@ -304,21 +304,29 @@ class Manager: def get_pref(self, key): # Get the value from the preferences object return self.config.get(key) # Dump torrent info without adding def dump_torrent_file_info(self, torrent): return deluge_core.dump_file_info(torrent) + # Dump trackers from torrent file + def dump_trackers(self, torrent): + return deluge_core.dump_trackers(torrent) + # Torrent addition and removal functions def add_torrent(self, filename, save_dir, compact): self.add_torrent_ns(filename, save_dir, compact) return self.sync() # Syncing will create a new torrent in the core, and return it's ID + + # When duplicate torrent error, use to find duplicate when merging tracker lists + def test_duplicate(self, torrent, unique_id): + return deluge_core.test_duplicate(torrent, unique_id) def remove_torrent(self, unique_ID, data_also, torrent_also): temp = self.unique_IDs[unique_ID] temp_fileinfo = deluge_core.get_file_info(unique_ID) self.remove_torrent_ns(unique_ID) self.sync() Index: src/interface.py =================================================================== --- src/interface.py (revision 1045) +++ src/interface.py (working copy) @@ -1103,16 +1103,43 @@ class DelugeGTK: return else: unique_id = self.manager.add_torrent(torrent, path, self.config.get('use_compact_storage')) except core.InvalidEncodingError, e: print "InvalidEncodingError", e dialogs.show_popup_warning(self.window, _("An error occured while trying to add the torrent. It's possible your .torrent file is corrupted.")) except core.DuplicateTorrentError, e: + print "duplicate's tracker list as string" + print self.manager.dump_trackers(torrent) + print "\n\n\n" + new_trackers_as_list = self.manager.dump_trackers(torrent).split('\n') + print "duplicate's tracker list" + print new_trackers_as_list + print "\n\n\n" + for unique_id in self.manager.unique_IDs: + if self.manager.test_duplicate(torrent, unique_id): + break + original_trackers_as_list = self.manager.get_trackers(unique_id).split('\n') + print "original tracker list" + print original_trackers_as_list + print "\n\n\n" + for index in xrange(len(new_trackers_as_list)-1): + if original_trackers_as_list.count(new_trackers_as_list[index]) == 0: + insert_to = len(original_trackers_as_list) - 1 + original_trackers_as_list.insert(insert_to, new_trackers_as_list[index]) + merged_trackers_as_string = "" + for index in xrange(len(original_trackers_as_list)-1): + merged_trackers_as_string = merged_trackers_as_string + original_trackers_as_list[index] + '\n' + print "merged tracker list" + print merged_trackers_as_string + self.manager.core.replace_trackers(unique_id, merged_trackers_as_string) + print "If it gets this far, we're good to go" + print self.core.get_trackers(unique_id).split("\n") + #this popup will be defunct dialogs.show_popup_warning(self.window, _("The torrent you've added seems to already be in Deluge.")) except core.InsufficientFreeSpaceError, e: nice_need = common.fsize(e.needed_space) nice_free = common.fsize(e.free_space) dialogs.show_popup_warning(self.window, _("There is not enough free disk space to complete your download.") + "\n" + \ _("Space Needed:") + " " + nice_need + "\n" + \ _("Available Space:") + " " + nice_free) else: Index: src/deluge_core.cpp =================================================================== --- src/deluge_core.cpp (revision 1045) +++ src/deluge_core.cpp (working copy) @@ -165,28 +165,27 @@ long get_torrent_index(torrent_handle &h { // printf("Found: %li\r\n", i); return i; } RAISE_INT(DelugeError, "Handle not found."); } - long get_index_from_unique_ID(long unique_ID) { for (unsigned long i = 0; i < M_torrents->size(); i++) if ((*M_torrents)[i].unique_ID == unique_ID) return i; RAISE_INT(DelugeError, "No such unique_ID."); } -torrent_info internal_dump_file_info(std::string const& torrent_name) +torrent_info internal_get_torrent_info(std::string const& torrent_name) { std::ifstream in(torrent_name.c_str(), std::ios_base::binary); in.unsetf(std::ios_base::skipws); entry e; e = bdecode(std::istream_iterator(in), std::istream_iterator()); torrent_info t(e); @@ -529,17 +528,17 @@ static PyObject *torrent_set_max_connect } static PyObject *torrent_dump_file_info(PyObject *self, PyObject *args) { const char *name; if (!PyArg_ParseTuple(args, "s", &name)) return NULL; - torrent_info t = internal_dump_file_info(name); + torrent_info t = internal_get_torrent_info(name); PyObject *file_info; long file_index = 0; PyObject *ret = PyTuple_New(t.num_files()); for(torrent_info::file_iterator i = t.begin_files(); i != t.end_files(); ++i) { file_entry const &currFile = (*i); @@ -552,16 +551,34 @@ static PyObject *torrent_dump_file_info( PyTuple_SetItem(ret, file_index, file_info); file_index++; }; return ret; } +static PyObject *torrent_dump_trackers(PyObject *self, PyObject *args) +{ + const char *name; + if (!PyArg_ParseTuple(args, "s", &name)) + return NULL; + + torrent_info t = internal_get_torrent_info(name); + std::string trackerslist; + { + for (std::vector::const_iterator i = t.trackers().begin(); + i != t.trackers().end(); ++i) + { + trackerslist = trackerslist + i->url +"\n"; + } + } + return Py_BuildValue("s",trackerslist.c_str()); +} + static PyObject *torrent_add_torrent(PyObject *self, PyObject *args) { const char *name, *save_dir; python_long compact; if (!PyArg_ParseTuple(args, "ssi", &name, &save_dir, &compact)) return NULL; boost::filesystem::path save_dir_2 (save_dir, empty_name_check); @@ -578,16 +595,32 @@ static PyObject *torrent_add_torrent(PyO catch (invalid_torrent_file&) { RAISE_PTR(InvalidTorrentError, ""); } catch (boost::filesystem::filesystem_error&) { RAISE_PTR(FilesystemError, ""); } catch (duplicate_torrent&) { RAISE_PTR(DuplicateTorrentError, "libtorrent reports this is a duplicate torrent"); } } +static PyObject *torrent_test_duplicate(PyObject *self, PyObject *args) +{ + const char *name; + python_long unique_ID; + if (!PyArg_ParseTuple(args, "si", &name, &unique_ID)) + return NULL; + + long index = get_index_from_unique_ID(unique_ID); + if (PyErr_Occurred()) + return NULL; + + torrent_info t = internal_get_torrent_info(name); + return Py_BuildValue("b", t.info_hash() == M_torrents->at(index).handle.info_hash()); + +} + static PyObject *torrent_move_storage(PyObject *self, PyObject *args) { const char *move_dir; python_long unique_ID; if (!PyArg_ParseTuple(args, "is", &unique_ID, &move_dir)) return NULL; long index = get_index_from_unique_ID(unique_ID); @@ -1506,59 +1539,61 @@ static PyObject *torrent_set_priv(PyObje } //==================== // Python Module data //==================== static PyMethodDef deluge_core_methods[] = { - {"pe_settings", torrent_pe_settings, METH_VARARGS, "."}, - {"pre_init", torrent_pre_init, METH_VARARGS, "."}, - {"init", torrent_init, METH_VARARGS, "."}, - {"quit", torrent_quit, METH_VARARGS, "."}, - {"save_fastresume", torrent_save_fastresume, METH_VARARGS, "."}, - {"set_max_half_open", torrent_set_max_half_open, METH_VARARGS, "."}, - {"set_download_rate_limit", torrent_set_download_rate_limit, METH_VARARGS, "."}, - {"set_upload_rate_limit", torrent_set_upload_rate_limit, METH_VARARGS, "."}, - {"set_listen_on", torrent_set_listen_on, METH_VARARGS, "."}, - {"is_listening", torrent_is_listening, METH_VARARGS, "."}, - {"listening_port", torrent_listening_port, METH_VARARGS, "."}, - {"set_max_uploads", torrent_set_max_uploads, METH_VARARGS, "."}, - {"set_max_connections", torrent_set_max_connections, METH_VARARGS, "."}, - {"add_torrent", torrent_add_torrent, METH_VARARGS, "."}, - {"move_storage", torrent_move_storage, METH_VARARGS, "."}, - {"remove_torrent", torrent_remove_torrent, METH_VARARGS, "."}, - {"get_num_torrents", torrent_get_num_torrents, METH_VARARGS, "."}, - {"reannounce", torrent_reannounce, METH_VARARGS, "."}, - {"pause", torrent_pause, METH_VARARGS, "."}, - {"resume", torrent_resume, METH_VARARGS, "."}, - {"get_torrent_state", torrent_get_torrent_state, METH_VARARGS, "."}, - {"pop_event", torrent_pop_event, METH_VARARGS, "."}, - {"get_session_info", torrent_get_session_info, METH_VARARGS, "."}, - {"get_peer_info", torrent_get_peer_info, METH_VARARGS, "."}, - {"get_file_info", torrent_get_file_info, METH_VARARGS, "."}, - {"dump_file_info", torrent_dump_file_info, METH_VARARGS, "."}, - {"constants", torrent_constants, METH_VARARGS, "."}, - {"start_DHT", torrent_start_DHT, METH_VARARGS, "."}, - {"stop_DHT", torrent_stop_DHT, METH_VARARGS, "."}, - {"get_DHT_info", torrent_get_DHT_info, METH_VARARGS, "."}, - {"create_torrent", torrent_create_torrent, METH_VARARGS, "."}, - {"reset_IP_filter", torrent_reset_IP_filter, METH_VARARGS, "."}, - {"add_range_to_IP_filter", torrent_add_range_to_IP_filter, METH_VARARGS, "."}, - {"use_upnp", torrent_use_upnp, METH_VARARGS, "."}, - {"use_natpmp", torrent_use_natpmp, METH_VARARGS, "."}, - {"use_utpex", torrent_use_utpex, METH_VARARGS, "."}, - {"set_ratio", torrent_set_ratio, METH_VARARGS, "."}, - {"proxy_settings", torrent_proxy_settings, METH_VARARGS, "."}, - {"get_trackers", torrent_get_trackers, METH_VARARGS, "."}, - {"replace_trackers", torrent_replace_trackers, METH_VARARGS, "."}, - {"set_flp", torrent_set_flp, METH_VARARGS, "."}, - {"prioritize_files", torrent_prioritize_files, METH_VARARGS, "."}, - {"set_priv", torrent_set_priv, METH_VARARGS, "."}, + {"pe_settings", torrent_pe_settings, METH_VARARGS, "."}, + {"pre_init", torrent_pre_init, METH_VARARGS, "."}, + {"init", torrent_init, METH_VARARGS, "."}, + {"quit", torrent_quit, METH_VARARGS, "."}, + {"save_fastresume", torrent_save_fastresume, METH_VARARGS, "."}, + {"set_max_half_open", torrent_set_max_half_open, METH_VARARGS, "."}, + {"set_download_rate_limit", torrent_set_download_rate_limit, METH_VARARGS, "."}, + {"set_upload_rate_limit", torrent_set_upload_rate_limit, METH_VARARGS, "."}, + {"set_listen_on", torrent_set_listen_on, METH_VARARGS, "."}, + {"is_listening", torrent_is_listening, METH_VARARGS, "."}, + {"listening_port", torrent_listening_port, METH_VARARGS, "."}, + {"set_max_uploads", torrent_set_max_uploads, METH_VARARGS, "."}, + {"set_max_connections", torrent_set_max_connections, METH_VARARGS, "."}, + {"add_torrent", torrent_add_torrent, METH_VARARGS, "."}, + {"move_storage", torrent_move_storage, METH_VARARGS, "."}, + {"remove_torrent", torrent_remove_torrent, METH_VARARGS, "."}, + {"get_num_torrents", torrent_get_num_torrents, METH_VARARGS, "."}, + {"reannounce", torrent_reannounce, METH_VARARGS, "."}, + {"pause", torrent_pause, METH_VARARGS, "."}, + {"resume", torrent_resume, METH_VARARGS, "."}, + {"get_torrent_state", torrent_get_torrent_state, METH_VARARGS, "."}, + {"pop_event", torrent_pop_event, METH_VARARGS, "."}, + {"get_session_info", torrent_get_session_info, METH_VARARGS, "."}, + {"get_peer_info", torrent_get_peer_info, METH_VARARGS, "."}, + {"get_file_info", torrent_get_file_info, METH_VARARGS, "."}, + {"dump_file_info", torrent_dump_file_info, METH_VARARGS, "."}, + {"constants", torrent_constants, METH_VARARGS, "."}, + {"start_DHT", torrent_start_DHT, METH_VARARGS, "."}, + {"stop_DHT", torrent_stop_DHT, METH_VARARGS, "."}, + {"get_DHT_info", torrent_get_DHT_info, METH_VARARGS, "."}, + {"create_torrent", torrent_create_torrent, METH_VARARGS, "."}, + {"reset_IP_filter", torrent_reset_IP_filter, METH_VARARGS, "."}, + {"add_range_to_IP_filter", torrent_add_range_to_IP_filter, METH_VARARGS, "."}, + {"use_upnp", torrent_use_upnp, METH_VARARGS, "."}, + {"use_natpmp", torrent_use_natpmp, METH_VARARGS, "."}, + {"use_utpex", torrent_use_utpex, METH_VARARGS, "."}, + {"set_ratio", torrent_set_ratio, METH_VARARGS, "."}, + {"proxy_settings", torrent_proxy_settings, METH_VARARGS, "."}, + {"get_trackers", torrent_get_trackers, METH_VARARGS, "."}, + {"dump_trackers", torrent_dump_trackers, METH_VARARGS, "."}, + {"replace_trackers", torrent_replace_trackers, METH_VARARGS, "."}, + {"set_flp", torrent_set_flp, METH_VARARGS, "."}, + {"prioritize_files", torrent_prioritize_files, METH_VARARGS, "."}, + {"set_priv", torrent_set_priv, METH_VARARGS, "."}, + {"test_duplicate", torrent_test_duplicate, METH_VARARGS, "."}, {NULL} }; PyMODINIT_FUNC initdeluge_core(void) { Py_InitModule("deluge_core", deluge_core_methods); };