-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideoSystem.py
More file actions
118 lines (109 loc) · 4.08 KB
/
videoSystem.py
File metadata and controls
118 lines (109 loc) · 4.08 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#Last Updated: 8/26/17
import shutil
import sys
import os
import TBACommunicator
import pdb
import traceback
#Gets a list of matches to make a list of names
def getSchedule():
tbac = TBACommunicator.TBACommunicator()
return filter(lambda v: v['comp_level'] == 'qm', tbac.makeEventMatchesRequest())
#Creates a name for a video based on recording order, with the match number and team numbers
def getVideoKey(number):
match = filter(lambda m: m['match_number'] == number + 1, matches)[0]
print(matches[number]['match_number'])
key = list('Q' + str(match['match_number']) + '_')
teams = match['alliances']['red']['teams'] + match['alliances']['blue']['teams']
[key.append(str(number) + '_') for number in teams]
return ''.join(key)
#Moves all videos from the start folder to destination folder
def moveVids(folder, dest):
#Cannot move without a start folder and a destination folder
if not folder or not dest:
print('Error: Folders not set')
return
files = os.listdir(folder)
destFiles = os.listdir(dest)[1:]
#Sort files by creation time
files = sorted(files, key = lambda k: os.stat(folder + k).st_ctime)
#Start from the first match not in destination and move each subsequent file
if destFiles:
matchToStartFrom = len(destFiles)
files = files[matchToStartFrom:]
matchesToFiles = zip(range(matchToStartFrom, len(files) + matchToStartFrom), files)
[moveVid(getVideoKey(k), folder + fileName, dest) for k, fileName in matchesToFiles]
return
#Otherwise, move all files, starting from match 1
map(lambda n: moveVid(getVideoKey(n), folder + files[n], dest), range(len(files)))
#Skips specific videos from downloading
def skip(folder, dest, number):
files = os.listdir(folder)
destFiles = os.listdir(dest)[1:]
files = sorted(files, key = lambda k: os.stat(folder + k).st_ctime)
print(len(files[:number - 1]))
for f in files[:number - 1]:
moveVid(getVideoKey(files.index(f)), folder + f, dest)
print(files[number - 1:])
for f in files[number - 1:]:
moveVid(getVideoKey(files.index(f) + 1), folder + f, dest)
#Deletes the most recent match for a replay
def replayLastMatch(folder):
#Start folder and recorded match needed for replay
if not folder:
print('ERROR: Folders not set')
return
if not len(os.listdir(folder)):
print('ERROR: No match to replay')
return
files = os.listdir(folder)
#Delete the most recent video, to make room for the replay
files = sorted(files, key = lambda k: os.stat(folder + k).st_ctime)
fileToDelete = files[-1]
print(folder + fileToDelete)
os.remove(folder + fileToDelete)
#Moves a video from the original location to a new location with a new name
def moveVid(key, filePath, dest):
print(key)
print(filePath)
shutil.copy(filePath, dest + key + '.mov')
print('Downloading schedule...')
matches = getSchedule()
#If two folder locations were entered when starting, the first is the folder the videos start in and the second is the folder they move to
try:
videoFolder = sys.argv[1]
destFolder = sys.argv[2]
#Otherwise, the folder locations need to be entered later
except:
videoFolder = ''
destFolder = ''
print("Video system 2017. Type 'help' for a list of commands.")
#Loop looks for input and runs commands
while(True):
cmd = raw_input('>>> ').split()
if not cmd: continue
try:
if cmd[0] == 'setdest':
destFolder = cmd[1]
except:
print('Error: Must supply more arguments')
try:
if cmd[0] == 'setvid':
videoFolder = cmd[1]
except:
print('Error: Must supply more arguments')
if cmd[0] == 'replay':
replayLastMatch(videoFolder)
elif cmd[0] == 'done':
moveVids(videoFolder, destFolder)
elif cmd[0] == 'skip':
try:
skip(videoFolder, destFolder, int(cmd[1]))
except:
print(traceback.format_exc())
elif cmd[0] == 'help':
print('setdest [FILEPATH] - Reset the file path to which you want videos to be moved')
print('setvid [FILEPATH] - Reset the file path to which unnamed videos will be stored')
print('replay - Delete last recording (RUN THIS BEFORE RECORDING ANYTHING ELSE)')
print('done - Run the video mover and organize all video files by match (run at the end of the day)')
print('skip - Skip specific videos and folders from download')