96 lines
3.0 KiB
Python
96 lines
3.0 KiB
Python
from selenium import webdriver
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
import os
|
|
import yt_dlp
|
|
import time
|
|
|
|
# Создаем объект webdriver
|
|
driver = webdriver.Chrome() # или другой браузер
|
|
url = input("Ссылка на youtube/piped : ").replace("https://piped.video/","https://www.youtube.com/")
|
|
download_dir = input("Путь к папке куда будут скачиваться видео : ")
|
|
if "/videos" in url:
|
|
pass
|
|
else:
|
|
url += "/videos"
|
|
#print(url)
|
|
pi_on = input("Использовать piped прокси для скачивания видео (y/n) : ") == "y"
|
|
|
|
|
|
# Открываем страницу канала YouTube
|
|
driver.get(url)
|
|
|
|
# Ждем, пока страница загрузится
|
|
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.ID, "video-title")))
|
|
|
|
# Прокручиваем страницу вниз, чтобы загрузить больше видео
|
|
last_height = driver.execute_script("return document.documentElement.scrollHeight")
|
|
while True:
|
|
driver.execute_script("window.scrollTo(0, document.documentElement.scrollHeight);")
|
|
time.sleep(1)
|
|
new_height = driver.execute_script("return document.documentElement.scrollHeight")
|
|
if new_height == last_height:
|
|
break
|
|
last_height = new_height
|
|
|
|
# Ждем, пока все видео загрузятся
|
|
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.TAG_NAME, "a")))
|
|
|
|
# Извлекаем список видео
|
|
videos = driver.find_elements(By.TAG_NAME, "a")
|
|
|
|
# Создаем список ссылок на видео
|
|
video_links = []
|
|
for video in videos:
|
|
video_link = video.get_attribute("href")
|
|
video_links.append(video_link)
|
|
|
|
#print(video_links)
|
|
|
|
# Закрываем браузер
|
|
driver.quit()
|
|
|
|
ls2 = []
|
|
|
|
for row in video_links:
|
|
if row != None:
|
|
if "https://www.youtube.com/watch?v=" in row:
|
|
ls2.append(row)
|
|
|
|
ls2 = list(set(ls2))
|
|
|
|
error_links = []
|
|
|
|
video_links = ls2.copy()
|
|
# Опции для yt-dlp
|
|
ydl_opts = {
|
|
'format': '248+251/136+140/136+141/136-251',
|
|
'outtmpl': os.path.join(download_dir, '%(title)s.%(ext)s'),
|
|
'progress': True,
|
|
'quiet': False,
|
|
'no_warnings': True,
|
|
'no_check_certificate': True,
|
|
'continue_dl': True,
|
|
}
|
|
|
|
|
|
|
|
chet = len(video_links)
|
|
os.system("clear")
|
|
print("Осталось : ",chet)
|
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
for link in video_links:
|
|
if pi_on:
|
|
link = link.replace("https://www.youtube.com/","https://piped.video/")
|
|
try:
|
|
ydl.download(link)
|
|
os.system("clear")
|
|
chet -= 1
|
|
print("Осталось : ",chet)
|
|
except yt_dlp.utils.DownloadError as e:
|
|
print(f"Error downloading {link}: {e}")
|
|
|
|
print("Problematic links (Или где качество меньше 720p) :")
|
|
for link in error_links:
|
|
print(link) |