-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (68 loc) · 3.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import argparse
from video_processor import VideoProcessor
from rename_image_prefix_date import RenameImagePrefixDate
from sort_images_to_folder import SortImagesToFolder
def main():
args = parse_arguments()
if args.mode == 'r':
if args.video:
video_processor = VideoProcessor()
sort_option = {'prefix': 'VIDEO', 'date_format': 0}
video_processor.scan_files(
args.input_path, args.output_path, sort_option, 'r')
else:
rename_image_prefix_date = RenameImagePrefixDate()
print(args.prefix)
print(args.output_path)
sort_option = {'prefix': args.prefix, 'date_format': 0}
rename_image_prefix_date.walk_images(
args.input_path, args.output_path, sort_option, 'r')
elif args.mode == 's':
folder = input("Give a folder containing images..\n")
destination = input("Give a destination for the ordered folders..\n")
answer = ''
result = 0
result, answer = get_sorting_option("Order by year? y/n \n", 2)
result, answer = get_sorting_option(
"Order by year and month? y/n \n", 1, answer, result)
result, answer = get_sorting_option(
"Order by year,month and day? y/n \n", 0, answer, result)
mode, answer = get_sorting_option("Recursively ? y/n \n", 'r')
sort_images_to_folder = SortImagesToFolder()
sort_images_to_folder.walk_images(folder, destination, result, mode)
def parse_arguments():
parser = argparse.ArgumentParser(
description='Sort files on exif date info, or rename them.')
parser.add_argument('-o', dest="output_path", action="store",
default="", help='The absolute directory to output the files to.')
parser.add_argument('-i', dest="input_path", action="store", default=".",
help='the path to read input from, defaults to current folder')
parser.add_argument('-mode', dest="mode", action="store", default="s",
help=" 's' => Sort, 'r' => Rename, default = Sort")
parser.add_argument('--video', dest="video", action="store_true", default="false",
help="Looks at modified time of video file")
parser.add_argument('--prefix', action="store",
dest="prefix", default="IMAGE", help='Default prefix is IMAGE or VIDEO if --video is given'
'\n e.g PREFIX_DATE -> IMAGE_20160111')
parser.add_argument('--verbose', action="store_true",
dest="verbose", help='Display all actions')
args = parser.parse_args()
return args
def get_sorting_option(question, res, prev_ans=None, prev_res=None):
result = 0
if prev_ans != None and prev_res != None:
if prev_ans != 'n': # stop followup
return prev_res, 'y'
while True:
answer = input(question)
if answer not in "yn":
print("Enter y or n")
continue
if answer == 'y':
result = res
break
else:
break
return result, answer
if __name__ == '__main__':
main()