-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstore_recordings.py
47 lines (37 loc) · 1.67 KB
/
store_recordings.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
'''
Copies trimmed recordings to the app's assets directory.
'''
import logging
import os
import os.path
import shutil
import progress
from recordings import Recording, SelectedRecording
from trim_recordings import TRIMMED_RECORDINGS_DIR
def add_args(parser):
parser.add_argument(
'--assets_recordings_dir',
default=os.path.join(os.path.dirname(__file__), '..', 'app', 'assets', 'sounds'),
help='Output directory for recordings to be included in app assets')
_args = None
def main(args, session):
logging.info('Loading selected recordings')
selected_recordings = session.query(Recording).join(SelectedRecording).all()
old_trimmed_recordings = os.listdir(args.assets_recordings_dir)
logging.info(f'Deleting {len(old_trimmed_recordings)} old trimmed recordings')
for old_trimmed_recording in old_trimmed_recordings:
try:
os.remove(os.path.join(args.assets_recordings_dir, old_trimmed_recording))
except OSError as ex:
logging.warning(f'Could not delete {old_trimmed_recording}: {ex}')
logging.info('Copying trimmed recordings')
for selected_recording in progress.percent(selected_recordings):
input_file_name = os.path.join(
TRIMMED_RECORDINGS_DIR,
f'{selected_recording.recording_id}.ogg')
# Android hates colons in file names in a really nonobvious way:
# https://stackoverflow.com/questions/52245654/failed-to-open-file-permission-denied
output_file_name = os.path.join(
args.assets_recordings_dir,
f'{selected_recording.recording_id.replace(":", "_")}.ogg')
shutil.copyfile(input_file_name, output_file_name)