Showing posts with label url. Show all posts
Showing posts with label url. Show all posts

Friday, February 28, 2014

Watch YouTube Videos by Country

Sometimes I wonder what the hell goes on in Greenland... or does Chittagong, Bangladesh have video bloggers?  I consider myself lucky to be living in a time where you can 'visit' just about any place in the world.

So, exactly how DO you find youtube videos posted from a certain country? 

You need to utilize the glorious Youtube API. The old one, in fact, but it works. This allows you to search for videos based on their latitude and longitude. Though, not all videos include that data, so it's not a perfect science. But you should find some results.

Here is an example url you would use:
 http://gdata.youtube.com/feeds/api/videos?max-results=50&start-index=5&q=bible&location=37.42307,-122.08427&location-radius=200km

Basically take the base url:  http://gdata.youtube.com/feeds/api/videos?

Then add any filters you want to include. They are optional:

location=37.42307,-122.08427  (Here is where you put the latitude/longitude for the location you wish to search)

location-radius=200km   (You can specify the km radius to search around the location)

 
max-results=50   (50 is the maximum amount. But you can make this lower if you want)

start-index=5    (What page do you want to start at?)

q=bible    (What type of keywords do you want?)

By default it will search by keyword relevance. But you can add these to the url, to search by
something else:

&orderby=published   (Search by published date)
&orderby=viewCount  (Search by viewCount - Highest to Lowest)

Unfortunately these are always in Descending order, and can't be changed to Ascending. Which is stupid! But whatever.

How do you find a location's latitude and longitude?    I use Google Maps, but a quick search would probably reveal more ways of doing it.

Using Google Maps, you can find a location (ex. Chittagong, Bangladesh).  Right-click on the city,
and select "What's Here?"




Then Google Maps will show you the name of the City, and the Long/Lat data. Simply copy and paste it into your url.


Here it is, with no other filters, except location and location radius:
 http://gdata.youtube.com/feeds/api/videos?location=22.289096,91.799927&location-radius=10km 

Let's see if I get anything....

 

It looks like there a good number of videos out there actually. 
I like changing the URL, because I find it to be the fastest way. But if you don't like messing with that,  you can go to http://gdata.youtube.com/demo/index.html, and scroll to the bottom. There is a form where you can enter this info, and generate an URL.

But why do all that when you can cut out the middle-man I say.

Happy Searching!

Thursday, November 15, 2012

PHP script to search IP's and find matching URL's

For those who saw my Mobotix camera post, you probably have an idea of my love for security cameras and the like.
While trying to find more Mobotix cameras using Google, I quickly ran out of search results to check out. But I knew there had to be more out there that Google just isn't finding.

I decided there must be a simple script you could run that searches for URL's that match a particular search string (just like Google does).  But you could have it search a particular range of IP's, routinely checking one for the search string.
It wouldn't be pretty or efficient of course, but it would be simple and I could probably code it.

Let me preface this by saying, I'd never coded in PHP before, which might already be obvious.

So, my little PHP search script looks like this:

 You enter an IP address (minus the last 3 digits). This of course means that the search range is very limited.

Then you enter the IP range you want it to search. In the example above the IP's searched are:
216.172.100.1 through 216.172.100.80.

Then you enter a filename for the script to save its results to. If any valid IP's have a url that matches the search string, their header information is written to the file.

Like I said, it is very limited in what it can do, but not bad for my first PHP script, written on the fly. It's a starting place for anyone who wants to expand on it.

Here is the code. It's broken up into two files.

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>IP Check</title>
</head>

<body>
 

<a href ="index.php">Home</a>

<p>IP Check
<p>
<p>
IP format XXX.XXX.XXX. (ex. 70.147.100.)
<p>
 X = lower number<p>
 max = upper limit <p>
 Filename to write to.<p><p><p>
 <form action="camcheck.php" method="post">

Enter IP: <input name="ip" size="12">
<p>
Enter X: <input name="x" size="3">
Enter Max: <input name="max" size="3">
<p>
 Filename: <input name="myfile" size="20">

<input type="submit" value="Start">
</form>

<p>
 <img src="magnify.jpg" alt="magnify"/>
<?php

?>
<p><p>
 </body>
</html>

The index file is basically just a bunch of html text boxes. The info captured is then used by the second file.

camcheck.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>IP Check</title>
</head>
<body>


<?php

$path = "/control/userimage.html";  // url search string
 
$myFile = $_POST['myfile'];
   
$fh = fopen($myFile, 'w') or die("Can't open file");  //open file

for ($x =(int)$_POST['x']; $x <= (int)$_POST['max']; $x++)
{
    $url= $_POST['ip'].strval($x);
    //echo $url;

    $valid = @fsockopen($url, 80, $errno, $errstr, 4);   //check url

 if (!$valid) {
     // Output Error Message, if you care
    // echo '<p>not valid<p>';
    //echo "$errstr ($errno)<br />\n";
    //$returnstring = $url."  Not Valid $errstr ($errno)> \n
    //$returnstring = "X = ".$x;
     //fwrite($fh,$returnstring);

       }
    else {
         // Output Success Message!
       fputs($valid, "\nHEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n"); //socket opened
        $headers = fread($valid, 4096);
       
     $returnstring = "\n".$url."  Valid\n";
     fwrite($fh,$returnstring);    //write valid IP to file
     fwrite($fh,$headers);         //write header info
     fwrite($fh,"\n");
     }
}
 echo "\n Program Complete. Results sent to ".$myFile;
fclose($fh);

?>
<p><p>
</body>
</html>

In the camcheck.php file, you'll see that the url search string is hard-coded into $path. It would probably be easy to make that another textbox, so you can change what url string to search for.

"/control/userimage.html" is a typical Mobotix web cam url. Which is what I created the script to find.

When you run the script, it saves the header results to a file on your webserver. 

Here are some example results:
 




216.172.104.49  Valid
HTTP/1.1 302 Found
Date: Thu, 15 Nov 2012 16:32:40 GMT
Server: Apache
Location: https://billing.dathorn.com/control/userimage.html
Connection: close
Content-Type: text/html; charset=iso-8859-1





216.172.104.50  Valid
HTTP/1.1 404 Not Found
Date: Thu, 15 Nov 2012 16:32:42 GMT
Server: LiteSpeed
Connection: close
Content-Type: text/html


216.172.104.55  Valid
HTTP/1.1 302 Found
Date: Thu, 15 Nov 2012 16:32:43 GMT
Server: LiteSpeed
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Location: https://2/control/userimage.html


216.172.104.56  Valid
HTTP/1.1 404 Not Found
Date: Thu, 15 Nov 2012 16:32:43 GMT
Server: LiteSpeed
Connection: close
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Thu, 15 Nov 2012 16:32:43 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
P3P: CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BUS IND PHY ONL UNI PUR COM NAV DEM STA"
Content-Type: text/html; charset=iso-8859-1
Set-Cookie: xid=788c930fc7639731a0609de479e12ae9; path=/
Set-Cookie: xid=788c930fc7639731a0609de479e12ae9; path=/; domain=www.comicjumps.com
Set-Cookie: xid=788c930fc7639731a0609de479e12ae9; path=/; domain=www.comicjumps.com
Set-Cookie: RefererCookie=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=www.comicjumps.com
Set-Cookie: store_language=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT
Set-Cookie: store_language=US; expires=Fri, 15-Nov-2013 16:32:43 GMT


I find it interesting just reading the different headers, and learning what they mean. You get an idea of what sites are located in certain IP's.
I haven't played with the script much, but I think it could be even more fun with some minor tweaks.

Right now it won't let me search more than 100 at a time before timing out. I haven't tried fixing that just yet.
Let me know if you have any hints/tips/fixes. I'd love to hear them.