0

I have the below code for retrieving views and subscribers from a YouTube channel "?q=dsagov"

$UserID = $_GET['q'];
$data = file_get_contents('http://gdata.youtube.com/feeds/api/users/'. $UserID.'');

$xml = new SimpleXMLElement($data);
$stats_data = (array)$xml->children('yt', true)->statistics->attributes();
$stats_data = $stats_data['@attributes'];

echo 'Views = '.$stats_data['subscriberCount'].'<br />';
echo 'Subscribers = '.$stats_data['totalUploadViews'].'<br />';

I would like to take this one step further and find the YouTube channel ID based on a website address, in this case https://www.gov.uk/government/organisations/driving-standards-agency .

So either REGEX the website find the Channel ID or another method which I am not aware of using YouTube API, I can put the URL of the website and have it find the official channel is this possible?

Thanks in advance.

Just to clarify For example I would like to enter a URL in query "/?q=gov.uk/government/organisations/driving-standards-agency" what the script would do is find the YouTube Channel ID on the URL and run the API and display the results

Meisam Ebrahimi
  • 111
  • 2
  • 12
  • Basically you want to build a website scrapper. That opens a certain page, tries to find a youtube video and then extract the youtube channel. If it did not find a youtube video, it tries to open a link in the previous opened page and so on. Now comes the fun part: What if the youtube video on the site is just a video from another author ? You can't possibly know. Have fun building a scrapper and trying to scrap a government website. Who knows, maybe they get you before you even get an ID :P – HamZa Feb 26 '14 at 11:26
  • Firstly, this was an example URL it's not used for scraping Government websites, I am trying to build a link building system to include social data for URLs, All I want the script to do is extract the channel ID from the homepage of a given URL as most websites display their social links on the front page and if it doesn't find a youtube channel it gives up and displays nothing – Meisam Ebrahimi Feb 26 '14 at 11:30
  • Yeah possible, so what have you tried ? Isn't it something simple as looping through all links and checking if it's a youtube video link ? Hint: you might even find non-linked videos with this [regex](http://stackoverflow.com/a/5831191) – HamZa Feb 26 '14 at 11:35
  • I haven't tried anything yet as I was looking for the best approach, maybe there is already something like this out there, I will look in to the REGEX link you sent, Thanks. – Meisam Ebrahimi Feb 26 '14 at 11:42

1 Answers1

0

I don't think this is possible. Where would you search for website name ? This could be in user's descriptions, video descriptions, many more places for many users and videos.

Rohit Awasthi
  • 686
  • 3
  • 12
  • For example I would like to enter a URL in query "/?q=gov.uk/government/organisations/driving-standards-agency" what the script would do is find the YouTube Channel ID on the URL and run the API and display the results – Meisam Ebrahimi Feb 26 '14 at 11:23