From 856420c6401262b9832062ec178d018e554d4d2c Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sun, 2 Dec 2007 22:36:02 +0000 Subject: [PATCH] add web seeds to torrent creator --- plugins/TorrentCreator/__init__.py | 6 +- plugins/TorrentCreator/torrentcreator.glade | 166 +++++++++++++------- src/core.py | 4 +- src/deluge_core.cpp | 19 ++- 4 files changed, 132 insertions(+), 63 deletions(-) diff --git a/plugins/TorrentCreator/__init__.py b/plugins/TorrentCreator/__init__.py index d0869fbbe..8ad62fae7 100644 --- a/plugins/TorrentCreator/__init__.py +++ b/plugins/TorrentCreator/__init__.py @@ -133,6 +133,10 @@ class TorrentCreator: trackers = self.glade.get_widget("trackers_textview").get_buffer() (start, end) = trackers.get_bounds() trackers = trackers.get_text(start, end).strip() + + webseeds = self.glade.get_widget("webseeds_textview").get_buffer() + (start, end) = webseeds.get_bounds() + webseeds = webseeds.get_text(start, end).strip() comments = self.glade.get_widget("comments_textview").get_buffer() (start, end) = comments.get_bounds() @@ -150,7 +154,7 @@ class TorrentCreator: # Create the torrent and add it to the queue if necessary if self.core.create_torrent(torrent, source, trackers, comments, - piece_size, author, set_private) == 1: + piece_size, author, set_private, webseeds) == 1: # Torrent was created successfully if add_torrent: # We need to add this torrent to the queue diff --git a/plugins/TorrentCreator/torrentcreator.glade b/plugins/TorrentCreator/torrentcreator.glade index b329a8186..c5206079d 100644 --- a/plugins/TorrentCreator/torrentcreator.glade +++ b/plugins/TorrentCreator/torrentcreator.glade @@ -1,6 +1,6 @@ - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -54,6 +54,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 GTK_SHADOW_NONE @@ -69,28 +70,17 @@ 2 2 - + True + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + This torrent will be made from a directory + Folder: + 0 + True + True - 1 - 2 - 1 - 2 - - - - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER - - - 1 - 2 - GTK_FILL @@ -112,17 +102,28 @@ - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - This torrent will be made from a directory - Folder: - 0 - True - True + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER + 1 + 2 + GTK_FILL + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + 1 + 2 + 1 + 2 @@ -150,6 +151,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 GTK_SHADOW_NONE @@ -169,22 +171,14 @@ 1 3 - + True + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - 5 - - - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 0 - Save Torrent File As: - - - GTK_FILL + 1 + 2 @@ -212,14 +206,22 @@ - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + 5 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + Save Torrent File As: + + - 1 - 2 + GTK_FILL @@ -269,6 +271,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 GTK_SHADOW_NONE @@ -311,10 +314,58 @@ 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + GTK_SHADOW_NONE + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + 12 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + GTK_RESIZE_QUEUE + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + GTK_WRAP_CHAR + False + + + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + <b>Web Seeds</b> + True + + + label_item + + + + + 3 + + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 GTK_SHADOW_NONE @@ -354,13 +405,14 @@ - 3 + 4 True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 GTK_SHADOW_NONE @@ -391,7 +443,7 @@ False - 4 + 5 @@ -416,17 +468,15 @@ - + True - True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Set Private Flag - 0 - True + The smaller the piece sizes, the more efficient the transfers will be, but the actual ".torrent" file will be larger + 0 + Piece Size: - 1 - 2 + @@ -451,15 +501,17 @@ - + True + True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - The smaller the piece sizes, the more efficient the transfers will be, but the actual ".torrent" file will be larger - 0 - Piece Size: + Set Private Flag + 0 + True - + 1 + 2 @@ -481,7 +533,7 @@ False False - 5 + 6 diff --git a/src/core.py b/src/core.py index 4debe19ac..75c1de307 100644 --- a/src/core.py +++ b/src/core.py @@ -1015,8 +1015,8 @@ Space:") + " " + nice_free) return ret def create_torrent(self, filename, source_directory, trackers, comments=None, - piece_size=32, author="Deluge", private=False): - return deluge_core.create_torrent(filename, source_directory, trackers, comments, piece_size, author, private) + piece_size=32, author="Deluge", private=False, webseeds=None): + return deluge_core.create_torrent(filename, source_directory, trackers, comments, piece_size, author, private, webseeds) # Creates/resets the IP filter list def reset_ip_filter(self): diff --git a/src/deluge_core.cpp b/src/deluge_core.cpp index 846a49fbe..0d13a6c21 100644 --- a/src/deluge_core.cpp +++ b/src/deluge_core.cpp @@ -1547,11 +1547,11 @@ static PyObject *torrent_create_torrent(PyObject *self, PyObject *args) //path::default_name_check(no_check); - char *destination, *comment, *creator_str, *input, *trackers; + char *destination, *comment, *creator_str, *input, *trackers, *webseeds; bool *priv; python_long piece_size; - if (!PyArg_ParseTuple(args, "ssssisb", - &destination, &input, &trackers, &comment, &piece_size, &creator_str, &priv)) + if (!PyArg_ParseTuple(args, "ssssisbs", + &destination, &input, &trackers, &comment, &piece_size, &creator_str, &priv, &webseeds)) return NULL; piece_size = piece_size * 1024; @@ -1582,6 +1582,19 @@ static PyObject *torrent_create_torrent(PyObject *self, PyObject *args) break; } + std::string stdWebseeds(webseeds); + unsigned long index2 = 0, next2 = stdWebseeds.find("\n"); + while (1 == 1) + { + t->add_url_seed(stdWebseeds.substr(index2, next2-index)); + index2 = next2 + 1; + if (next2 >= stdWebseeds.length()) + break; + next2 = stdWebseeds.find("\n", index2); + if (next2 == std::string::npos) + break; + } + int num = t->num_pieces(); std::vector buf(piece_size); for (int i = 0; i < num; ++i)