Changed newline char

This commit is contained in:
jpk 2017-09-29 20:40:05 +02:00
parent 6739410172
commit e4d9dfe1ae
1 changed files with 69 additions and 44 deletions

113
pytorrentinfo.py Normal file → Executable file
View File

@ -1,44 +1,69 @@
#!/usr/bin/env python3
import sys
import os
import glob
from torrentool.api import Torrent
"""
'announce_urls', 'comment', 'create_from', 'created_by', 'creation_date', 'files', 'from_file', 'from_string',
'get_magnet', 'httpseeds', 'info_hash', 'magnet_link', 'name', 'private', 'to_file', 'to_string', 'total_size',
'webseeds']
"""
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))
try:
print('| Size : {} bytes'.format(torrent.total_size))
except:
print('| Size : {}'.format('n/a'))
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, True, False)
print('Found {} .torrent files.'.format(index+1))
#!/usr/bin/env python3
import sys
import os
import glob
from torrentool.api import Torrent
"""
'announce_urls', 'comment', 'create_from', 'created_by', 'creation_date', 'files', 'from_file', 'from_string',
'get_magnet', 'httpseeds', 'info_hash', 'magnet_link', 'name', 'private', 'to_file', 'to_string', 'total_size',
'webseeds']
"""
ARG_OPTIONS = {'short': False, 'files': False}
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))
try:
print('| Size : {} bytes'.format(torrent.total_size))
except:
print('| Size : {}'.format('n/a'))
if not ARG_OPTIONS['short']:
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 ARG_OPTIONS['files']:
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__':
try:
for option in ARG_OPTIONS.keys():
if '--' + option in sys.argv:
ARG_OPTIONS[option] = not ARG_OPTIONS[option]
sys.argv.remove('--' + option)
if len(sys.argv) <= 1 or len(sys.argv) > 2:
raise IndexError
scanpath = sys.argv[-1]
if os.name == 'nt':
if not scanpath[-1] == '\\':
scanpath += '\\'
scanpath = scanpath.replace('\\', '\\\\')
else:
if not scanpath[-1] == '/':
scanpath += '/'
except IndexError:
print('Not enough parameters.\n Usage: {} [--short|--files] <directory>'.format(sys.argv[0]))
sys.exit(1)
for index, torrentfile in enumerate(glob.glob(scanpath + '*.torrent')):
torrentfile = torrentfile.replace('\\', '\\')
parse_torrent_file(torrentfile)
try:
print('Found {} .torrent files.'.format(index+1))
except NameError:
print('No valid files found.')
sys.exit(1)