Spaces:
Paused
Paused
Commit ·
1ecfaff
1
Parent(s): 19f3a65
Create other.py
Browse files
other.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
from datetime import datetime, timedelta
|
| 4 |
+
from moviepy.editor import VideoFileClip
|
| 5 |
+
import streamlit as st
|
| 6 |
+
from streamlit_option_menu import option_menu
|
| 7 |
+
|
| 8 |
+
def format_number(number):
|
| 9 |
+
if number < 1000:
|
| 10 |
+
return str(number)
|
| 11 |
+
elif number < 1000000:
|
| 12 |
+
return f"{round(number / 1000)} ribu"
|
| 13 |
+
elif number < 1000000000:
|
| 14 |
+
return f"{round(number / 1000000)} juta"
|
| 15 |
+
else:
|
| 16 |
+
return f"{round(number / 1000000000)} miliar"
|
| 17 |
+
|
| 18 |
+
def cut_video(filename, judul_video, start_time, end_time):
|
| 19 |
+
start_time_parts = start_time_str.split(':')
|
| 20 |
+
end_time_parts = end_time_str.split(':')
|
| 21 |
+
start_time_seconds = int(start_time_parts[0]) * 3600 + int(start_time_parts[1]) * 60 + float(start_time_parts[2])
|
| 22 |
+
end_time_seconds = int(end_time_parts[0]) * 3600 + int(end_time_parts[1]) * 60 + float(end_time_parts[2])
|
| 23 |
+
potong = "/home/user/app/Hasil Potong"
|
| 24 |
+
if not os.path.exists(potong):
|
| 25 |
+
os.makedirs(potong)
|
| 26 |
+
output_file_path = f'{potong}/{judul_video}.mp4'
|
| 27 |
+
|
| 28 |
+
with VideoFileClip(filename) as video:
|
| 29 |
+
subclip = video.subclip(start_time_seconds, end_time_seconds)
|
| 30 |
+
subclip.write_videofile(output_file_path)
|
| 31 |
+
|
| 32 |
+
return output_file_path
|
| 33 |
+
|
| 34 |
+
def session(video_info, video_file, cut):
|
| 35 |
+
st.session_state.video_info = video_info
|
| 36 |
+
st.session_state.video_file = video_file
|
| 37 |
+
if cut:
|
| 38 |
+
hasil = "Hasil Potongan "
|
| 39 |
+
else:
|
| 40 |
+
hasil = ""
|
| 41 |
+
if 'video_info' in st.session_state:
|
| 42 |
+
num_lines = st.session_state.video_info.count('\n') + 1
|
| 43 |
+
text_area_height = 25 * num_lines
|
| 44 |
+
st.text_area("Informasi Video", st.session_state.video_info, height=text_area_height)
|
| 45 |
+
st.video(st.session_state.video_file)
|
| 46 |
+
with open(st.session_state.video_file, 'rb') as f:
|
| 47 |
+
file_contents = f.read()
|
| 48 |
+
st.download_button(
|
| 49 |
+
label=f"Download {hasil}Video",
|
| 50 |
+
data=file_contents,
|
| 51 |
+
file_name=st.session_state.video_file.replace('/home/user/app/Hasil Potong', '').title().replace('Mp4', 'mp4'),
|
| 52 |
+
mime='application/octet-stream'
|
| 53 |
+
)
|
| 54 |
+
|