-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_processor.py
81 lines (69 loc) · 2.78 KB
/
video_processor.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
import os
import helper
import logging
import datetime
from file_info import FileInfo
MP4 = '.mp4'
LOGGER = logging.getLogger()
class VideoProcessor():
def __init__(self):
self.writes = 0
self.skipped = 0
self.errors = 0
self.no_exif = 0
def scan_files(self, folder, destination, sort_option, mode):
# Relative or absolute path
if os.path.isdir(folder):
count_files = 0
if mode == 'r':
for folder, subs, files in os.walk(folder):
count = 0
if destination not in subs:
for file_name in files:
if count == 0:
print(folder)
count += 1
if helper.check_extension(file_name, MP4):
try:
self.process_file(
FileInfo(file_name, folder, destination), sort_option)
except:
raise
LOGGER.error(
"error on file! : " + file_name)
self.incr_errors()
count_files += 1
print('Found video files ' + str(count_files))
else:
files = [f for f in os.listdir(folder)
if helper.check_extension(file_name, MP4) or helper.check_jpeg_extension(file_name)]
for file_name in files:
try:
self.process_file(
FileInfo(file_name, folder, destination), sort_option)
except:
print("error on file! : " + file_name)
self.incr_errors()
count_files += 1
def process_file(self, file_info, sort_option):
"""
Look at the modified time
"""
video_orig_writeback = open(
str(file_info.current_folder + '/' + file_info.filename), 'rb')
video_file_orig = video_orig_writeback.read()
video_orig_writeback.close()
time = os.path.getmtime(
file_info.current_folder + "\\" + file_info.filename)
date = datetime.datetime.fromtimestamp(
time).strftime('%Y-%m-%d %H:%M:%S')
file_name = helper.create_filename_for_file(
sort_option, MP4[1:], date)
helper.write_file(file_name, file_info.destination + "\\", video_file_orig)
self.incr_writes()
def incr_errors(self):
self.errors += 1
def incr_skipped(self):
self.skipped += 1
def incr_writes(self):
self.writes += 1