Variables to snake_case
This commit is contained in:
@ -3,37 +3,37 @@ import os
|
||||
from datetime import timedelta
|
||||
import json
|
||||
|
||||
from roughEdit.utils import strToTimedelta, escapeString, generateRegex
|
||||
from roughEdit.fileWriters import ffmpegCommand, mpvCommand
|
||||
from rough_edit.utils import str_to_timedelta, escape_string, generate_regex
|
||||
from rough_edit.file_writers import ffmpeg_command, mpv_command
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
baseDir = '../'
|
||||
subsDir = f"{baseDir}subs/"
|
||||
subs_dir = f"{baseDir}subs/"
|
||||
outDir = f"{baseDir}out/"
|
||||
|
||||
phrase = "I don't know"
|
||||
regex = generateRegex(phrase)
|
||||
regex = generate_regex(phrase)
|
||||
|
||||
paddingLeft = timedelta(seconds=3)
|
||||
paddingRight = timedelta(seconds=3)
|
||||
padding_left = timedelta(seconds=3)
|
||||
padding_right = timedelta(seconds=3)
|
||||
count = 0
|
||||
|
||||
with open('rip.sh', 'w') as ripFile:
|
||||
ripFile.write(f'rm {outDir}/*\nmpv\\\n')
|
||||
for filename in os.listdir(subsDir):
|
||||
subsFile = subsDir + filename
|
||||
with open(subsFile) as sample:
|
||||
with open('rip.sh', 'w') as rip_file:
|
||||
rip_file.write(f'rm {outDir}/*\nmpv\\\n')
|
||||
for filename in os.listdir(subs_dir):
|
||||
subs_file = subs_dir + filename
|
||||
with open(subs_file) as sample:
|
||||
results = re.findall(regex, sample.read())
|
||||
episodeNum = filename[:3]
|
||||
baseName = filename[3:-7]
|
||||
episode_num = filename[:3]
|
||||
base_name = filename[3:-7]
|
||||
|
||||
for result in results:
|
||||
print(filename)
|
||||
print(result)
|
||||
beg = strToTimedelta(result[0]) - paddingLeft
|
||||
end = strToTimedelta(result[-1]) + paddingRight
|
||||
ripFile.write(ffmpegCommand(episodeNum, beg, end, count, outDir, baseName))
|
||||
# ripFile.write(mpvCommand(episodeNumber, beg, end))
|
||||
beg = str_to_timedelta(result[0]) - padding_left
|
||||
end = str_to_timedelta(result[-1]) + padding_right
|
||||
# rip_file.write(ffmpeg_command(episode_num, beg, end, count, outDir, base_name))
|
||||
rip_file.write(mpv_command(episode_num, beg, end))
|
||||
count += 1
|
||||
ripFile.write('\techo Finished')
|
||||
rip_file.write('\techo Finished')
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
from roughEdit.utils import escapeString
|
||||
|
||||
|
||||
def mpvCommand(episodeNum, beg, end):
|
||||
return f' --\\` ../original/{episodeNum}* --start={beg} --end={end} --\\~\\\n'.replace('`', '{').replace('~', '}')
|
||||
|
||||
|
||||
def ffmpegCommand(episodeNum, beg, end, count, outDir, baseName):
|
||||
paddedCount = f'{count:06}'
|
||||
return f"""
|
||||
# {baseName}
|
||||
ffmpeg -i ../original/{episodeNum}* -ss {beg} -t {end-beg} -async 1 "{outDir}{paddedCount}{baseName}.mp4" -y
|
||||
"""
|
||||
13
rough_edit/file_writers.py
Executable file
13
rough_edit/file_writers.py
Executable file
@ -0,0 +1,13 @@
|
||||
from rough_edit.utils import escape_string
|
||||
|
||||
|
||||
def mpv_command(episode_num, beg, end):
|
||||
return f' --\\` ../original/{episode_num}* --start={beg} --end={end} --\\~\\\n'.replace('`', '{').replace('~', '}')
|
||||
|
||||
|
||||
def ffmpeg_command(episode_num, beg, end, count, outDir, base_name):
|
||||
padded_count = f'{count:06}'
|
||||
return f"""
|
||||
# {base_name}
|
||||
ffmpeg -i ../original/{episode_num}* -ss {beg} -t {end-beg} -async 1 "{outDir}{padded_count}{base_name}.mp4" -y
|
||||
"""
|
||||
@ -2,7 +2,7 @@ import os
|
||||
import re
|
||||
|
||||
|
||||
def checkConditions(line):
|
||||
def check_conditions(line):
|
||||
# tells if the line passes some regex comparasions
|
||||
conditions = [
|
||||
'^WEBVTT$',
|
||||
@ -17,11 +17,11 @@ def checkConditions(line):
|
||||
return True
|
||||
|
||||
|
||||
for fileName in os.listdir('../../subs'):
|
||||
print(fileName)
|
||||
with open(f'../../subs/{fileName}', 'r') as infile:
|
||||
with open(f'../../out-subs/{fileName}', 'w') as outfile:
|
||||
for file_name in os.listdir('../../subs'):
|
||||
print(file_name)
|
||||
with open(f'../../subs/{file_name}', 'r') as infile:
|
||||
with open(f'../../out-subs/{file_name}', 'w') as outfile:
|
||||
for line in infile:
|
||||
if checkConditions(line):
|
||||
if check_conditions(line):
|
||||
outfile.write(line)
|
||||
# .replace('\n', ''))
|
||||
@ -1,7 +1,7 @@
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
def stringToTimedelta(time):
|
||||
def string_to_timedelta(time):
|
||||
time = time.split(':')
|
||||
return timedelta(hours=int(time[0]), minutes=int(time[1]), seconds=int(time[2]))
|
||||
|
||||
@ -18,8 +18,8 @@ with open('rip2.sh') as file:
|
||||
|
||||
for d in data:
|
||||
print(d)
|
||||
d[1] = stringToTimedelta(d[1])
|
||||
d[2] = stringToTimedelta(d[2])
|
||||
d[1] = string_to_timedelta(d[1])
|
||||
d[2] = string_to_timedelta(d[2])
|
||||
|
||||
cur = timedelta(seconds=0)
|
||||
with open('rip3.sh', 'w') as outfile:
|
||||
@ -3,7 +3,7 @@ from datetime import timedelta
|
||||
import os
|
||||
|
||||
|
||||
def escapeString(string):
|
||||
def escape_string(string):
|
||||
# escapes chars like ' and &
|
||||
# strings I have to replace to make the * work
|
||||
for sign in [' ', "'", '"', '(', ')', '&']:
|
||||
@ -11,10 +11,10 @@ def escapeString(string):
|
||||
return string
|
||||
|
||||
|
||||
def strToTimedelta(string):
|
||||
def str_to_timedelta(string):
|
||||
# TODO later: change findall to get rid of those [0]s
|
||||
timeRegexFormat = r"(\d{2}):(\d{2}):(\d{2})\.(\d{3})"
|
||||
results = re.findall(timeRegexFormat, string)
|
||||
time_regex_format = r"(\d{2}):(\d{2}):(\d{2})\.(\d{3})"
|
||||
results = re.findall(time_regex_format, string)
|
||||
hours, minutes, seconds, milliseconds = results[0]
|
||||
return timedelta(hours=int(hours),
|
||||
minutes=int(minutes),
|
||||
@ -22,15 +22,15 @@ def strToTimedelta(string):
|
||||
milliseconds=int(milliseconds))
|
||||
|
||||
|
||||
def generateRegex(prase):
|
||||
praseArray = prase.split(" ")
|
||||
timeRegex = r"(\d{2}:\d{2}:\d{2}.\d{3})"
|
||||
outRegex = ""
|
||||
def generate_regex(prase):
|
||||
phrase_array = prase.split(" ")
|
||||
time_regex = r"(\d{2}:\d{2}:\d{2}.\d{3})"
|
||||
out_regex = ""
|
||||
|
||||
for word in praseArray:
|
||||
outRegex += f"<{timeRegex}><c> ({word})</c>"
|
||||
outRegex += f"<{timeRegex}>"
|
||||
for word in phrase_array:
|
||||
out_regex += f"<{time_regex}><c> ({word})</c>"
|
||||
out_regex += f"<{time_regex}>"
|
||||
|
||||
print(outRegex)
|
||||
return outRegex
|
||||
print(out_regex)
|
||||
return out_regex
|
||||
# regex = f"<{timeRegex}><c> ({text})</c><{timeRegex}><c> ({text})</c><{timeRegex}>"
|
||||
Reference in New Issue
Block a user