Home > Software design >  YouTube URL with channel_id vs 'c'
YouTube URL with channel_id vs 'c'

Time:12-20

I am writing a PHP script where I am using the YouTube XML URLs as my input

I understood that if the channel has a 'user' like https://www.youtube.com/user/ahodzi24 then its XML URL will be https://www.youtube.com/feeds/videos.xml?user=ahodzi24

And if it has a 'channel' like https://www.youtube.com/channel/UC3lQ8A-4ZJwrq_FnQrEFsqg then its XML URL will be https://www.youtube.com/feeds/videos.xml?channel_id=UC3lQ8A-4ZJwrq_FnQrEFsqg

But I am unable to figure out if the URL doesn't have a channel id and instead has a channel name like this one: https://www.youtube.com/c/ADUAquascaping

Then what should be its XML URL in this case?

CodePudding user response:

I would recommend you to get the channel id from the channel name. To do it you can look for the first "UC" (which the prefix for YouTube channel ids) string in the YouTube welcome webpage like this:

// if you know that the ID works in a URL of the type: https://www.youtube.com/c/ID
$ID = 'ADUAquascaping';
$content = file_get_contents('https://www.youtube.com/c/' . $ID);
$parts = explode('"UC', $content);
$channelId = 'UC' . explode('"', $parts[1])[0];
echo 'Use: https://www.youtube.com/feeds/videos.xml?channel_id=' . $channelId;
  • Related