# -*- coding: utf-8 -*-
import ssl,urllib.request,re
from bs4 import BeautifulSoup
ctx=ssl.create_default_context();ctx.check_hostname=False;ctx.verify_mode=ssl.CERT_NONE
HDR={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124 Safari/537.36'}
def fetch(u): return urllib.request.urlopen(urllib.request.Request(u,headers=HDR),timeout=25,context=ctx).read()
rows={
 'r107_해외재생_46':'https://www.komipo.co.kr/kor/content/46/main.do?mnCd=FN020903',
 'r163_ESG홍보영상_642':'https://www.komipo.co.kr/esg/content/642/main.do?mnCd=ESG010205',
 'r222_홍보영상_126':'https://www.komipo.co.kr/kor/content/126/main.do?mnCd=FN0902',
 'r223_KOMIPOMEDIA_215':'https://www.komipo.co.kr/kor/content/215/main.do?mnCd=FN090202',
 'r166_기후변화_102':'https://www.komipo.co.kr/esg/content/102/main.do?mnCd=ESG020201',
}
for n,u in rows.items():
    soup=BeautifulSoup(fetch(u),'html.parser')
    cont=soup.select_one('#content') or soup
    vids=cont.find_all('video')
    iframes=[i.get('src','') for i in cont.find_all('iframe') if i.get('src')]
    yt=[s for s in iframes if 'youtube' in s or 'youtu.be' in s or 'vimeo' in s]
    htmlv=re.findall(r'(youtube\.com/embed|youtu\.be|vimeo\.com|\.mp4)', str(cont))
    print(f'{n}: <video>{len(vids)} iframe{len(iframes)} yt/vimeo{len(yt)} htmlvid{set(htmlv)}')
    if yt: print('   ', yt[:2])
