Spaces:
Sleeping
Sleeping
modified the time converting part
Browse files
app.py
CHANGED
|
@@ -19,24 +19,22 @@ def delete_files(files):
|
|
| 19 |
print("files deleted")
|
| 20 |
|
| 21 |
def classify_input_format(input_string):
|
| 22 |
-
# check if the input string is empty
|
| 23 |
-
if not input_string:
|
| 24 |
-
return 0
|
| 25 |
-
|
| 26 |
# check if the input string is a valid time in the format HH:MM:SS
|
| 27 |
hhmmss_pattern = re.compile('^\d{1,2}:\d{1,2}:\d{1,2}$')
|
| 28 |
-
if hhmmss_pattern.match(input_string):
|
|
|
|
| 29 |
return HHMMSS_to_sec(time_str=input_string)
|
| 30 |
|
| 31 |
# check if the input string is a valid number in the format of seconds
|
| 32 |
try:
|
| 33 |
seconds = float(input_string)
|
|
|
|
| 34 |
return float(input_string)
|
| 35 |
except ValueError:
|
| 36 |
pass
|
| 37 |
|
| 38 |
# if the input format is neither seconds nor HH:MM:SS, return None
|
| 39 |
-
|
| 40 |
|
| 41 |
def set_output_file(input_file, output_format, folder):
|
| 42 |
# Set output file name and extension
|
|
@@ -52,13 +50,16 @@ def set_output_file(input_file, output_format, folder):
|
|
| 52 |
def trim_video_helper(input_file, output_file, start_time, end_time):
|
| 53 |
if start_time == "":
|
| 54 |
start_time = 0
|
| 55 |
-
|
|
|
|
| 56 |
end_time = 300 + HHMMSS_to_sec(time_str=start_time)
|
|
|
|
|
|
|
| 57 |
# Trim the video
|
| 58 |
print("start trimming")
|
| 59 |
start_time = classify_input_format(start_time)
|
| 60 |
-
end_time = classify_input_format(end_time)
|
| 61 |
print("start time: ", start_time)
|
|
|
|
| 62 |
print("end time: ", end_time)
|
| 63 |
output_file = trim_media(input_file.name, output_file, start_time, end_time)
|
| 64 |
print("finish trimming")
|
|
|
|
| 19 |
print("files deleted")
|
| 20 |
|
| 21 |
def classify_input_format(input_string):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# check if the input string is a valid time in the format HH:MM:SS
|
| 23 |
hhmmss_pattern = re.compile('^\d{1,2}:\d{1,2}:\d{1,2}$')
|
| 24 |
+
if hhmmss_pattern.match(str(input_string)):
|
| 25 |
+
print("input string is a valid time in the format HH:MM:SS")
|
| 26 |
return HHMMSS_to_sec(time_str=input_string)
|
| 27 |
|
| 28 |
# check if the input string is a valid number in the format of seconds
|
| 29 |
try:
|
| 30 |
seconds = float(input_string)
|
| 31 |
+
print("input string is a valid number in the format of seconds")
|
| 32 |
return float(input_string)
|
| 33 |
except ValueError:
|
| 34 |
pass
|
| 35 |
|
| 36 |
# if the input format is neither seconds nor HH:MM:SS, return None
|
| 37 |
+
gradio.Error("Input format not supported. Please enter a valid time in the format HH:MM:SS or seconds.")
|
| 38 |
|
| 39 |
def set_output_file(input_file, output_format, folder):
|
| 40 |
# Set output file name and extension
|
|
|
|
| 50 |
def trim_video_helper(input_file, output_file, start_time, end_time):
|
| 51 |
if start_time == "":
|
| 52 |
start_time = 0
|
| 53 |
+
end_time = 300
|
| 54 |
+
elif start_time != "" and end_time == "":
|
| 55 |
end_time = 300 + HHMMSS_to_sec(time_str=start_time)
|
| 56 |
+
print("start time: ", start_time)
|
| 57 |
+
print("end time: ", end_time)
|
| 58 |
# Trim the video
|
| 59 |
print("start trimming")
|
| 60 |
start_time = classify_input_format(start_time)
|
|
|
|
| 61 |
print("start time: ", start_time)
|
| 62 |
+
end_time = classify_input_format(end_time)
|
| 63 |
print("end time: ", end_time)
|
| 64 |
output_file = trim_media(input_file.name, output_file, start_time, end_time)
|
| 65 |
print("finish trimming")
|