Premshree Pillai ([info]premshree) wrote,
@ 2005-03-01 00:06:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Current music:Beck - Lost Cause

I’m listening to...

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!



(Post a new comment)


[info]nash_da_basher
2005-02-28 06:57 pm UTC (link)
I seriously wish I understood all that...

(Reply to this)(Thread)


[info]mansu
2005-02-28 07:29 pm UTC (link)
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?

(Reply to this)(Parent)(Thread)


[info]teemus
2005-02-28 07:46 pm UTC (link)
http://premshree.org/journal/curr_song.png

Very clever. Neat work, dude.

(Reply to this)(Parent)


[info]teemus
2005-02-28 07:48 pm UTC (link)
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

(Reply to this)(Parent)(Thread)


[info]premshree
2005-02-28 09:00 pm UTC (link)
Righto!

(Reply to this)(Parent)


[info]premshree
2005-02-28 09:01 pm UTC (link)
It changes with the song I play. It could’ve changed to something else by now.

(Reply to this)(Parent)(Thread)


[info]ravi
2005-05-05 01:50 pm UTC (link)
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! :)

(Reply to this)(Parent)(Thread)


[info]premshree
2005-05-05 03:21 pm UTC (link)
I did think of the directory thing—I thought of creating an OPML feed. Maybe I’ll do it later.

(Reply to this)(Parent)


[info]freegeek
2005-03-01 08:03 pm UTC (link)
What corny songs have you been listening to?

Where's all the metal?

(Reply to this)(Thread)


[info]premshree
2005-03-01 08:05 pm UTC (link)
You mean dance bar numbers? :-p

(Reply to this)(Parent)


Create an Account
Forgot your login?
Login w/ OpenID
English • Español • Deutsch • Русский…