From ff25a7e9699fcc0720de184d237070d00072ae17 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 8 Jun 2009 21:57:02 +0000 Subject: [PATCH] Torrent creation fixes in regards to web seeds Fix adding torrent to session after creation by setting the proper download location --- deluge/core/core.py | 10 ++++----- deluge/metafile.py | 28 ++++++++++++++++++------ deluge/ui/gtkui/createtorrentdialog.py | 30 ++++++++++++++++---------- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index de38f9372..7257eb1a5 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -616,7 +616,7 @@ class Core(component.Component): @export def create_torrent(self, path, tracker, piece_length, comment, target, - url_list, private, created_by, httpseeds, trackers, add_to_session): + webseeds, private, created_by, trackers, add_to_session): log.debug("creating torrent..") threading.Thread(target=_create_torrent_thread, @@ -626,15 +626,14 @@ class Core(component.Component): piece_length, comment, target, - url_list, + webseeds, private, created_by, - httpseeds, trackers, add_to_session)).start() def _create_torrent_thread(self, path, tracker, piece_length, comment, target, - url_list, private, created_by, httpseeds, trackers, add_to_session): + webseeds, private, created_by, trackers, add_to_session): import deluge.metafile deluge.metafile.make_meta_file( path, @@ -642,10 +641,9 @@ class Core(component.Component): piece_length, comment=comment, target=target, - url_list=url_list, + webseeds=webseeds, private=private, created_by=created_by, - httpseeds=httpseeds, trackers=trackers) log.debug("torrent created!") if add_to_session: diff --git a/deluge/metafile.py b/deluge/metafile.py index 2918ebf45..f18849779 100644 --- a/deluge/metafile.py +++ b/deluge/metafile.py @@ -57,8 +57,8 @@ def dummy(v): def make_meta_file(path, url, piece_length, progress=dummy, title=None, comment=None, safe=None, content_type=None, - target=None, url_list=None, name=None, private=False, - created_by=None, httpseeds=None, trackers=None): + target=None, webseeds=None, name=None, private=False, + created_by=None, trackers=None): data = {'creation date': int(gmtime())} if url: data['announce'] = url.strip() @@ -77,20 +77,34 @@ def make_meta_file(path, url, piece_length, progress=dummy, data['info'] = info if title: - data['title'] = title + data['title'] = title.encode("utf8") if comment: - data['comment'] = comment + data['comment'] = comment.encode("utf8") if safe: - data['safe'] = safe + data['safe'] = safe.encode("utf8") + + httpseeds = [] + url_list = [] + + if webseeds: + for webseed in webseeds: + if webseed.endswith(".php"): + httpseeds.append(webseed) + else: + url_list.append(webseed) + if url_list: data['url-list'] = url_list - if created_by: - data['created by'] = created_by if httpseeds: data['httpseeds'] = httpseeds + if created_by: + data['created by'] = created_by.encode("utf8") + if trackers: data['announce-list'] = trackers + data["encoding"] = "UTF-8" + h.write(bencode(data)) h.close() diff --git a/deluge/ui/gtkui/createtorrentdialog.py b/deluge/ui/gtkui/createtorrentdialog.py index fb6a7e4b7..74e3d1bee 100644 --- a/deluge/ui/gtkui/createtorrentdialog.py +++ b/deluge/ui/gtkui/createtorrentdialog.py @@ -258,11 +258,22 @@ class CreateTorrentDialog: # Get the path path = self.files_treestore[0][0] # Get a list of trackers - trackers = [t[1] for t in self.trackers_liststore] - if len(trackers) == 0: + trackers = [] + if not len(self.trackers_liststore): tracker = None else: - tracker = trackers[0] + # Create a list of lists [[tier0, ...], [tier1, ...], ...] + for tier, tracker in self.trackers_liststore: + try: + tier_list = trackers[tier] + except IndexError: + trackers.insert(tier, []) + + trackers[tier].append(tracker) + + # Get the first tracker in the first tier + tracker = trackers[0][0] + # Get a list of webseeds webseeds = [] b = self.glade.get_widget("textview_webseeds").get_buffer() @@ -288,10 +299,9 @@ class CreateTorrentDialog: piece_length, comment, result, - None, + webseeds, private, author, - webseeds, trackers, add_to_session) @@ -309,10 +319,9 @@ class CreateTorrentDialog: self._on_create_torrent_progress, comment, result, - trackers, + webseeds, private, author, - webseeds, trackers, add_to_session)).start() @@ -320,7 +329,7 @@ class CreateTorrentDialog: self.dialog.destroy() def create_torrent(self, path, tracker, piece_length, progress, comment, target, - url_list, private, created_by, httpseeds, trackers, add_to_session): + webseeds, private, created_by, trackers, add_to_session): import deluge.metafile deluge.metafile.make_meta_file( path, @@ -329,17 +338,16 @@ class CreateTorrentDialog: progress=progress, comment=comment, target=target, - url_list=url_list, + webseeds=webseeds, private=private, created_by=created_by, - httpseeds=httpseeds, trackers=trackers) self.glade.get_widget("progress_dialog").hide_all() if add_to_session: client.core.add_torrent_file( os.path.split(target)[-1], base64.encodestring(open(target).read()), - None) + {"download_location": os.path.split(path)[0]}) def _on_create_torrent_progress(self, value, num_pieces): percent = float(value)/float(num_pieces)