VideoCutter / pornhub.py
GilbertClaus's picture
Update pornhub.py
3d3d1b5
raw
history blame
3.45 kB
import os
import requests
import subprocess
import youtube_dl
from datetime import datetime, timedelta
from moviepy.editor import VideoFileClip
def download_pornhub(url, resolusi, nama_channel, judul_video, extension):
download = f"/home/user/app/Hasil Download/Pornhub/{nama_channel}"
if not os.path.exists(download):
os.makedirs(download)
file_name = judul_video + "." + extension
filename = f'{download}/{file_name}'
subprocess.run(["youtube-dl", "-f", f"bestvideo[height<={resolusi}]+bestaudio/best[height<={resolusi}]", "-o", filename, url])
return filename
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 ph_down(url, resolusi_input, start_time_str, end_time_str):
video_info = ""
ydl_opts = {
'quiet': True,
'skip_download': True,
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(url, download=False)
if 'formats' in info_dict:
formats = info_dict['formats']
# Process formats here
else:
print('No formats available')
# Filter available formats
resolutions = []
for f in formats:
if 'p' in f['format_id']:
resolutions.append(f['format_id'])
nama_channel = info_dict['uploader']
judul_video = info_dict['title'].replace('/',' ').replace('\\',' ').title()
tanggal_upload = datetime.strptime(info_dict['upload_date'], '%Y%m%d').strftime('%-d %B %Y')
jumlah_viewer = format_number(info_dict['view_count'])
selisih_hari = (datetime.now() - datetime.strptime(info_dict['upload_date'], '%Y%m%d')).days
rata2_viewer_per_hari = format_number(int(info_dict['view_count'] if selisih_hari < 1 else info_dict['view_count'] / selisih_hari))
durasi_video = str(timedelta(seconds=info_dict['duration']))
video_info += f"Nama Channel: {nama_channel}\n"
video_info += f"Judul Video: {judul_video}\n"
video_info += f"Tanggal Upload: {tanggal_upload}\n"
video_info += f"Jumlah Viewer: {jumlah_viewer}\n"
video_info += f"Rata-rata Viewer per Hari: {rata2_viewer_per_hari}\n"
video_info += f"Durasi Video: {durasi_video}\n"
video_info += f"Resolusi yang tersedia: {', '.join(resolutions)}\n"
filename = download_pornhub(url, resolusi, nama_channel, judul_video, 'mp4')
return filename, judul_video, video_info
def ph_cut(url, resolusi_input, start_time_str, end_time_str):
filename, judul_video, video_info = ph_down(url, resolusi_input, start_time_str, end_time_str)
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 video_info, output_file_path