Last active
January 28, 2025 17:59
-
-
Save JacobWeisenburger/f43f4635be7bfb8328823103bfaf3e5f to your computer and use it in GitHub Desktop.
checkIfYouTubeChannelIsLive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
CORS blocks this request from the browser, so you will need to run this code on the server. | |
*/ | |
async function checkIfYouTubeChannelIsLive ( channelId: string ) { | |
const liveCheckURL = `https://www.youtube.com/embed/live_stream?channel=${ channelId }` | |
const responseText = await fetch( liveCheckURL ).then( res => res.text() ) | |
const isLive = responseText.indexOf( 'This video is unavailable' ) < 0 | |
return isLive | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment