Advertisement
elirang

magnet2name.py

Jun 29th, 2019
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Description- Fetch torrents names from magnet URLs
  4.  
  5. import sys
  6. import time
  7. import libtorrent as lt
  8.  
  9. IFACE = "0.0.0.0"
  10. PORT = "6881"
  11.  
  12. if (len(sys.argv) != 2):
  13.     sys.stderr.write("Usage: {} filename/-\n".format(sys.argv[0]))
  14.     sys.exit(1)    :
  15.    
  16. if (sys.argv[1] == "-"):
  17.     r = sys.stdin.readlines()
  18. else:
  19.     f=open(sys.argv[1], "r")
  20.     r=f.readlines()
  21.    
  22. sess = lt.session({'listen_interfaces': IFACE + ':' + PORT})
  23.  
  24. spinner = ['-', '\\', '|', '/']
  25. spinner_pos = 0
  26.  
  27. for line in r:
  28.     if line == '\n':
  29.         continue
  30.    
  31.     line=line.rstrip()
  32.     h = sess.add_torrent({
  33.         'save_path': "./" ,
  34.         'info_hash': lt.parse_magnet_uri(line)['info_hash']
  35.         })
  36.     h.prioritize_files([0]*1000)
  37.     s = h.status()
  38.      
  39.     while True:
  40.         try:
  41.             print("\r" + h.torrent_file().name())
  42.             break
  43.         except:
  44.             sys.stdout.write("\r" +
  45.                     spinner[spinner_pos % len(spinner)])
  46.             sys.stdout.flush()
  47.             time.sleep(0.05)
  48.             spinner_pos = spinner_pos + 1
  49.             continue
  50.    
  51.     spinner_pos = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement