There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

Automatically download livestreams for a specific channel, an updated Windows batch script

Hi folks! Glad to see that the Data Hoarders community has migrated to Lemmy. I thought I’d share a yt-dlp script that I use regularly.

cross-posted from: sh.itjust.works/post/1891050

Hi folks! Glad to see that the youtube-dl community has migrated to Lemmy.

As I documented in The Other Place, I previously put together a Windows batch script to continuously monitor a specific channel for livestreams and download them as they occur.

A recent change to YouTube resulted in https://www.youtube.com/%channel_name%/live no longer consistently linking to the most recent livestream. Fortunately, u/werid’s suggestion of using –match-filter “live_status = is_live” on https://www.youtube.com/%channel_name%/streams still works, though I had to rework the script to not issue the download command for the same stream multiple times.

If anyone is interested or needs to do something similar, this is the current .bat script that I use:


<span style="color:#323232;">@echo off
</span><span style="color:#323232;">set channel_name=@SpaceX
</span><span style="color:#323232;">:loop
</span><span style="color:#323232;">@echo off
</span><span style="color:#323232;">set DATE_TIME=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%_%TIME:~0,2%-%TIME:~3,2%-%TIME:~6,2%
</span><span style="color:#323232;">set DATE_TIME=%DATE_TIME: =0%
</span><span style="color:#323232;">set /A clock=%RANDOM% %% 80 + 1
</span><span style="color:#323232;">set clock=%clock: =0%
</span><span style="color:#323232;">
</span><span style="color:#323232;">set newLivestream=false
</span><span style="color:#323232;">echo Looking for new %channel_name% livestreams...
</span><span style="color:#323232;">@for /f %%i in ('yt-dlp --print id --match-filter "live_status = is_live" "https://www.youtube.com/%channel_name%/streams"') do (
</span><span style="color:#323232;">	@if NOT defined %%i (
</span><span style="color:#323232;">	set newLivestream=true
</span><span style="color:#323232;">	echo New livestream found: %%i
</span><span style="color:#323232;">	@set "%%i=false"
</span><span style="color:#323232;">	start cmd /c yt-dlp --live-from-start -x -k -o "D:/Videos/%%(release_date)s_%%(channel)s_%%(id)s_%%(title)s.%%(ext)s" https://www.youtube.com/watch?v=%%i
</span><span style="color:#323232;">	@set "%%i=true"
</span><span style="color:#323232;">	@timeout /t 1
</span><span style="color:#323232;">	)
</span><span style="color:#323232;">)
</span><span style="color:#323232;">if %newLivestream%==false (
</span><span style="color:#323232;">	echo No new livestreams found
</span><span style="color:#323232;">)
</span><span style="color:#323232;">timeout /t %clock%
</span><span style="color:#323232;">goto loop
</span>

You’ll obviously need to change the channel_name and output template to suit your needs.

sherry ,
@sherry@lemmy.sherry.moe avatar

Thank you for sharing. I’ll totally give this a try next time I need it 😯

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • [email protected]
  • lifeLocal
  • goranko
  • All magazines