suburbia

Premshree's (品速力) Personal Weblog

etc.

Previous Entry Add to Memories Tell a Friend Next Entry
I’m listening to...
suburbia
[info]premshree

That’s the current song playing on my system. It’ll appear on my blog’s right. Requires XMMS bindings for Ruby and Ruby-GD (I don’t know the links to the websites.)

Ruby code »

#!/usr/local/bin/ruby

#
# $currsong.rb$ $2005-02-28 23:49$
# $premshree pillai$
#

require 'xmms'
require 'GD'
require 'net/ftp'

def do_current_song
	def ftp_image(image)
		ftp = Net::FTP.new($server_ftp)
		ftp.login($server_user, $server_pass)
		files = ftp.chdir($server_path)
		ftp.putbinaryfile(image)
		ftp.close
	end

	remote = Xmms::Remote.new
	song_title = remote.title

	image = GD::Image.new($image_width, $image_height)
	white = image.colorResolve(255,255,255)
	black = image.colorResolve(0,0,0)
	x = 0
	y = 10
	(err, brect) = image.stringTTF(black, $font_path, $font_size, $angle, x, y, song_title)

	if err
		puts err
		exit 1
	end

	file = open($file_name, 'wb')
	image.png file
	image.destroy
	file.close
	ftp_image($file_name)
end

##
# required stuff
##
$file_name = 'curr_song.png' # outputs this file
$font_path = '/path/to/some/font'
$server_ftp = 'ftp.myserver.com'
$server_user = 'foo'
$server_pass = 'bar'
$server_path = '/path/to/dir'

##
# for your pleasure
##
$angle = 0
$font_size = 8.0
$image_width = 200
$image_height = 12

do_current_song

Enjoi!


I seriously wish I understood all that...

He is defining a function to ftp a file.

Then calls the XMMS library to get the title of the current song.

Calls the GD library to create an image with some text formatting.
Creates a png file out of that image and ftp's it to a server.

Premshree,I didnot look at the rss, but r u displying the current song
and not the current one when u posted the blog?


but r u displying the current song
and not the current one when u posted the blog?

This is just an annexure to the many panels he has on his blog. Even if he hasn't posted anything on his blog, this part would keep updating whenever this script is running and he's listening to music! :p

It changes with the song I play. It could’ve changed to something else by now.

If you've got the diskspace, what you could do is stick all older images into a directory (counting back say upto 1 week) and then provide a link to that directory so that I can know what sorta music you have listened to for the past year :)

An even more innovative hack would be to grab the title and query the CDDA database and grab meta-data info and display that too ... ;/

IAC -- nifty hack, dude! :)

I did think of the directory thing—I thought of creating an OPML feed. Maybe I’ll do it later.

What corny songs have you been listening to?

Where's all the metal?

You mean dance bar numbers? :-p