예제 #1
0
def main(args, options):
  if len(args) != 1:
    app.help()

  torrent = Torrent.from_file(args[0])

  print('Torrent: %s' % args[0])
  print('Announce url: %s' % torrent.announce)

  print('Metainfo:')
  files = list(torrent.info.files(rooted_at=''))
  print('  name: %s' % torrent.info.name)
  print('  size: %d' % torrent.info.length)
  print('  files: %d' % len(files))
  print('  pieces: %d' % torrent.info.num_pieces)
  print('  piece size: %d' % torrent.info.piece_size)
  print()

  print('Hash manifest:')
  for index, hash in enumerate(torrent.info.piece_hashes):
    print('   [%4d]: %s' % (index, binascii.hexlify(hash)))
  print()

  print('File manifest:')
  for mif in files:
    print('  offset: [%9d-%9d] size: [%9d] filename: %s' % (mif.start, mif.end, mif.length, mif.name))
예제 #2
0
def main(args, options):
    if len(args) <= 2:
        app.help()

    torrent_name, tracker = args[0:2]

    filelist = []

    def add_file(filename):
        print("Adding %s" % filename)
        filelist.append(os.path.realpath(filename))

    def add_dir(dirname):
        for root, _, files in os.walk(dirname):
            for filename in files:
                add_file(os.path.join(root, filename))

    def add(file_or_dir):
        if os.path.isfile(file_or_dir):
            add_file(file_or_dir)
        elif os.path.isdir(file_or_dir):
            add_dir(file_or_dir)
        else:
            app.error("Unknown or non-existent file: %s" % file_or_dir)

    for path in args[2:]:
        add(path)

    if options.relpath:
        relpath = os.path.realpath(options.relpath)
    else:
        relpath = os.path.realpath(".")

    mib = MetaInfoBuilder(filelist, relpath=relpath)
    torrent = Torrent.from_metainfo(mib.build(), tracker)

    print("Writing torrent to file: %s" % torrent_name)
    torrent.to_file(torrent_name)