-
Notifications
You must be signed in to change notification settings - Fork 0
/
lrpi_convert.py
65 lines (58 loc) · 2.03 KB
/
lrpi_convert.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
#!/usr/bin/env python
# lrpi_convert.py
# traverse track folders, converting mlp files to .mp4 and creating empty .srt
# files if they don't exist
import os, commands
from os.path import abspath, join, isdir, splitext, exists
from os import system, chdir, walk, listdir
from shutil import copyfile
#MEDIA_DIR = "/media/usb/tracks"
MEDIA_DIR = "/Volumes/usbstick/tracks"
CONVERT_CMD = "ffmpeg -i %s %s"
SRT_TOUCH_CMD = "touch %s"
debug = True
def process_folder(target_dir):
print("\nConverting .mlp files in folder %s." % target_dir)
files = listdir(target_dir)
for f in files:
fn = join(MEDIA_DIR,target_dir,f)
if not isdir(f):
fp, fe = splitext(fn)
if fe.lower() == ".mlp":
mp4_fn = fp+".mp4"
# print(mp4_fn)
if not exists(mp4_fn):
#print(fp, fe)
cmd_mlp = CONVERT_CMD % (fn, mp4_fn)
print(cmd_mlp)
system(cmd_mlp)
else:
print("The MP4 file %s already exists." % mp4_fn)
srt_fn = fp+".srt"
# print(srt_fn)
if not exists(srt_fn):
cmd_srt = SRT_TOUCH_CMD % srt_fn
print(cmd_srt)
system(cmd_srt)
else:
print("The SRT file %s already exists." % srt_fn)
# #outfilename = join(abspath(target_dir),FILENAME)
# outfilename = FILENAME
# if debug: print(outfilename, json)
# filename = open(outfilename,'w')
# filename.write(json)
# filename.close()
# if target_dir == ".":
# cmd = RCLONE_COPY_CMD % (outfilename, "")
# else:
# cmd = RCLONE_COPY_CMD % (outfilename, join(target_dir,""))
# copyfile(outfilename, join(target_dir,FILENAME))
# print(cmd)
# system(cmd)
def main():
chdir(MEDIA_DIR)
for root, dirs, files in walk(".", topdown = False):
for name in dirs:
process_folder(name)
if __name__ == "__main__":
main()