As you know, iPhone has Safari browser onboard. It's pretty neat and great working... but sites with huge layouts don't look good on small iPhone screen. When you have own blog it would be good to display it in customized way.
Today almost all blogs have RSS Feeds so if we want to display our blog in cusomized, iPhone ready look it's just to put blog's feed through some RSS parser and display it as iPhone ready web page. Let's use iui - project started by Joe Hewitt - creator of firebug. It's a simple JavaScript framework for iPhone web pages.
So, we have iui now we need some PHP RSS reader. We'll use SimpleXMLObject class because it's ... simple.
<?php
$feed = simplexml_load_file($feedURL);
?>
As you can notice in php code we have function calls to something called xcache - it's very nice plugin for php speeding up your code by doing magic opcode caching. But for now we'll use different advantage of cache - you can store variables just in your server memory and get access to it on different php file calls. I this case we use this to download RSS feed once and store it for a while. So if you refresh your browser or some one else will go on your blog we do not need to download feed again.
Now we have our blog's feed and we can display it in nice iui internface.
Putting all things together we have pretty simple and neat iPhone blog: http://botmonster.com/iFeed/
Now, let's make browser detection - if browser is iPhone's Safari redirect user to our "iPhone ready" blog page. Just paste this JavaScript snippet into html section of your blog template. Replace "feedURL=" with link to your blog's feed.
<script type="'text/javascript'">
//<!--[CDATA[
if(document.location.href == 'http://blog.botmonster.com/' && navigator.userAgent.match(/iPhone|iPod/i)){ document.location='http://botmonster.com/blog/?feedURL=http://feeds.feedburner.com/BotmonstersWired'; }
//]]-->
</script>
It's very simple detection, if you need more sophisticated detection I'll recommend using this webkit detect script Just try to enter this address into your iPhone: blog.botmonster.com - you'll be redirect into iFeed page and you will see something like this:
You can download all iFeed code from google code at http://code.google.com/p/ifeed/
Available under MIT licence.
Showing posts with label iPhone. Show all posts
Showing posts with label iPhone. Show all posts
Tuesday, December 25, 2007
How to put your own blog on iPhone...
at
22:46
3
comments
Labels: blog, iPhone, JavaScript, php
Sunday, December 23, 2007
iTunes Album Art With Amazon Covers Using PHP/JS
How to get album art for your favorite mp3 album? It's pretty easy. There's lot of little programs and scripts to add custom covers for albums, but when you have hundreds of thousands albums it's better to make some batch programming.
How to setup itunes album art in 3 easy steps?
- Put all your mp3's in artist - album names.
- Download album cover from amazon.com
- Put this cover for all tracks in itunes album.
Ok, so let's get started. First of all we need Amazon Web Services account.After the registration progress we can create custom app that will search and download covers of our albums. We'll be using amazon web services api with our secret Access Key ID and Secret Access Key. We want to have a little PHP crawler that will go through all of folders and search for album art.
Fille called getCovers.php:
We can execute this script from command line
//Enter your Amazon Web Services IDs
define("Access_Key_ID", "");
define("Associate_tag", "");
//Set up the operation in the request
function ItemSearch($SearchIndex, $Keywords){
$Operation = "ItemSearch";
$Version = "2007-07-16";
$ResponseGroup = "ItemAttributes,Images";
$request=
"http://ecs.amazonaws.com/onca/xml"
. "?Service=AWSECommerceService"
. "&AssociateTag=" . Associate_tag
. "&AWSAccessKeyId=" . Access_Key_ID
. "&Operation=" . $Operation
. "&Version=" . $Version
. "&SearchIndex=" . $SearchIndex
. "&Keywords=" . $Keywords
. "&ResponseGroup=" . $ResponseGroup;
$response = file_get_contents($request);
$parsed_xml = simplexml_load_string($response);
if(isset($parsed_xml->OperationRequest->Errors->Error) || isset($parsed_xml->Items->Request->Errors))
return null;
else
return $parsed_xml;
}
$it = new RecursiveDirectoryIterator($argv[1]);
foreach (new RecursiveIteratorIterator($it, 2) as $path) {
if(!$path->isDir())
continue;
$search = preg_replace(array('#'.addslashes($argv[1]).'#','/[\\\_\-]/','/\([0-9a-zA-Z ]+\)/',),
array('',' ','',),$path);
$item = ItemSearch('Music', urlencode($search));
if($item !== null)
file_put_contents($path.'\cover.jpg',file_get_contents($item->Items->Item[0]->LargeImage->URL));
}
c:> php getCovers.php "c:\mp3"
first parameter is our main folder name where we have stored all our mp3 albums. In each folder an cover.jpg file will appear.
Now, we must put this covers to iTunes. We can do it manually by right click on song and adding cover from disc. Of course it's not very efficient way to do that specially when we have tons of mp3's. So we can use apple scripting advantages. Specially when we work on Windows we'll use COM api for iTunes. You can obtains Apple's COM SDK from here if you are curious what can be done with iTunes.
iTunes remote control via JScript
Now we have to iterate trough all files in our iTunes library and put cover.jpg file to each of them. We'll use simple Windows JScript with Apples COM interface and FileSystemObject to operate on our disc. Let's call out script putCovers.js:
/**
* (c) 2007 botmonster http://blog.botmonster.com
*/
var iTunesApp = WScript.CreateObject("iTunes.Application");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var tracks = iTunesApp.LibraryPlaylist.Tracks;
var numTracks = tracks.Count;
var i;
var c = 0;WScript.Echo(numTracks);
for (i = 1; i <= numTracks; i++) { var currTrack = tracks.Item(i); if ( currTrack.Artwork.Count == 0 && currTrack.Location != ''){ var songFile = fso.GetFile(currTrack.Location); var size = songFile.Size; var cover = fso.GetParentFolderName(currTrack.Location) + '\\cover.jpg'; if (fso.FileExists(cover)){ if (songFile.attributes & 1){ songFile.attributes = songFile.attributes - 1; } try{ currTrack.AddArtworkFromFile(cover); }catch (e){ WScript.Echo(e.description + '\n'); } } } }
We can execute this script from command line
c:> cscript putCovers.js
It will take a while depending on your mp3 database size. Now you see all covers in your Cover Flow View in iTunes and you can synchronize albums to your iPod touch or iPhone for even better album view experience :)
at
18:27
0
comments
Labels: iPhone, iTunes, JavaScript, JScript, php
Subscribe to:
Posts (Atom)
