mohammed777 commited on
Commit
2ef501e
·
verified ·
1 Parent(s): c6b7d2d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -6
main.py CHANGED
@@ -77,6 +77,10 @@ selected_user_agent = get_desktop_user_agent()
77
 
78
  headers = {'User-Agent': selected_user_agent}
79
 
 
 
 
 
80
  ydl_opts_video_info = {
81
  'quiet': True,
82
  'skip_download': True,
@@ -85,7 +89,8 @@ ydl_opts_video_info = {
85
  'no_warnings': True,
86
  'age_limit': 18,
87
  'force_generic_extractor': False,
88
- 'http_headers': headers
 
89
  }
90
 
91
  # --- النموذج ---
@@ -116,7 +121,8 @@ def preprocess_text(text):
116
 
117
  # --- معالجة فيديو واحد فقط (نسخة 2) ---
118
  def process_single_video2(video_url, loaded_quality_model, loaded_sentiment_pipeline, max_comments_per_video=50):
119
- downloader = YoutubeCommentDownloader()
 
120
 
121
  video_id = extract_video_id(video_url)
122
  if not video_id:
@@ -228,7 +234,7 @@ async def evaluate_youtube_playlist_individually_same_method2(youtube_url: str,
228
 
229
  video_links = []
230
  try:
231
- with yt_dlp.YoutubeDL({'extract_flat': True, 'quiet': True, 'playlist_items': '1:10'}) as ydl:
232
  playlist_info = ydl.extract_info(youtube_url, download=False)
233
  if 'entries' in playlist_info:
234
  for entry in playlist_info['entries'][:10]:
@@ -255,12 +261,12 @@ async def evaluate_youtube_playlist_individually_same_method2(youtube_url: str,
255
  ) for video_url in video_links
256
  ]
257
 
258
- for future in futures: # استخدام futures مباشرة بدون tqdm
259
  result = future.result()
260
  if result:
261
  individual_results.append(result)
262
- # تأخير إضافي بين معالجة نتائج الفيديوهات (اختياري)
263
- time.sleep(random.uniform(0.5, 1.5)) # تأخير بين 0.5 و 1.5 ثانية
264
 
265
  # --- الإحصاء النهائي ---
266
  num_good_videos = sum(1 for r in individual_results if r and r.get('quality') == 'جيد')
 
77
 
78
  headers = {'User-Agent': selected_user_agent}
79
 
80
+ # تحديد مسار ملف الكوكيز داخل حاوية Docker
81
+ # تأكد من أن هذا المسار يتطابق مع المكان الذي قمت برفع cookies.txt إليه في Hugging Face Space
82
+ COOKIES_FILE_PATH = '/app/cookies.txt' # افتراض أن cookies.txt في الجذر /app/
83
+
84
  ydl_opts_video_info = {
85
  'quiet': True,
86
  'skip_download': True,
 
89
  'no_warnings': True,
90
  'age_limit': 18,
91
  'force_generic_extractor': False,
92
+ 'http_headers': headers,
93
+ 'cookiefile': COOKIES_FILE_PATH # إضافة خيار ملف الكوكيز لـ yt-dlp
94
  }
95
 
96
  # --- النموذج ---
 
121
 
122
  # --- معالجة فيديو واحد فقط (نسخة 2) ---
123
  def process_single_video2(video_url, loaded_quality_model, loaded_sentiment_pipeline, max_comments_per_video=50):
124
+ # تمرير مسار ملف الكوكيز إلى YoutubeCommentDownloader
125
+ downloader = YoutubeCommentDownloader(cookies_file=COOKIES_FILE_PATH)
126
 
127
  video_id = extract_video_id(video_url)
128
  if not video_id:
 
234
 
235
  video_links = []
236
  try:
237
+ with yt_dlp.YoutubeDL({'extract_flat': True, 'quiet': True, 'playlist_items': '1:10', 'cookiefile': COOKIES_FILE_PATH}) as ydl: # إضافة cookiefile هنا
238
  playlist_info = ydl.extract_info(youtube_url, download=False)
239
  if 'entries' in playlist_info:
240
  for entry in playlist_info['entries'][:10]:
 
261
  ) for video_url in video_links
262
  ]
263
 
264
+ for future in futures:
265
  result = future.result()
266
  if result:
267
  individual_results.append(result)
268
+ # تأخير إضافي بين معالجة نتائج الفيديوهات
269
+ time.sleep(random.uniform(0.5, 1.5))
270
 
271
  # --- الإحصاء النهائي ---
272
  num_good_videos = sum(1 for r in individual_results if r and r.get('quality') == 'جيد')