-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
34 lines (29 loc) · 853 Bytes
/
cli.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
from asciipy import VideoConverter, ImageConverter, GifConverter, ConverterConfig, __version__ as version
import sys
from PIL import UnidentifiedImageError
_help = f"""
asciipy {version}
Usage:
asciipy [input_file] [output_file] [width] (optional, default=80)
"""
def main():
try:
_input = sys.argv[1]
output = sys.argv[2]
except IndexError:
print(_help)
return
width = 80
if len(sys.argv) == 4:
width = int(sys.argv[3])
conf = ConverterConfig(width=width)
try:
GifConverter(conf).convert(_input, output)
except (UnidentifiedImageError, ValueError):
try:
ImageConverter(conf).convert(_input, output)
except UnidentifiedImageError:
VideoConverter(conf).convert(_input, output)
print('Done!')
if __name__ == "__main__":
main()