Tag Archives: AJAX

Music 2.0: Pitchfork

I love my music, I really do. Problem is however that I have far too much of it (2980 Songs, 16 GB currently, not counting audiobooks etc…) to carry it around with me all the time. It just doesn’t fit on my iPod Mini, nor does it fit on my notebook (I know shame on me, but I need the diskspace for work too). So I always have to carry around a selection of the songs I want to listen too, and far too often just the song I want to listen too is on my fileserver, and the trouble to transfer it to my notebook takes too long for me to be still in the mood to listen to it…
Pitchfork is the solution to all of my problems, well almost all… Pitchfork allows me to stream my music over my Local Network, and over the internet, with a nice and responsive interface that facilitates access to my songs.
Advertisement BadgeWhether you’re going to learn the electric guitar or if you would prefer to learn how to play the acoustic guitar instead you may want to go online and read some guitar reviews before buying one brand or another, from Ibanez guitars to many others.

Installing MPD

Since Pitchfork is based upon MPD, which will take care of streaming the data to the various clients and maintain the song database, we will first have to set it up. Sadly my distro (OpenSuSe 10.2) doesn’t have a version of MPD in its package management, so I had to download the sources and compile it myself:
wget http://www.musicpd.org/uploads/files/mpd-0.12.2.tar.bz2
tar -xvjf mpd-0.12.2.tar.bz2
cd mpd-0.12.2/
Now we have the sources, and we have to check that we have all the dependencies. Depending on how you are going to use MPD you have to have the following packages (along with their devel packages):
  • libshout: because we will be streaming the songs to an Icecast server
  • oss: as far as I know this is the most widely used and best supported. If it doesnt work take a look here
  • libmad: for mp3 support
  • libogg: for OGG Vorbis support
  • libvorbis: for Metadata support for Vorbis formats
  • libid3tag: Metadata support for mp3.
Quite a long list, but this is about the most essential stuff, if you have some special needs take a look at the official dependency listing.
Now it’s time to get to the actual compilation:
./configure
make
sudo make install
After the configure step, you’ll see a list of options that are turned on or off, if something is missing it probably means that you are missing some development packages.
So now we have mpd installed, the next step is to configure it. First you have to move the example configuration to the correct location:
sudo cp doc/mpdconf.example /etc/mpd.conf
Then we edit it according to our needs, especially the location of the Songs, Logfiles and Database should be changed: music_directory "/storage/Music/" playlist_directory "/storage/Music/playlists" db_file "/var/lib/mpd.db" log_file "/var/log/mpd.log" error_file "/var/log/mpd.error" pid_file "/var/run/mpd.pid" The pid_file has to be uncommented since we will run MPD in daemon mode, and we want to shut it down later. Now let’s create these files and change the owners:
sudo touch /var/lib/mpd.db /var/log/mpd.log /var/log/mpd.error /var/run/mpd.pid
sudo chown mpd /var/lib/mpd.db /var/log/mpd.log /var/log/mpd.error /var/run/mpd.pid
“mpd” being the user that will later run the daemon (if you don’t have an mpd user refer to your distro documentation on how to create one. It is really important that the mpd user is in the sour). Next we have to set some more settings:
user                            "mpd"
audio_output {
        type                    "oss"
        name                    "Direct OSS output"
}
audio_output {
        type                    "shout"
        name                    "Icecast Stream"
        host                    "localhost"
        port                    "8000"
        mount                   "/mpd.ogg"
        password                "youricecastpassword"
        bitrate                 "96"
        format                  "44100:16:1"
}
mixer_type                      "oss"
mixer_device                    "/dev/mixer"
mixer_control                   "PCM"
mixer_type                      "software"

Initializing the database:

mpd --create-db
This will insert all your songs into the database for faster access. Now MPD is set up and should work. Try with
sudo mpd
MPD will complain that it can’t connect to the Icecast server (which we’ll setup a few lines below this, but everything else should work fine.

Installing Icecast

As I said, my Music resides on a fileserver, and I want the songs to be streamed directly to my other machines, so what’s better than Icecast, an opensource streaming solution, used by many internet radios out in the wild. Luckily most distros have it in their packagemanagement software (I know openSuSe has :D ) so it shouldn’t be too hard to get it up and running, just make sure that the source password in /etc/icecast.xml matches the password you specified above, in the /etc/mpd.conf file.

Installing Pitchfork

Installing pitchfork is pretty straight forward. All you need is this:
  • PHP 5.1.3 or newer
  • PHP-Pear
  • DOM2 capable browser (firefox, konqueror, opera, safari, etc)
Please refer to your distro documentation to see how to setup these. My setup uses an apache 2 server with mod_php, and Firefox 2 on my notebook. Now to the installation itself, depending on your distribution the document root of your webserver is /var/www/htdocs or /srv/www/htdocs, change to that directory and do the following:
wget http://pitchfork.remiss.org/files/pitchfork-0.5.2.tar.bz2
tar -xvjf pitchfork-0.5.2.tar.bz2
cd pitchfork-0.5.2/
chmod a+rwx config/
The rest of the configuration is done through the browser, just point your browser to http://localhost/pitchfork-0.5.2/ if you installed pitchfork on the computer you’re currently on, or replace localhot with the IP of your server. Change whatever you’d like to change (but it should not be necessary as the important configuration is done in MPD itself), and then press Save and you’ll be taken to the Pitchfork interface. Voila, it’s all done :D

Installing mpdscribble (optional)

I’m a huge fan of Last.fm, but sadly I can’t update my profile using the Player, because the songs are streamed to it. So why not use the MPD to update them for me? For this purpose I will be using mpdscribble:
wget http://www.frob.nl/projects/scribble/mpdscribble-0.2.12.tar.gz
tar -xvzf mpdscribble-0.2.12.tar.gz
cd mpdscribble-0.2.12
./configure
make 
sudo make install
Now create the basic configuration
mkdir ~/.mpdscribble
It is suggested that mpdscribble is run as your user since it has read access to your username and password-hash. Edit the configuration file ~/.mpdscribble/mpdscribble.conf as follows: username = "lastfm_username" password = "md5sum of lastfm password" Where the md5sum can be found using either this tool or the command line md5sum tool:
echo -n "your_lastfm_password" | md5sum
And that’s it, mpdscribble is set up and ready to be run:
mpdscribble &

Further reading

cwna, Certified Wireless Network Administrator certification exams introduce new technologies of wireless networking system. ccnp boot camp offers all kinds of troubleshooting and booting techniques to tackle any systematic faults. The IT professionals are guided by giving mcp training in the effective manners. If you want more validate information for supporting and troubleshooting of computing system, a+ certification is the best IT certification in order to provide authentic training for IT professionals. The most valuable and measurable rewards are provided by cisco certification which endows perfect skills and training to the professionals of IT industry. The network+ certifications give full knowledge and information which has great significance for networking administrators.
Did you like this? Share it:

Google’s new Feed API

JSONP feeds are great! They allow you to access information in a secure way across domains, build slim mashups and keep the load off your own servers. Sadly though they aren’t as widespread as many of us would like them to be, still RSS Feeds and Atom Feeds have the majority. But now Google comes into play: the new Service from the Google Ajax API’s team Google AJAX Feed not only translates RSS and Atom Feeds into JSONP Feeds, but also caches them for you, speeding up the loading, and keeping the load off the publishers side (a feature Digg & Co. will be grateful for).

And so with only a few lines of code

<html>
  <head>
    <script type="text/javascript" src="http://www.google.com/jsapi?key=YOUR_KEY_HERE"></script>
    <script type="text/javascript">
 
    google.load("feeds", "1");
 
    function initialize() {
      var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
      feed.load(function(result) {
        if (!result.error) {
          var container = document.getElementById("feed");
          for (var i = 0; i < result.feed.entries.length; i++) {
            var entry = result.feed.entries[i];
            var div = document.createElement("div");
            div.appendChild(document.createTextNode(entry.title));
            container.appendChild(div);
          }
        }
      });
    }
    google.setOnLoadCallback(initialize);
 
    </script>
  </script></head>
  <body>
    <div id="feed"></div>
  </body>
</html>
you can grab the Digg.com feed via Javascript.

What a beautiful day to be a developer :)

Did you like this? Share it:

Y! Pipes support for Prototype

Dojo did it about a month ago, they added support for Y! Pipes to dojo.io.bind. So I figured I should write a small wrapper that works like the Prototype Ajax.Request object (as I did a few months ago for Google Calendar) for Yahoo! Pipes. So here it is: YPipe Library 0.1.

To use it just find the id of the pipe you want to request, so if the URL of the pipe is something like this

http://pipes.yahoo.com/pipes/pipe.info?_id=vp9FNLji2xGA7PYxEpPZnA

then just take the bold part of it and create a new request just like this:

cal = new YPipe("vp9FNLji2xGA7PYxEpPZnA",{
    onsuccess: someFunction
  });

This immediately fires up the request and after completing the someFunction will be called with the first argument being the returned JSON-Object. It’s as simple as it gets :-P

For a quick demo head over here.

Did you like this? Share it:

GCalendar: Accessing Google Calendar from JavaScript

Introduction

Some weeks ago Google has added a nice new feature to their GData libraries: JSON data retrieval. This means that we now can retrieve data from some services of Google (Base, Blogger and Calendar for now) without having to proxy it through our servers (if you still don’t know, after thousands of posts about Cross-Domain issues, why you need to do this, just look here).

Why can we do this? Because we can just create a <script>-Element, points the src to the feed URL and tell the GData API what function to call upon load.

 
var headTag = document.getElementsByTagName('head')[0]; 
var script = document.createElement('script'); 
script.type = 'text/javascript'; 
script.src = feedurl; 
headTag.appendChild(script);

I was a bit sorry to see that Google doesn’t provide an API for Client side JavaScript. So once again, in one of those “don’t complain, do it better“-moments I figured it would be nice to write it myself for the Calendar. Off course some stuff can’t be done with JavaScript, we can only retrieve data, not submit new data to Google, so we can’t add new entries directly, but hey it’s a start :D

The library

We start off by modelling the Entry class, as you might easily figure out by the following code we rely on the Prototype library.

 
var EventEntry = Class.create();
EventEntry.prototype = {
	title: null,
	content: null,
	startDate: null,
	endDate: null,
	location: null,
	initialize: function(entry){
		this.title = entry.title.$t;
		this.content = entry.content.$t;
		this.startDate = DateConverter.rfc3339toDate(entry.gd$when[0].startTime);
		this.endDate = DateConverter.rfc3339toDate(entry.gd$when[0].endTime);
		this.location = entry.gd$where[0].valueString;
	}
};

Next we create a class that takes care of loading the feed, calling the callbacks and so on.

 
var Calendar = Class.create();
Calendar.prototype = {
	uri: "7cghno42lleqpbihmoi5qiikm8%40group.calendar.google.com",
	orderby: "starttime",
	singleEvents: true,
	futureEvents: true,
	sortOrder: "ascending",
	entries: {},
	initialize: function(u){
		if(u){this.uri = u;}
	},
	
	buildURL: function(){
		var str = "http://www.google.com/calendar/feeds/";
		str += this.uri;
		str += "/public/full-noattendees?orderby=" + this.orderby;
		str += "&alt=json-in-script&callback=window.activeCalendar.parseFeed&";
		str += "singleevents=" + this.singleEvents;
		str += "&sortorder=" + this.sortOrder;
		str += "&futureevents=" + this.futureEvents;
		return str;
	},
	
	loadFeed: function(){
		window.activeCalendar = this;
		var headTag = document.getElementsByTagName('head')[0]; 
		var script = document.createElement("script");
		script.src = this.buildURL();
		script.language = "JavaScript";
		headTag.appendChild(script);
	},
 
	parseFeed: function(json){
		e = json.feed.entry;
		for(var i=0;i < e.length;i++){
			this.entries[i] = new EventEntry(e[i])
		}
		try {
			this.onsuccess(this);
      } catch (e) {}
	},
	
	onsuccess: function(c){}
};

Notice the first line of the loadFeed? Yep, it’s a workaround, and an ugly one too. The problem is that we want to have access to the Calendar-object once we have the feed data. So we add it to the window-object. Anyway, this is the reason why you can load only one calendar at once.
And what would we be without some really ugly utility objects? So here you go, a pretty useless date converter class:

 
/**
 * Singleton object used to convert Dates from one format to another.
 */
var DateConverter = {
	rfc3339toDate: function(t){
		t = t.substr(0,19).replace(/-/g,"/").replace("T"," ");
		var dt = new Date();
		dt.setTime(Date.parse(t));
		return dt;
	}
};

So after all this code that you don't have to write (because you can download it all here) now some code you have to write.

How to use it

I tried to keep it as simple as possible, if there are enough requests I may well extend it further, but for now it works nicely as it is. First you have to find out the feed identifier. Take the Feed URL as can be found in Google Calendar in the Calendar details and it will look something like this:

http://www.google.com/calendar/feeds/7cghno42lleqpbihmoi5qiikm8%40group.calendar.google.com/public/basic

Take the bold part and that's the Feed Identifier that will then be used to create the instance of the Calendar:

 
var cal = new Calendar("7cghno42lleqpbihmoi5qiikm8%40group.calendar.google.com");

Next thing we need to do is add a callback function that is called once the Feed is loaded, and then kick the request off:

 
cal.onsuccess = function(c){alert(c);}
cal.loadFeed();

And that's it :P
Now let's see what we can do with it, and the reason I started fiddling with the Calendar in the first place. My custom frontend to one of my calendars can be seen here.

The main objective of advertising is to give detailed information about any kind of products in order to increase the number of potential customers. The dedicated servers provide the perfect managed web hosting solutions with great efficiency and productivity. You have a lot of opportunities to do work at home by surfing different freelancing jobs via internet. The application of website development software helps a lot to enhance the speed of web designers to develop new web designs. The internet advertising has opened a new horizon to run marketing campaigns on the large scale to have direct access to the extensive range of the customers. The wireless camera is designed by the implementation of the advanced technology of wireless networking system.
Did you like this? Share it:

htmlPlayground, the Ajax way of doing a reference

Ever tried to remember what a particular HTML-Tag does, and how to use it in a standard way? Well now you can, in a stylish way: htmlPlayground!
Advertisement BadgeIt’s worth trying to learn HTML because you may find that learning HTML is easier than you would have thought.
htmlPlayground is build on top of Google Webtoolkit and has the complete set of XHTML 1.0 strict Tags and CSS 2 attributes (although I couldn’t get it to work when I tested it). htmlPlayground Personally, I just love it :-D [via Ajaxian]
Did you like this? Share it: