GilbertClaus commited on
Commit
4470ece
·
1 Parent(s): 5b2dd83

Create pornhub.py

Browse files
Files changed (1) hide show
  1. pornhub.py +84 -0
pornhub.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import subprocess
4
+ import youtube_dl
5
+ from datetime import datetime, timedelta
6
+ from moviepy.editor import VideoFileClip
7
+
8
+ video_info = ""
9
+
10
+ def download_pornhub(url, resolusi, nama_channel, judul_video, extension):
11
+ download = f"/home/user/app/Hasil Download/Pornhub/{nama_channel}"
12
+ if not os.path.exists(download):
13
+ os.makedirs(download)
14
+ file_name = judul_video + "." + extension
15
+ filename = f'{download}/{file_name}'
16
+ subprocess.run(["youtube-dl", "-f", f"bestvideo[height<={resolusi}]+bestaudio/best[height<={resolusi}]", "-o", filename, url])
17
+ return filename
18
+
19
+ def format_number(number):
20
+ if number < 1000:
21
+ return str(number)
22
+ elif number < 1000000:
23
+ return f"{round(number / 1000)} ribu"
24
+ elif number < 1000000000:
25
+ return f"{round(number / 1000000)} juta"
26
+ else:
27
+ return f"{round(number / 1000000000)} miliar"
28
+
29
+ def ph_down(url, resolusi_input, start_time_str, end_time_str):
30
+
31
+ ydl_opts = {
32
+ 'quiet': True,
33
+ 'skip_download': True,
34
+ }
35
+
36
+ with youtube_dl.YoutubeDL(ydl_opts) as ydl:
37
+ info_dict = ydl.extract_info(url, download=False)
38
+ if 'formats' in info_dict:
39
+ formats = info_dict['formats']
40
+ # Process formats here
41
+ else:
42
+ print('No formats available')
43
+
44
+ # Filter available formats
45
+ resolutions = []
46
+ for f in formats:
47
+ if 'p' in f['format_id']:
48
+ resolutions.append(f['format_id'])
49
+
50
+ nama_channel = info_dict['uploader']
51
+ judul_video = info_dict['title'].replace('/',' ').replace('\\',' ').title()
52
+ tanggal_upload = datetime.strptime(info_dict['upload_date'], '%Y%m%d').strftime('%-d %B %Y')
53
+ jumlah_viewer = format_number(info_dict['view_count'])
54
+ selisih_hari = (datetime.now() - datetime.strptime(info_dict['upload_date'], '%Y%m%d')).days
55
+ rata2_viewer_per_hari = format_number(int(info_dict['view_count'] if selisih_hari < 1 else info_dict['view_count'] / selisih_hari))
56
+ durasi_video = str(timedelta(seconds=info_dict['duration']))
57
+
58
+ video_info += f"Nama Channel: {nama_channel}\n"
59
+ video_info += f"Judul Video: {judul_video}\n"
60
+ video_info += f"Tanggal Upload: {tanggal_upload}\n"
61
+ video_info += f"Jumlah Viewer: {jumlah_viewer}\n"
62
+ video_info += f"Rata-rata Viewer per Hari: {rata2_viewer_per_hari}\n"
63
+ video_info += f"Durasi Video: {durasi_video}\n"
64
+ video_info += f"Resolusi yang tersedia: {', '.join(resolutions)}\n"
65
+
66
+ filename = download_pornhub(url, resolusi, nama_channel, judul_video, 'mp4')
67
+ return filename, judul_video
68
+
69
+ def ph_cut(url, resolusi_input, start_time_str, end_time_str):
70
+ filename, judul_video = ph_down(url, resolusi_input, start_time_str, end_time_str)
71
+ start_time_parts = start_time_str.split(':')
72
+ end_time_parts = end_time_str.split(':')
73
+ start_time_seconds = int(start_time_parts[0]) * 3600 + int(start_time_parts[1]) * 60 + float(start_time_parts[2])
74
+ end_time_seconds = int(end_time_parts[0]) * 3600 + int(end_time_parts[1]) * 60 + float(end_time_parts[2])
75
+ potong = "/home/user/app/Hasil Potong"
76
+ if not os.path.exists(potong):
77
+ os.makedirs(potong)
78
+ output_file_path = f'{potong}/{judul_video}.mp4'
79
+
80
+ with VideoFileClip(filename) as video:
81
+ subclip = video.subclip(start_time_seconds, end_time_seconds)
82
+ subclip.write_videofile(output_file_path)
83
+
84
+ return video_info, output_file_path, output_file_path