Torrent creation fixes in regards to web seeds

Fix adding torrent to session after creation by setting the proper download location
This commit is contained in:
Andrew Resch 2009-06-08 21:57:02 +00:00
parent 95cd5e4932
commit ff25a7e969
3 changed files with 44 additions and 24 deletions

View File

@ -616,7 +616,7 @@ class Core(component.Component):
@export @export
def create_torrent(self, path, tracker, piece_length, comment, target, 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..") log.debug("creating torrent..")
threading.Thread(target=_create_torrent_thread, threading.Thread(target=_create_torrent_thread,
@ -626,15 +626,14 @@ class Core(component.Component):
piece_length, piece_length,
comment, comment,
target, target,
url_list, webseeds,
private, private,
created_by, created_by,
httpseeds,
trackers, trackers,
add_to_session)).start() add_to_session)).start()
def _create_torrent_thread(self, path, tracker, piece_length, comment, target, 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 import deluge.metafile
deluge.metafile.make_meta_file( deluge.metafile.make_meta_file(
path, path,
@ -642,10 +641,9 @@ class Core(component.Component):
piece_length, piece_length,
comment=comment, comment=comment,
target=target, target=target,
url_list=url_list, webseeds=webseeds,
private=private, private=private,
created_by=created_by, created_by=created_by,
httpseeds=httpseeds,
trackers=trackers) trackers=trackers)
log.debug("torrent created!") log.debug("torrent created!")
if add_to_session: if add_to_session:

View File

@ -57,8 +57,8 @@ def dummy(v):
def make_meta_file(path, url, piece_length, progress=dummy, def make_meta_file(path, url, piece_length, progress=dummy,
title=None, comment=None, safe=None, content_type=None, title=None, comment=None, safe=None, content_type=None,
target=None, url_list=None, name=None, private=False, target=None, webseeds=None, name=None, private=False,
created_by=None, httpseeds=None, trackers=None): created_by=None, trackers=None):
data = {'creation date': int(gmtime())} data = {'creation date': int(gmtime())}
if url: if url:
data['announce'] = url.strip() data['announce'] = url.strip()
@ -77,20 +77,34 @@ def make_meta_file(path, url, piece_length, progress=dummy,
data['info'] = info data['info'] = info
if title: if title:
data['title'] = title data['title'] = title.encode("utf8")
if comment: if comment:
data['comment'] = comment data['comment'] = comment.encode("utf8")
if safe: 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: if url_list:
data['url-list'] = url_list data['url-list'] = url_list
if created_by:
data['created by'] = created_by
if httpseeds: if httpseeds:
data['httpseeds'] = httpseeds data['httpseeds'] = httpseeds
if created_by:
data['created by'] = created_by.encode("utf8")
if trackers: if trackers:
data['announce-list'] = trackers data['announce-list'] = trackers
data["encoding"] = "UTF-8"
h.write(bencode(data)) h.write(bencode(data))
h.close() h.close()

View File

@ -258,11 +258,22 @@ class CreateTorrentDialog:
# Get the path # Get the path
path = self.files_treestore[0][0] path = self.files_treestore[0][0]
# Get a list of trackers # Get a list of trackers
trackers = [t[1] for t in self.trackers_liststore] trackers = []
if len(trackers) == 0: if not len(self.trackers_liststore):
tracker = None tracker = None
else: 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 # Get a list of webseeds
webseeds = [] webseeds = []
b = self.glade.get_widget("textview_webseeds").get_buffer() b = self.glade.get_widget("textview_webseeds").get_buffer()
@ -288,10 +299,9 @@ class CreateTorrentDialog:
piece_length, piece_length,
comment, comment,
result, result,
None, webseeds,
private, private,
author, author,
webseeds,
trackers, trackers,
add_to_session) add_to_session)
@ -309,10 +319,9 @@ class CreateTorrentDialog:
self._on_create_torrent_progress, self._on_create_torrent_progress,
comment, comment,
result, result,
trackers, webseeds,
private, private,
author, author,
webseeds,
trackers, trackers,
add_to_session)).start() add_to_session)).start()
@ -320,7 +329,7 @@ class CreateTorrentDialog:
self.dialog.destroy() self.dialog.destroy()
def create_torrent(self, path, tracker, piece_length, progress, comment, target, 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 import deluge.metafile
deluge.metafile.make_meta_file( deluge.metafile.make_meta_file(
path, path,
@ -329,17 +338,16 @@ class CreateTorrentDialog:
progress=progress, progress=progress,
comment=comment, comment=comment,
target=target, target=target,
url_list=url_list, webseeds=webseeds,
private=private, private=private,
created_by=created_by, created_by=created_by,
httpseeds=httpseeds,
trackers=trackers) trackers=trackers)
self.glade.get_widget("progress_dialog").hide_all() self.glade.get_widget("progress_dialog").hide_all()
if add_to_session: if add_to_session:
client.core.add_torrent_file( client.core.add_torrent_file(
os.path.split(target)[-1], os.path.split(target)[-1],
base64.encodestring(open(target).read()), base64.encodestring(open(target).read()),
None) {"download_location": os.path.split(path)[0]})
def _on_create_torrent_progress(self, value, num_pieces): def _on_create_torrent_progress(self, value, num_pieces):
percent = float(value)/float(num_pieces) percent = float(value)/float(num_pieces)