Spaces:
Paused
Paused
| import os | |
| import requests | |
| from datetime import datetime, timedelta | |
| from moviepy.editor import VideoFileClip | |
| import streamlit as st | |
| from streamlit_option_menu import option_menu | |
| def format_number(number): | |
| if number < 1000: | |
| return str(number) | |
| elif number < 1000000: | |
| return f"{round(number / 1000)} ribu" | |
| elif number < 1000000000: | |
| return f"{round(number / 1000000)} juta" | |
| else: | |
| return f"{round(number / 1000000000)} miliar" | |
| def cut_video(filename, judul_video, start_time, end_time): | |
| start_time_parts = start_time_str.split(':') | |
| end_time_parts = end_time_str.split(':') | |
| start_time_seconds = int(start_time_parts[0]) * 3600 + int(start_time_parts[1]) * 60 + float(start_time_parts[2]) | |
| end_time_seconds = int(end_time_parts[0]) * 3600 + int(end_time_parts[1]) * 60 + float(end_time_parts[2]) | |
| potong = "/home/user/app/Hasil Potong" | |
| if not os.path.exists(potong): | |
| os.makedirs(potong) | |
| output_file_path = f'{potong}/{judul_video}.mp4' | |
| with VideoFileClip(filename) as video: | |
| subclip = video.subclip(start_time_seconds, end_time_seconds) | |
| subclip.write_videofile(output_file_path) | |
| return output_file_path | |
| def session(video_info, video_file, cut): | |
| st.session_state.video_info = video_info | |
| st.session_state.video_file = video_file | |
| if cut: | |
| hasil = "Hasil Potongan " | |
| else: | |
| hasil = "" | |
| if 'video_info' in st.session_state: | |
| num_lines = st.session_state.video_info.count('\n') + 1 | |
| text_area_height = 25 * num_lines | |
| st.text_area("Informasi Video", st.session_state.video_info, height=text_area_height) | |
| st.video(st.session_state.video_file) | |
| with open(st.session_state.video_file, 'rb') as f: | |
| file_contents = f.read() | |
| st.download_button( | |
| label=f"Download {hasil}Video", | |
| data=file_contents, | |
| file_name=st.session_state.video_file.replace('/home/user/app/Hasil Potong', '').title().replace('Mp4', 'mp4'), | |
| mime='application/octet-stream' | |
| ) | |