bep40 commited on
Commit
5bbadb7
·
verified ·
1 Parent(s): aa5083a

Fix: add @baosuckhoedoisongboyte to shorts (parallel), limit OG fallback to 5 items for speed

Browse files
Files changed (1) hide show
  1. main.py +10 -9
main.py CHANGED
@@ -176,14 +176,15 @@ def _yt_channel_shorts(channel, count=15):
176
  return videos
177
  except:return[]
178
  def scrape_shorts():
179
- """Fetch shorts from @baodantri7941 and @fptbongdaofficial"""
180
  vids=[]
181
- for ch in ["baodantri7941","fptbongdaofficial"]:
182
- try:
183
- r=_yt_channel_shorts(ch,10)
184
- if r:vids.extend(r)
185
- except:pass
186
- if len(vids)>=15:break
 
187
  return vids[:20]
188
 
189
  # ===== LIVESCORE =====
@@ -373,9 +374,9 @@ def scrape_genk_ai():
373
  if img_src:break
374
  container=container.parent
375
  seen.add(href)
376
- if not img_src:
377
  try:
378
- og_r=requests.get(href,headers=HEADERS,timeout=8);og_r.encoding="utf-8"
379
  og_soup=BeautifulSoup(og_r.text,"lxml");og_tag=og_soup.find("meta",property="og:image")
380
  if og_tag:img_src=og_tag.get("content","")
381
  except:pass
 
176
  return videos
177
  except:return[]
178
  def scrape_shorts():
179
+ """Fetch shorts from multiple channels in parallel"""
180
  vids=[]
181
+ with ThreadPoolExecutor(3) as ex:
182
+ futs=[ex.submit(_yt_channel_shorts,ch,8) for ch in ["baodantri7941","baosuckhoedoisongboyte","fptbongdaofficial"]]
183
+ for f in as_completed(futs):
184
+ try:
185
+ r=f.result()
186
+ if r:vids.extend(r)
187
+ except:pass
188
  return vids[:20]
189
 
190
  # ===== LIVESCORE =====
 
374
  if img_src:break
375
  container=container.parent
376
  seen.add(href)
377
+ if not img_src and sum(1 for x in articles if not x.get("img"))<5:
378
  try:
379
+ og_r=requests.get(href,headers=HEADERS,timeout=5);og_r.encoding="utf-8"
380
  og_soup=BeautifulSoup(og_r.text,"lxml");og_tag=og_soup.find("meta",property="og:image")
381
  if og_tag:img_src=og_tag.get("content","")
382
  except:pass