This module is used to capture images from YouTube live.
Näkymä Helsingistä location list
YouTube Capture Experiment
with youtube_dl.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(nakyma_helsinkigista_youtube_live_url, download=False)for o in info['formats']:if o['resolution'] =='1280x720':print(o['url'])breakelse:raiseValueError("No 1280x720 format")
[youtube] Extracting URL: https://www.youtube.com/watch?v=LMZQ7eFhm58
[youtube] LMZQ7eFhm58: Downloading webpage
[youtube] LMZQ7eFhm58: Downloading ios player API JSON
[youtube] LMZQ7eFhm58: Downloading web creator player API JSON
[youtube] LMZQ7eFhm58: Downloading m3u8 information
https://manifest.googlevideo.com/api/manifest/hls_playlist/expire/1731361277/ei/nSUyZ7_VK6a80u8Pr9XG4Qc/ip/2001:14bb:693:814b:6cf8:466:4906:b913/id/LMZQ7eFhm58.4/itag/232/source/yt_live_broadcast/requiressl/yes/ratebypass/yes/live/1/sgovp/gir%3Dyes%3Bitag%3D136/rqh/1/hdlc/1/hls_chunk_host/rr5---sn-qo5-ixas.googlevideo.com/xpc/EgVo2aDSNQ%3D%3D/playlist_duration/3600/manifest_duration/3600/vprv/1/playlist_type/DVR/initcwndbps/1467500/met/1731339678,/mh/l8/mm/44/mn/sn-qo5-ixas/ms/lva/mv/m/mvi/5/pcm2cms/yes/pl/49/rms/lva,lva/dover/13/pacing/0/short_key/1/keepalive/yes/fexp/51312688,51326932/mt/1731339162/sparams/expire,ei,ip,id,itag,source,requiressl,ratebypass,live,sgovp,rqh,hdlc,xpc,playlist_duration,manifest_duration,vprv,playlist_type/sig/AJfQdSswRQIgFW9WJZ0GfBMxlRihLf2v4o741rOonQ5NivOu4kHwVx8CIQDA3g0dAE0BWx_BDkfyldNsF2z4Jf74xYomUYrSKs4UBA%3D%3D/lsparams/hls_chunk_host,initcwndbps,met,mh,mm,mn,ms,mv,mvi,pcm2cms,pl,rms/lsig/AGluJ3MwRgIhAK3opSPBuO135lJUjthUvwfChQaEONmaVsFidce2uE9gAiEAspdlt85ojgsBDa697pSlYP7X308ml8MSpMmKky605LM%3D/playlist/index.m3u8
[youtube] Extracting URL: https://www.youtube.com/watch?v=LMZQ7eFhm58
[youtube] LMZQ7eFhm58: Downloading webpage
[youtube] LMZQ7eFhm58: Downloading ios player API JSON
[youtube] LMZQ7eFhm58: Downloading web creator player API JSON
[youtube] LMZQ7eFhm58: Downloading m3u8 information
def capture_youtube_live_frame(youtube_live_url:str=nakyma_helsinkigista_youtube_live_url):"Capture a frame from the given YouTube Live URL and save into a JPEG file" url = stream_url(youtube_live_url, ydl_opts) cap = cv2.VideoCapture(url) ret, frame = cap.read()#show_frame(crop_frame(frame))if ret==False:raiseException("Failed to capture frame.")try: path = Path("../data")/fname("cap_", *meta(crop_frame(frame), printing=True))except: path = Path("../data")/fname("fail_", datetime.now(), "nowhere") path.parent.mkdir(parents=True, exist_ok=True) cv2.imwrite(path, frame)return pathfile= capture_youtube_live_frame()file
[youtube] Extracting URL: https://www.youtube.com/live/Cp4RRAEgpeU?si=IwqJ4QU1Umv9PdgW
[youtube] Cp4RRAEgpeU: Downloading webpage
[youtube] Cp4RRAEgpeU: Downloading ios player API JSON
[youtube] Cp4RRAEgpeU: Downloading web creator player API JSON
[youtube] Cp4RRAEgpeU: Downloading m3u8 information
[youtube] Extracting URL: https://www.youtube.com/watch?v=LMZQ7eFhm58
[youtube] LMZQ7eFhm58: Downloading webpage
[youtube] LMZQ7eFhm58: Downloading ios player API JSON
[youtube] LMZQ7eFhm58: Downloading web creator player API JSON
[youtube] LMZQ7eFhm58: Downloading m3u8 information
SR ILO ee
cap_2024.11.11_17:48:51_unclear.jpg
for i, o inenumerate(glob.glob("../data/cap_*_unclear.jpg")):try: new = Path("../data")/fname("cap_", *meta(o, True))print(i, o, " -> ", new) os.rename(o, new)exceptExceptionas e:print(o)