Accept a single file as parameter to parse
This commit is contained in:
parent
e4d9dfe1ae
commit
3a879b042c
|
@ -47,23 +47,25 @@ if __name__ == '__main__':
|
|||
sys.argv.remove('--' + option)
|
||||
if len(sys.argv) <= 1 or len(sys.argv) > 2:
|
||||
raise IndexError
|
||||
scanpath = sys.argv[-1]
|
||||
scan_path = sys.argv[-1]
|
||||
if os.name == 'nt':
|
||||
if not scanpath[-1] == '\\':
|
||||
scanpath += '\\'
|
||||
scanpath = scanpath.replace('\\', '\\\\')
|
||||
if not scan_path[-1] == '\\' and os.path.isdir(scan_path):
|
||||
scan_path += '\\'
|
||||
scan_path = scan_path.replace('\\', '\\')
|
||||
else:
|
||||
if not scanpath[-1] == '/':
|
||||
scanpath += '/'
|
||||
if not scan_path[-1] == '/' and os.path.isdir(scan_path):
|
||||
scan_path += '/'
|
||||
except IndexError:
|
||||
print('Not enough parameters.\n Usage: {} [--short|--files] <directory>'.format(sys.argv[0]))
|
||||
print('Not enough parameters.\n Usage: {} [--short|--files] <directory|filename>'.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)
|
||||
if os.path.isdir(scan_path):
|
||||
for index, torrentfile in enumerate(glob.glob(scan_path + '*.torrent')):
|
||||
parse_torrent_file(torrentfile)
|
||||
try:
|
||||
print('Found {} .torrent files.'.format(index+1))
|
||||
except NameError:
|
||||
print('No valid files found.')
|
||||
sys.exit(1)
|
||||
else:
|
||||
parse_torrent_file(scan_path)
|
||||
|
|
Loading…
Reference in New Issue