Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -287,7 +287,27 @@ def write_srt(subtitle_text, output_file="edited_srt.srt"):
|
|
287 |
with open(output_file+".srt", 'w', encoding="utf-8") as file:
|
288 |
file.write(subtitle_text)
|
289 |
return output_file+".srt"
|
290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
def clean_text(text):
|
292 |
# Remove 'srt ' from the start of each line
|
293 |
# Remove ''' from the start and end
|
@@ -448,7 +468,7 @@ def process_video(video, url, type):
|
|
448 |
|
449 |
def video_edit(srt, input_video, input_audio= 'audio.mp3'):
|
450 |
input_video_name = input_video.replace(".mp4", "")
|
451 |
-
srt_name=
|
452 |
return input_video, srt_name
|
453 |
""" input_video_name = input_video.replace(''.mp4', '')
|
454 |
video = VideoFileClip(input_video)
|
|
|
287 |
with open(output_file+".srt", 'w', encoding="utf-8") as file:
|
288 |
file.write(subtitle_text)
|
289 |
return output_file+".srt"
|
290 |
+
|
291 |
+
def generate_translated_subtitle(language, segments, input_video_name):
|
292 |
+
subtitle_file = f"sub-{input_video_name}-{language}.srt"
|
293 |
+
text = ""
|
294 |
+
lines = segments.split('\n')
|
295 |
+
new_list = [item for item in lines if item != '']
|
296 |
+
segment_number = 1
|
297 |
+
|
298 |
+
for index, segment in enumerate(new_list):
|
299 |
+
if (index+1) % 3 == 1 or (index+1)==1:
|
300 |
+
text += f"{segment}\n"
|
301 |
+
segment_number += 1
|
302 |
+
if (index+1) % 3 == 2 or (index+1)==2:
|
303 |
+
text += segment + "\n"
|
304 |
+
if (index+1) % 3 == 0:
|
305 |
+
text += f"\u200F{segment}\n\n"
|
306 |
+
|
307 |
+
with open(subtitle_file, "w", encoding='utf8') as f:
|
308 |
+
f.write(text)
|
309 |
+
return subtitle_file
|
310 |
+
|
311 |
def clean_text(text):
|
312 |
# Remove 'srt ' from the start of each line
|
313 |
# Remove ''' from the start and end
|
|
|
468 |
|
469 |
def video_edit(srt, input_video, input_audio= 'audio.mp3'):
|
470 |
input_video_name = input_video.replace(".mp4", "")
|
471 |
+
srt_name=generate_translated_subtitle("fa", srt, input_video_name)
|
472 |
return input_video, srt_name
|
473 |
""" input_video_name = input_video.replace(''.mp4', '')
|
474 |
video = VideoFileClip(input_video)
|