php Youtube Get video id from live_stream

naguchennai

How YouTube Get video id from live_stream using php. I using this url

 https://www.youtube.com/embed/live_stream?channel=UCmyKnNRH0wH-r8I-ceP-dsg

I try this code but return nothing

function getvideourl($chid){
$videoId = null;

// Fetch the livestream page
if($data = file_get_contents('https://www.youtube.com/embed/live_stream?channel='.$chid))
{
    // Find the video ID in there
    if(preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $link, $matches))
        $videoId = $matches[1];
    
    else
        $videoId ="";
}
else
    throw new Exception('Couldn\'t fetch data');

 $video_url = "https://www.youtube.com/embed/".$videoId;


return $video_url;
}
b14d35

You're using the variable $link instead of $data, try change it like this:

if(preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $data, $matches))
        $videoId = substr($matches[0], 0, -2);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Getting video id "Live Stream" from Youtube

Get all video ID's from a YouTube playlist into a PHP array

How to get live video id from YouTube channel

Get youtube video id from youtube url in smarty template?

Get youtube video Id from shared video Url

I need some help in correcting my codes in php - How to get the video id from a YouTube URL

Youtube Data API: Get latest video ID from channel excluding live streams

How can I get a Youtube video ID from the Youtube API given the video url?

How do I get the YouTube video ID from a URL?

How to get youtube video id from URL with java?

How to get thumbnail of youtube video from url using php and API

Embed a YouTube channel's current live stream without the video ID

How to get video tags from youtube video?

Youtube Data API - How to get video comments from multiple video id

how to get youtube player id and stop video

separate get requests for each youtube video ID

How to get ID of last uploaded video to YouTube?

Retrieve video ID from YouTube link

Extract the video ID from youtube url in .net

Get YouTube video thumbnail and use it with PHP

Fetch YouTube Video Id from youtube URL in zend framework

how to get video id from clicking youtube search page link in a webview

How do I parse YouTube URLs to get the video ID from a URL using Dart?

Youtube API v3 get every Video ID from given channel

Is there solution "get youtube video ID from url" contains mobile web url?

How to get the data of a video from youtube in javascript

Get length of YouTube video from page source?

Display Youtube Video from database in PHP

Processing a live video from Youtube for speech to text