Added option to print shortend output for torrent info

This commit is contained in:
Julian Knauer 2017-09-29 11:03:12 +02:00
parent 26f4c7de6b
commit 6739410172
1 changed files with 16 additions and 15 deletions

View File

@ -13,31 +13,32 @@ from torrentool.api import Torrent
"""
def parse_torrent_file(torrentfile, list_contents=True):
def parse_torrent_file(torrentfile, short_output=False, list_contents=True):
torrent = Torrent.from_file(torrentfile)
print('+- Torrent : {}'.format(os.path.basename(torrentfile)))
print('| Title : {}'.format(torrent.name))
print('| Comment : {}'.format(torrent.comment or 'n/a'))
try:
print('| Size : {} bytes'.format(torrent.total_size))
except:
print('| Size : {}'.format('n/a'))
print('| Created : {}'.format(torrent.creation_date or 'n/a'))
print('| Hash : {}'.format(torrent.info_hash))
if torrent.comment:
print('| Comment : {}'.format(torrent.comment))
if len(torrent.httpseeds) > 0:
print('| httpseeds: {}'.format(torrent.httpseeds))
if len(torrent.webseeds) > 0:
print('| webseeds : {}'.format(torrent.webseeds))
if list_contents:
for index, fileinfo in enumerate(torrent.files):
print('| FILE[{:4}] name = {}'.format(index, fileinfo[0]))
print('| FILE[{:4}] size = {}'.format(index, fileinfo[1]))
if not short_output:
print('| Comment : {}'.format(torrent.comment or 'n/a'))
print('| Created : {}'.format(torrent.creation_date or 'n/a'))
print('| Hash : {}'.format(torrent.info_hash))
if torrent.comment:
print('| Comment : {}'.format(torrent.comment))
if len(torrent.httpseeds) > 0:
print('| httpseeds: {}'.format(torrent.httpseeds))
if len(torrent.webseeds) > 0:
print('| webseeds : {}'.format(torrent.webseeds))
if list_contents:
for index, fileinfo in enumerate(torrent.files):
print('| FILE[{:4}] name = {}'.format(index, fileinfo[0]))
print('| FILE[{:4}] size = {}'.format(index, fileinfo[1]))
if __name__ == '__main__':
for index, torrentfile in enumerate(glob.glob('D:\\XWF\\CASE\\EY_MAIN_DRAG\\MAIN DRAG Teil 2\\ASS20_HDD01, P1\\Ex\\Documents and Settings\\Administrator\\Application Data\\Azureus\\active\\*.torrent')):
torrentfile = torrentfile.replace('\\', '\\')
parse_torrent_file(torrentfile, False)
parse_torrent_file(torrentfile, True, False)
print('Found {} .torrent files.'.format(index+1))