Prompt for user input has been moved out to a funtion. Reflecting changes of exception name to InsufficientNameError.

This commit is contained in:
2018-10-18 22:09:47 +02:00
parent 3833b59732
commit bac145c6a1

View File

@@ -1,37 +1,59 @@
#!usr/bin/env python3.6 #!usr/bin/env python3.6
from guessit import guessit
import click import click
from guessit import guessit
from core import scan_folder, moveHome from core import scan_folder, moveHome
from video import Video from video import Video
from exceptions import InsufficientInfoError from exceptions import InsufficientNameError
def moveHome(video):
print('Would have moved: {}'.format(video))
def tweet(video):
pass
def prompt(name):
manual_name = input("Insufficient name: '{}'\nInput name manually: ".format(name))
if manual_name is 'q':
assert KeyboardInterrupt
if manual_name is 's':
return None
return manual_name
@click.command() @click.command()
@click.argument('path') @click.argument('path')
def main(path): @click.option('--daemon', '-d', daemon)
videos, insufficient_info = scan_folder(path) def main(path, daemon):
# print('Sweet lemonade: {} {}'.format(videos, insufficient_info)) videos, insufficient_name = scan_folder(path)
for video in videos: for video in videos:
moveHome(video) moveHome(video)
while len(insufficient_info) >= 1: while len(insufficient_name) >= 1:
for file in insufficient_info: for file in insufficient_name:
supplementary_info = input("Insufficient info for match file: '{}'\nSupplementary info: ".format(file))
if supplementary_info is 'q':
exit(0)
if supplementary_info is 's':
insufficient_info.pop()
continue
try: try:
video = Video.fromguess(file, guessit(supplementary_info)) manual_name = prompt(file)
print(video)
moveHome(video) if manual_name is None:
insufficient_info.pop() insufficient_name.pop()
except InsufficientInfoError: continue
pass
try:
video = Video.fromguess(file, guessit(manual_name))
moveHome(video)
insufficient_name.pop()
except InsufficientNameError:
continue
except KeyboardInterrupt:
# Logger: Received interrupt, exiting parser.
# should the class objects be deleted ?
print('Interrupt detected. Exiting')
exit(0)
if __name__ == '__main__': if __name__ == '__main__':
main() main()