yt bot protection

This commit is contained in:
salvacybersec
2025-11-13 05:31:43 +03:00
parent 01f9cfc8b2
commit 86ce4913b8
2 changed files with 128 additions and 19 deletions

View File

@@ -8,6 +8,7 @@ import os
import yaml
import time
import logging
import random
from pathlib import Path
# Logger oluştur
@@ -211,10 +212,10 @@ def process_channel(channel_id: str, max_items: int = 50) -> dict:
else:
logger.debug(f"[PROCESS] Tüm videolar zaten veritabanında")
# Bekleyen videoları işle (max_items kadar, 20'şer batch'ler halinde)
# YouTube IP blocking'i önlemek için her batch'te 20 video işlenir
# Bekleyen videoları işle (max_items kadar, küçük batch'ler halinde)
# YouTube IP blocking'i önlemek için her batch'te sadece 5 video işlenir
# max_items: Her istekte kaç video transcript işleneceği (maksimum 100)
batch_size = 20 # Her batch'te işlenecek video sayısı
batch_size = 5 # Her batch'te işlenecek video sayısı (küçük batch = daha az blocking riski)
processed_count = 0 # İşlenen transcript sayısı
# Tüm bekleyen videoları al (channel_id'ye göre filtrele)
@@ -290,10 +291,11 @@ def process_channel(channel_id: str, max_items: int = 50) -> dict:
# Batch özeti
logger.info(f"[BATCH] Batch {current_batch}/{total_batches} tamamlandı - İşlenen: {batch_processed}, Cache: {batch_cached}, Başarısız: {batch_failed}")
# Batch tamamlandı, kısa bir bekleme (rate limiting için)
# Batch tamamlandı, uzun bekleme (YouTube IP blocking önleme için)
if processed_count < max_items and batch_start + batch_size < len(all_pending_videos):
wait_time = 2
logger.debug(f"[BATCH] Batch'ler arası bekleme: {wait_time} saniye")
# Blocking varsa daha uzun bekle
wait_time = 60 + random.uniform(0, 30) # 60-90 saniye random (human-like)
logger.info(f"[BATCH] Batch'ler arası bekleme: {wait_time:.1f} saniye ({wait_time/60:.1f} dakika) - YouTube IP blocking önleme")
time.sleep(wait_time)
# İşlenmiş videoları getir