-
Notifications
You must be signed in to change notification settings - Fork 19
/
screens.py
executable file
·82 lines (66 loc) · 2.13 KB
/
screens.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Takes screenshots of a set of video files, and uploads them to an image host.
"""
from __future__ import print_function, unicode_literals, division, absolute_import
import logging
import argparse
import os
import files
import image_hosts
import config
image_host = image_hosts.ImageBam
files.set_log_file_name('screenshots.log')
# Set up the argument parser
parser = argparse.ArgumentParser(description='Takes screenshots of one or more video files, '
'and uploads them to an image host.')
parser.add_argument(
'file_list',
type=str,
metavar='video-file',
nargs='+',
help='file or directory containing the release'
)
parser.add_argument(
'-n',
'--num-screenshots',
type=int,
metavar='<number>',
dest='num_screenshots',
default=config.NUM_SCREENSHOTS,
help='number of screenshots to save and upload'
)
parser.add_argument(
'-U',
'--no-upload',
dest='upload',
default=True,
action='store_false',
help='do not upload; save screenshots and exit'
)
args = parser.parse_args()
for path in args.file_list:
if isinstance(path, bytes):
path = path.decode('utf-8')
logging.info('------------------------------------------------------------')
logging.info(os.path.basename(path))
logging.info('------------------------------------------------------------')
try:
screenshots = files.Screenshots(path)
screenshots.take(args.num_screenshots)
if args.upload:
screenshots.upload(
image_host=image_host,
delete_after_upload=config.DELETE_SCREENS_AFTER_UPLOAD,
)
logging.info('BBCode:\n' + screenshots.bbcode)
else:
for screenshot_path in screenshots.files:
logging.info(screenshot_path)
except (files.ScreenshotsError, image_hosts.ImageHostError) as e:
logging.error(e)
continue
except Exception:
logging.exception('An unexpected error occurred. Please report the following information to the developers:')
continue