Software: January 2005 Archives
I don't know why I never thought of doing this before.
$ nmap -sT -sR -sV -I -O -PI -PT 192.168.1.103
This is probably the first of several posts that will deal with this topic.
The new Tivo system software upgrade brings many interesting features to Tivo, the most well-known of which is TivoToGo, which lets you copy the video files to your PC.
However, the software upgrade also includes a web server. This means you can interact with your Tivo via any web browser on any PC. I won't discuss all the ramifications of this right now, but one notable one is that Tivo can now produce your "Now Playing" list (a list of everything on your Tivo) as either an HTML or XML file.
The XML file is particularly exciting, because XML is very, very easy to parse nowadays. People have already parsed this XML into RSS, and I expect to be doing the same over the next couple of days.
To access your Tivo's Now Playing list as an XML file, use this URL:
https://192.168.1.103/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying
Just change the IP to the address of your Tivo, then login using the username tivo and your Media Access Key as your password.
Some of the scripts other people have released to parse this file are quite elaborate (and cool), but I wanted to demonstrate how easy it is to parse the Now Playing list into a simple HTML stream that could be easily included on any website. This took me about 10 mins to write, and it isn't very elegant.
Here you go:
<?php
function converttivodate($format, $input){
//borrowed from A. Cassidy Napoli's Tivo_XML script
return date($format, hexdec($input));}
$file = "nowplaying.xml";
$sxe = simplexml_load_file($file);
foreach($sxe->Item as $item) {
$details = $item->Details;
echo "$details->Title: $details->EpisodeTitle<br/>
$details->Description (" .
converttivodate('n/d/y G:i',$details->CaptureDate) .
", $details->SourceStation, $details->SourceChannel)</p>\n"; }
?>That's about 6 lines of PHP, and it's easy to see the same (or even more) could probably be accomplished in about 2 lines. (See the update below.)
Just use include() or the Curl extensions to include the file on your site, and you're all set. This code snippet requires PHP5's SimpleXML support.
It produces something like this:
Law & Order: Merger
A scandal involving two wealthy families threatens McCoy and Carmichael's chances of a conviction in the murder of a drug-addicted girl of 15. (1/26/05 15:59, TNT, 3-0)Seinfeld: The Doorman
A doorman (Larry Miller) tries to cause trouble for Jerry; Kramer develops a male undergarment. (1/26/05 15:29, TBS, 22-0)Malcolm in the Middle: Reese's Apartment
Francis is determined to show his parents why they should not have kicked Reese out; Malcolm helps a football player writer a college essay. (1/26/05 14:59, WWOR, 9-0)
Here's a demo:
Update (1/27/05): Well, if you're willing to sacrifice readability in the code, you can implement the above with just 2 lines of PHP. I just took out the extra function call and variable assignments from the code above, and wound up with two lines.
When you take a picture with a digital camera, most cameras store some data along with the picture, such as the date and time you took the photo, whether you used the flash, the focal length, the f-stop, and the make and model of the camera. This information is called EXIF data.
I thought it would be useful to be able to automatically publish this data in an RSS or Atom feed, so I wrote a PHP script to do just that.
My script, named Asif, will process a directory containing JPEGs and output an HTML, RSS, or Atom feed containing some or all of the Exif data for each picture, as well as (optionally) a thumbnail version of the picture.
See it in action:
This demo processes the files in this directory. The thumbnails are generated dynamically, as needed. (The good pictures are from manyhighways.com.)
Asif has two primary benefits:
- It allows you to instantly generate a gallery from a directory full of images without having to write a single line of HTML or set any configuration options. To accomplish this, just drop asif.php into a directory, and access the page.
- It allows you to instantly provide an RSS or Atom feed containing Exif data for any directory full of photos. You could use this for a photoblog, or, really, for instantly creating a photoblog by just dropping your photos into a directory on your server and renaming asif.php to index.php and pointing readers to that directory. Your gallery will automatically update every time you drop a file in the directory, and the RSS/Atom feed will always be fresh.
The output format is controlled by the user. Simply append the name of the format to the URL, and you get what you asked for. So, http://yourdomain.com/photos/asif.php?format=rss gets you RSS, and asif.php?format=atom gets you Atom. Omitting the format parameter produces HTML.
Similarly, the user controls whether to display thumbnails: asif.php?thumbnails=yes displays them. Omitting that parameter omits them. If thumbnails are requested, they will be included in the RSS or Atom feeds as well.
Asif can handle any directory path you pass to it on the URL. So, asif.php?format=rss&directory=sample will process the web directory called "sample". Directory paths are relative to the path of the script. So, asif.php?format=rss&directory=sample/travel/nyc will go down three directories and display the images. Omitting the directory directive tells Asif to display the data for the current directory.
Cameras often store far more Exif data than is really useful, such as manufacturers' notes that are essentially encoded gibberish. For this reason, Asif by default will only show you certain Exif fields. However, if you wish to see all available Exif data for a file, pass the directive &alldata=yes on the URL, and Asif will return everything it finds in the file.
By default, Asif produces valid XHTML 1.0, valid RSS 2.0, and valid Atom .3. As long as you don't have any weird stuff mixed into your Exif data, it should always validate. The appearance of the HTML is controlled entirely via CSS, which of course you can customize.
Requirements
Asif requires PHP5, compiled with the GD libraries and with the directive --enable-exif. However, I believe only one line of code -- a call to scandir() -- needs to be rewritten to work in PHP4. (I included the alternate PHP4-compliant code in the comments.) If you don't have PHP5 installed on your server, I discuss how to do so in another post.
Installation
- Get the source code.
- Get the CSS file asif.css so you can control the HTML formatting.
- Install both files in a directory on your webserver, and rename asif.phps to asif.php.
It will be instantly ready to use, assuming the GD and Exif libraries are working on your server. If desired, change the constants defined at the top of the file to meet your needs.
Asif is free software and covered by the GPL.
Using Asif
Asif is controlled by passing parameters on the URL. These parameters are described above and in the source code. Available parameters are: format, directory, alldata, and thumbnails.
formatcan be "RSS", "Atom", or "HTML". It defaults to HTML.directoryis the path you want to process. Omit the trailing slash on the path. For security reasons, Asif does not, by default, process directories above the one where the Asif script resides. So, if asif.php is inyourdomain.com/photos/galleries/travel/, you can't do something likeasif.php?directory=../sportsto display photos in/galleries/sports. Instead, put asif.php in thegalleriesdirectory, and pass the directory name on the url, likeasif.php?directory=sportsorasif.php?directory=travel. Get it? Also, if you omit thedirectoryparameter, Asif processes whatever directory it resides in.alldatacan be "yes" or "no"/left blank. It defaults to "no." If set to yes, alldata will show all available Exif data for each file. If left blank or set to something other than "yes", it will only show certain common pieces of Exif data: date/time taken, filesize, height/width, f-stop, camera model, ISO, flash, focal length, and user comment. It is not hard to customize the code to add or omit these fields.thumbnailscan be "yes" or "no"/left blank. If set to "yes," thumbnails will be generated (if necessary) and displayed. They will be included in the RSS or Atom feeds asimgtags, with thesrcattribute pointing to the URL for the thumbnail, and thelinktags pointing to the URL for the full image.
Support
If you have questions or comments, please post them below.
Disclaimer
I am not the world's greatest PHP programmer. The code is inefficient, it may not work, and it may expose your server to security risks. Be sure to read all of the comments in the code, and secure your own webserver properly. Use this software at your own risk. It is offered without warranty or assumption of liability.
Update (2005-02-09): I figured out how to generate RSS feeds using PHP5's DOM support, which I recommend using. When I get some time, I will update this script to use the DOM.
