-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
174 lines (150 loc) · 6.65 KB
/
Copy pathmain.py
File metadata and controls
174 lines (150 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import os
import traceback
import wget
import time
from urllib.parse import unquote
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager # type: ignore
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from bs4 import BeautifulSoup
import requests
import os
proxy_user = "celengspeed"
proxy_pass = "celengspeed"
proxy_host = "103.197.190.122"
proxy_port = "1080"
socks_proxy = f"socks5h://{proxy_user}:{proxy_pass}@{proxy_host}:{proxy_port}"
# --- Requests ---
proxies = {
"http": socks_proxy,
"https": socks_proxy,
}
def download_video(url: str, save_path: str = "video.mp4"):
try:
# request dengan stream=True biar tidak boros RAM
with requests.get(url, stream=True, timeout=20, proxies=proxies) as r:
print("status", r)
r.raise_for_status()
total_size = int(r.headers.get("content-length", 0))
# bikin folder kalau belum ada
os.makedirs(os.path.dirname(save_path) or ".", exist_ok=True)
with open(save_path, "wb") as f:
downloaded = 0
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
downloaded += len(chunk)
done = int(50 * downloaded / total_size) if total_size else 0
print(f"\r[{'█' * done}{'.' * (50-done)}] {downloaded}/{total_size} bytes", end="")
print(f"\n✅ Download selesai: {save_path}")
return save_path
except Exception as e:
print(f"❌ Gagal download: {e}")
return None
def KillPid():
try:
# Kill Chrome dan Chromedriver di Windows
os.system("taskkill /F /IM chrome.exe /T")
os.system("taskkill /F /IM chromedriver.exe /T")
except:
pass
class VHtearDriver:
def __init__(self):
self.options = Options()
# Lokasi default Chrome di Windows
self.options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
if not os.path.exists(self.options.binary_location):
self.options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
#self.options.add_argument('--headless=new')
self.options.add_argument('--disable-gpu')
self.options.add_argument('--disable-software-rasterizer')
self.options.add_argument('--disable-dev-shm-usage')
self.options.add_argument('--disable-extensions')
self.options.add_argument('--disable-logging')
self.options.add_argument('--log-level=3')
self.options.add_argument('--silent')
self.service = Service(ChromeDriverManager().install())
def youtubeDownload(self, youtube_url):
self.driver = webdriver.Chrome(service=self.service, options=self.options)
dataNE = {}
try:
self.driver.get("https://yt-mp4.org/")
input_form = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located(
(By.CSS_SELECTOR, 'input[placeholder="Enter YouTube URL here..."]')
)
)
input_form.clear()
input_form.send_keys(youtube_url)
button = WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable(
(By.XPATH, '//button[contains(text(), "Fetch Video")]')
)
)
button.click()
for i in range(30):
try:
download_section = self.driver.find_element(By.ID, "downloadSection")
print("✅ Download section muncul!")
break
except NoSuchElementException:
print(f"⏳ Belum muncul... ({i+1})")
time.sleep(0.5)
else:
raise Exception("❌ Download section tidak muncul dalam 30 detik")
for i in range(30):
try:
get_link_button = self.driver.find_element(By.CSS_SELECTOR, "button.bg-green-600")
get_link_button.click()
print("🔗 Tombol Get Link diklik")
break
except NoSuchElementException:
print(f"⏳ Tombol Get Link belum ada... ({i+1})")
time.sleep(1)
else:
raise Exception("❌ Tombol Get Link tidak ditemukan dalam 30 detik")
for i in range(30):
try:
download_button = self.driver.find_element(
By.CSS_SELECTOR,
"a.text-white.rounded-lg.p-2.text-center"
)
download_link = download_button.get_attribute("href")
soup = BeautifulSoup(self.driver.page_source, "html.parser")
img = soup.find("img")
original_url = ""
if img:
src = img["src"]
if "url=" in src:
original_url = unquote(src.split("url=")[1].split("&")[0])
print("URL Asli:", original_url)
else:
print("SRC:", src)
print("✅ Link download:", download_link)
ce = "jancok"
dataNE = {
'status': 200,
'img': original_url,
'url_ori': download_link
}
self.driver = webdriver.Chrome(service=self.service, options=self.options)
download_video(download_link)
return dataNE
except NoSuchElementException:
print(f"⏳ Link download belum siap... ({i+1})")
time.sleep(1)
else:
raise Exception("❌ Link download tidak tersedia dalam 30 detik")
except:
print(traceback.format_exc())
KillPid()
finally:
KillPid()
VHdriver = VHtearDriver()
sw = VHdriver.youtubeDownload("https://youtu.be/rdD-dKr-L-I?si=PT-oBsfEWa5ecZvv")
print(sw)