Android Question Check if YouTube video link exists?

Zdravko Filipovic

Member
Licensed User
Longtime User
Is it possible to check if YouTube video exists before I send the link to Youtube player.

I found this:

publicfunction checkVideoExists(){
$headers = get_headers('http://gdata.youtube.com/feeds/api/videos/'. $videoId);
if(!strpos($headers[0],'200')){
echo "The YouTube video you entered does not exist";
returnfalse;
}
}


and this:

$videoID ="o8UCI7r1Aqw";
$header = get_headers("http://gdata.youtube.com/feeds/api/videos/". $videoID);
exit(var_dump($header));
switch($headers[0]){
case'200':
// video valid
break;

case'403':
// private video
break;

case'404':
// video not found
break;

default:
// nothing above
break;

but I'm beginner and I don't know how to do this in Basic4Android.
 

Zdravko Filipovic

Member
Licensed User
Longtime User
This works but generates much traffic (each request downloads a file of ~3.5KB) and because I have many links to check is there a different way to check for link existance like in examples above where is checked only header?

Or I'm wrong, it doesn't download file?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
See this example
 

Attachments

  • youtubecheck.zip
    6.3 KB · Views: 207
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
This works but generates much traffic (each request downloads a file of ~3.5KB) and because I have many links to check is there a different way to check for link existance like in examples above where is checked only header?

Or I'm wrong, it doesn't download file?

Sure it does (Aehm... I THINK SO). You can use the Google Youtube API to minimize the traffic.
But to just checks whether a video exists or not it works.

If you have to check a lot of videos then you should be in an wireless-lan :D
 
Last edited:
Upvote 0

Zdravko Filipovic

Member
Licensed User
Longtime User
Thank you again, but I have new problem.

Because httputils2 sends all requests simultaneously I'm now getting error for too many calls:

"<?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:quota</domain><code>too_many_recent_calls</code></error></errors>".

Is there another way to do this (not using httputils2) where I could send requests one by one with some pause between them:

- send request
- wait for result
- pause

and repeat that for all links.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
This can be done also - and that´s suggested - with httputils2.
Right now i have not the time to make a new example for you. but this evening (6PM GMT+1) i have... I´ll make an example for you then.

But you can try it by yourself.

You have the jobmap. Just begin with creating this map (and not starteing all jobs at this time
create a sub which reads the first item which contains "Checking" from this map (that job have to be done). THIS job you create then and let it run...

In Jobdone you mark the job in jobmap like now; changing the "Checking" to an result.

Now I suggest to start a timer (5 seconds for ex)... On timer tick you stop the timer and then you can check here whether there are items in jobmap with "Checking".
If yes. Start your sub to sends one job again...

This will last till the last job is done.
 
Upvote 0
Top