aboutsummaryrefslogtreecommitdiff
path: root/modules/torrent.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-26 18:27:17 +0100
committerGravatar jesopo2018-09-26 18:27:17 +0100
commit51a52e2b0e54031cce5876f54d1d48c268b5441c (patch)
treea4c0e8e86c55aa701b06297d5b5a2ceebeaab60d /modules/torrent.py
parentAlso use docstrings to check if a command has help available, allow one-string (diff)
Switch to using @Utils.hook and docstrings for event hooks
Diffstat (limited to 'modules/torrent.py')
-rw-r--r--modules/torrent.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/torrent.py b/modules/torrent.py
new file mode 100644
index 00000000..fdc3221d
--- /dev/null
+++ b/modules/torrent.py
@@ -0,0 +1,49 @@
+#--ignore
+
+import tempfile, time
+import libtorrent
+
+def magnet(magnet):
+ #log.info("Opening session for link %s", url)
+
+ session = libtorrent.session()
+ session.add_extension('ut_metadata')
+ session.add_extension('ut_pex')
+ session.add_extension('metadata_transfer')
+ session.add_dht_router("router.utorrent.com", 6881)
+ session.add_dht_router("router.bittorrent.com", 6881)
+ session.add_dht_router("dht.transmissionbt.com", 6881)
+ session.add_dht_router("dht.aelitis.com", 6881)
+ session.start_dht()
+ session.start_lsd()
+ session.start_upnp()
+ session.start_natpmp()
+
+ params = {'save_path': "/dev/null", 'duplicate_is_error': True,
+ 'storage_mode': libtorrent.storage_mode_t(2), 'paused': False,
+ 'auto_managed': True}
+ handle = libtorrent.add_magnet_uri(session, magnet, params)
+
+ #log.info("Waiting metadata")
+ has_metadata = False
+ for i in range(10):
+ if handle.has_metadata():
+ print("yes!")
+ has_metadata = True
+ break
+ else:
+ time.sleep(1)
+ if not has_metadata:
+ print("no!")
+ #event["stderr"].write("Timed out getting magnet info")
+ return
+ session.pause()
+
+ #log.info("Metadata retrieved")
+ torrent_info = handle.get_torrent_info()
+ print(dir(torrent_info))
+
+ session.remove_torrent(handle)
+ #log.info("Torrent file saved to %s", file_path)
+
+magnet("magnet:?xt=urn:btih:ea5938cbb6176a675a3e71682faf9801b5b6116f")