text: import os
  import sys
  
  
  def bt2magnet(torrent_file):
      import bencodepy
      import hashlib
      import base64
      with open(torrent_file, 'rb') as f:
          b32hash = base64.b32encode(hashlib.sha1(bencodepy.encode(bencodepy.decode(f.read())[b'info'])).digest()).decode(
              "utf-8")
          return f'magnet:?xt=urn:btih:{b32hash}'
  
  
  if sys.argv[1] == '/d':
      parent = sys.argv[2]
      for name in os.listdir(parent):
          if name.endswith('.torrent') or name.endswith('.TORRENT'):
              print(bt2magnet(os.path.join(parent, name)))
  else:
      print(bt2magnet(sys.argv[1]))
  