Spaces:
Paused
Paused
Commit ·
784ea8a
1
Parent(s): 1ecfaff
Update youtube.py
Browse files- youtube.py +2 -28
youtube.py
CHANGED
|
@@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
|
| 4 |
from pytube import YouTube
|
| 5 |
from moviepy.editor import VideoFileClip
|
| 6 |
from tqdm import tqdm
|
|
|
|
| 7 |
|
| 8 |
def download_youtube(url, nama_channel, new_name, extension):
|
| 9 |
response = requests.get(url, stream=True)
|
|
@@ -27,16 +28,6 @@ def download_youtube(url, nama_channel, new_name, extension):
|
|
| 27 |
print("")
|
| 28 |
|
| 29 |
return filename
|
| 30 |
-
|
| 31 |
-
def format_number(number):
|
| 32 |
-
if number < 1000:
|
| 33 |
-
return str(number)
|
| 34 |
-
elif number < 1000000:
|
| 35 |
-
return f"{round(number / 1000)} ribu"
|
| 36 |
-
elif number < 1000000000:
|
| 37 |
-
return f"{round(number / 1000000)} juta"
|
| 38 |
-
else:
|
| 39 |
-
return f"{round(number / 1000000000)} miliar"
|
| 40 |
|
| 41 |
def yt_down(link, resolusi_input, start_time_str, end_time_str):
|
| 42 |
video_info = ""
|
|
@@ -68,21 +59,4 @@ def yt_down(link, resolusi_input, start_time_str, end_time_str):
|
|
| 68 |
else:
|
| 69 |
filename = download_youtube(stream.url, nama_channel, judul_video, 'mp4')
|
| 70 |
|
| 71 |
-
returm filename, judul_video, video_info
|
| 72 |
-
|
| 73 |
-
def yt_cut(link, resolusi_input, start_time_str, end_time_str):
|
| 74 |
-
filename, judul_video, video_info = yt_down(link, resolusi_input, start_time_str, end_time_str)
|
| 75 |
-
start_time_parts = start_time_str.split(':')
|
| 76 |
-
end_time_parts = end_time_str.split(':')
|
| 77 |
-
start_time_seconds = int(start_time_parts[0]) * 3600 + int(start_time_parts[1]) * 60 + float(start_time_parts[2])
|
| 78 |
-
end_time_seconds = int(end_time_parts[0]) * 3600 + int(end_time_parts[1]) * 60 + float(end_time_parts[2])
|
| 79 |
-
potong = "/home/user/app/Hasil Potong"
|
| 80 |
-
if not os.path.exists(potong):
|
| 81 |
-
os.makedirs(potong)
|
| 82 |
-
output_file_path = f'{potong}/{judul_video}.mp4'
|
| 83 |
-
|
| 84 |
-
with VideoFileClip(filename) as video:
|
| 85 |
-
subclip = video.subclip(start_time_seconds, end_time_seconds)
|
| 86 |
-
subclip.write_videofile(output_file_path)
|
| 87 |
-
|
| 88 |
-
return video_info, output_file_path
|
|
|
|
| 4 |
from pytube import YouTube
|
| 5 |
from moviepy.editor import VideoFileClip
|
| 6 |
from tqdm import tqdm
|
| 7 |
+
from other import format_number
|
| 8 |
|
| 9 |
def download_youtube(url, nama_channel, new_name, extension):
|
| 10 |
response = requests.get(url, stream=True)
|
|
|
|
| 28 |
print("")
|
| 29 |
|
| 30 |
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def yt_down(link, resolusi_input, start_time_str, end_time_str):
|
| 33 |
video_info = ""
|
|
|
|
| 59 |
else:
|
| 60 |
filename = download_youtube(stream.url, nama_channel, judul_video, 'mp4')
|
| 61 |
|
| 62 |
+
returm filename, judul_video, video_info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|