Spaces:
Paused
Paused
Commit ·
b6af08b
1
Parent(s): 18cba5a
init!
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import os
|
| 2 |
-
import requests
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
from pytube import YouTube
|
| 5 |
from moviepy.editor import VideoFileClip
|
|
@@ -31,7 +30,17 @@ def download_youtube(url, nama_channel, new_name, extension):
|
|
| 31 |
return f'File berhasil diunduh dan disimpan di direktori:\n\n{filename}', filename
|
| 32 |
|
| 33 |
# Function to cut and save the video
|
| 34 |
-
def cut_video(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
start_time_parts = start_time_str.split(':')
|
| 36 |
end_time_parts = end_time_str.split(':')
|
| 37 |
start_time_seconds = int(start_time_parts[0]) * 3600 + int(start_time_parts[1]) * 60 + float(start_time_parts[2])
|
|
@@ -46,7 +55,7 @@ def cut_video(start_time_str, end_time_str, filename, judul_video):
|
|
| 46 |
subclip.write_videofile(output_file_path)
|
| 47 |
|
| 48 |
return output_file_path
|
| 49 |
-
|
| 50 |
def format_number(number):
|
| 51 |
if number < 1000:
|
| 52 |
return str(number)
|
|
@@ -56,20 +65,37 @@ def format_number(number):
|
|
| 56 |
return f"{round(number / 1000000)} juta"
|
| 57 |
else:
|
| 58 |
return f"{round(number / 1000000000)} miliar"
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
iface = gr.Interface(
|
| 66 |
fn=cut_video,
|
| 67 |
-
inputs=[
|
| 68 |
-
gr.inputs.Textbox(lines=1, label="Start Time (HH:MM:SS.MS)"),
|
| 69 |
-
gr.inputs.Textbox(lines=1, label="End Time (HH:MM:SS.MS)"),
|
| 70 |
-
gr.inputs.Textbox(lines=1, label="Original Video File Path"),
|
| 71 |
-
gr.inputs.Textbox(lines=1, label="Video Title"),
|
| 72 |
-
],
|
| 73 |
outputs=gr.outputs.File(label="Download Cut Video"),
|
| 74 |
title="YouTube Video Cutter",
|
| 75 |
description="Cut and download portions of YouTube videos.",
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
from datetime import datetime, timedelta
|
| 3 |
from pytube import YouTube
|
| 4 |
from moviepy.editor import VideoFileClip
|
|
|
|
| 30 |
return f'File berhasil diunduh dan disimpan di direktori:\n\n{filename}', filename
|
| 31 |
|
| 32 |
# Function to cut and save the video
|
| 33 |
+
def cut_video(link, start_time_str, end_time_str):
|
| 34 |
+
yt = YouTube(link)
|
| 35 |
+
stream = yt.streams.filter(progressive=True, resolution='720p').first()
|
| 36 |
+
|
| 37 |
+
if stream is None:
|
| 38 |
+
return "Maaf, resolusi yang Anda pilih tidak tersedia."
|
| 39 |
+
|
| 40 |
+
nama_channel = yt.author
|
| 41 |
+
judul_video = yt.title.replace('/', ' ')
|
| 42 |
+
filename = download_youtube(stream.url, nama_channel, judul_video, 'mp4')
|
| 43 |
+
|
| 44 |
start_time_parts = start_time_str.split(':')
|
| 45 |
end_time_parts = end_time_str.split(':')
|
| 46 |
start_time_seconds = int(start_time_parts[0]) * 3600 + int(start_time_parts[1]) * 60 + float(start_time_parts[2])
|
|
|
|
| 55 |
subclip.write_videofile(output_file_path)
|
| 56 |
|
| 57 |
return output_file_path
|
| 58 |
+
|
| 59 |
def format_number(number):
|
| 60 |
if number < 1000:
|
| 61 |
return str(number)
|
|
|
|
| 65 |
return f"{round(number / 1000000)} juta"
|
| 66 |
else:
|
| 67 |
return f"{round(number / 1000000000)} miliar"
|
| 68 |
+
|
| 69 |
+
link = gr.inputs.Textbox(lines=1, label="Input Link Youtube")
|
| 70 |
+
yt = YouTube(link)
|
| 71 |
+
|
| 72 |
+
nama_channel = yt.author
|
| 73 |
+
judul_video = yt.title.replace('/', ' ')
|
| 74 |
+
tanggal_upload = yt.publish_date.strftime("%-d %B %Y")
|
| 75 |
+
jumlah_viewer = format_number(yt.views)
|
| 76 |
+
selisih_hari = (datetime.now() - yt.publish_date).days
|
| 77 |
+
rata2_viewer_per_hari = format_number(int(yt.views if selisih_hari < 1 else yt.views / selisih_hari))
|
| 78 |
+
durasi_video = str(timedelta(seconds=yt.length))
|
| 79 |
+
|
| 80 |
+
print("Nama Channel:", nama_channel)
|
| 81 |
+
print("Judul Video:", judul_video)
|
| 82 |
+
print("Tanggal Upload:", tanggal_upload)
|
| 83 |
+
print("Jumlah Viewer:", jumlah_viewer)
|
| 84 |
+
print("Rata-rata Viewer per Hari:", rata2_viewer_per_hari)
|
| 85 |
+
print("Durasi Video:", durasi_video)
|
| 86 |
+
|
| 87 |
+
resolusi_tersedia = [stream.resolution for stream in yt.streams.filter(progressive=True)]
|
| 88 |
+
print("Resolusi yang tersedia:", ", ".join(resolusi_tersedia))
|
| 89 |
+
|
| 90 |
+
resolusi_input = gr.inputs.Dropdown(choices=resolusi_tersedia, label="Pilih Resolusi")
|
| 91 |
+
start_time_input = gr.inputs.Textbox(lines=1, label="Start Time (HH:MM:SS.MS)")
|
| 92 |
+
end_time_input = gr.inputs.Textbox(lines=1, label="End Time (HH:MM:SS.MS)")
|
| 93 |
+
|
| 94 |
+
cut_button = gr.outputs.Button(label="Cut Video")
|
| 95 |
|
| 96 |
iface = gr.Interface(
|
| 97 |
fn=cut_video,
|
| 98 |
+
inputs=[link, start_time_input, end_time_input, cut_button],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
outputs=gr.outputs.File(label="Download Cut Video"),
|
| 100 |
title="YouTube Video Cutter",
|
| 101 |
description="Cut and download portions of YouTube videos.",
|