suburbia

Premshree's (品速力) Personal Weblog

etc.

Previous Entry Add to Memories Tell a Friend Next Entry
What’s playing
suburbia
[info]premshree

I play all my music from iTunes now (most of it is on my FreeBSD box, though, served using mt-daapd). Anyway, time to update my current song script:

#!/opt/local/bin/ruby

require "rubygems"
require "net/ssh"
require "net/sftp"

script = <<SCRIPT
        tell application "iTunes"
                set {art, nm} to {artist of current track, name of current track}
                set disp to art & " - " & nm
                if disp is "" then
                        set disp to current stream title
                end if
                return disp
        end tell
SCRIPT

song = `osascript -ss -e '#{script}'`.chomp

exit if song == ""

`convert -fill black -pointsize 12 'label:#{song}' curr_song.png`

Net::SFTP.start("<host>", "<username>", "<password>") do |sftp|
        File.open("songs.txt", "a") { |f| f.write "#{song} (#{Time.now.to_s})\n" }
        ["songs.txt", "curr_song.png"].each { |file|
                sftp.put_file(file, "public_html/journal/#{file}")
        }       
end

Yeah, that’s a bit of AppleScript in there.

I’ve set it up to run every ten minutes. It also generates a list of all the songs I’ve played. I can probably use that data to figure not-so-useful patterns.


bash$ dcop amarok playlist saveCurrentPlaylist &&
       xsltproc ~/hacks/amarok.xsl ~/.kde/share/apps/amarok/current.xml -o ...

And are you using my FreeBSD port of mt-daapd ?

I've never coded in Ruby, but that's some beautiful code there.

When you have a hammer ...

[info]t3rmin4t0r

2006-06-05 10:18 am (UTC)

His code is hardly in ruby ... for all it's there, it could've been a shell script which called applescript, convert and sftp.

One of those cases where it was done in ruby because *Premshree* was between the chair and keyboard ...

Re: When you have a hammer ...

[info]bipin

2006-06-05 10:26 am (UTC)

I wasn't talking about how well the code was 'written', but how naturally the first bit seemed to be 'expressed'. Very pseudo-codish to me.

And to a certain extent, I'd like to give credit to the syntax of the language.

Maybe you could force such intuitive clarity in a shell-script. I certainly can't.

Re: When you have a hammer ...

[info]t3rmin4t0r

2006-06-05 10:29 am (UTC)

> but how naturally the first bit seemed to be 'expressed'. Very pseudo-codish to me.

Apple Script: The Natural Language Metaphor.

Worship the right stuff :)

Re: When you have a hammer ...

[info]bipin

2006-06-05 12:06 pm (UTC)

Aah. My bad :)

Re: When you have a hammer ...

[info]premshree

2006-06-05 11:54 am (UTC)

Well, yeah, that first bit is all AppleScript. :-)

This obviously isn't an issue for personal use, but I recommend using #!/usr/bin/env ruby. It searches PATH for ruby and executes it. This obviously makes the script more portable. Some people are bothered by it because you don't have much control over which version is picked but I think that if you need that much control you should just edit the darn line.

Oh yeah, that’s what I normally use. I have 1.8.2 and 1.8.4 on my box; I was using the ports one this time.

Re: Tip

(Anonymous)

2006-07-13 09:21 am (UTC)

Why not just use #!ruby ?

If you were on linux

[info]spo0nman

2006-06-06 08:45 am (UTC)


You would be *using* amarok. :)


Re: If you were on linux

[info]premshree

2006-06-06 12:39 pm (UTC)

Well, now that I have a Linux box, I’ll probably move all my music there. Also gives me more to hack on. :-)

Compiling kdelibs now...

Flickr.rb??

(Anonymous)

2006-06-12 09:06 pm (UTC)

Hey

Was out looking for the flickr.rb that you wrote, do you know where can I get the latest version? Couldn't find it on rubyforge ;(

Really Ruby is cool, Am a PHP developer and am amazed with ROR want to learn it please any one help me out...

please write me to maq005@yahoo.com or maqs24@gmail.com


Another alternative

(Anonymous)

2006-07-13 09:22 am (UTC)

Have you taken a look at http://last.fm ?