Spaces:
Paused
Paused
| import os | |
| import requests | |
| import subprocess | |
| import sys | |
| import youtube_dl | |
| from datetime import datetime, timedelta | |
| from moviepy import VideoFileClip | |
| from others import * | |
| def download_pornhub(url, resolusi, nama_channel, judul_video): | |
| download = f"/home/user/app/Hasil Download/Pornhub/{nama_channel}" | |
| if not os.path.exists(download): | |
| os.makedirs(download) | |
| file_name = judul_video + ".mp4" | |
| filename = f'{download}/{file_name}' | |
| subprocess.run(["youtube-dl", "--verbose", "-f", f"bestvideo[height<={resolusi}]+bestaudio/best[height<={resolusi}]", "-o", filename, url]) | |
| return filename | |
| def pornhub(url, resolusi_input): | |
| 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_input, nama_channel, judul_video) | |
| return filename, judul_video, video_info | |