Entries from April 2007 ↓
April 29th, 2007 — Ruby
I wrote the entire UI for my “Simple Skype” front end in wxRuby. wxRuby’s benefit comes from it’s use of widgets native to the window manager (i.e., Aqua on Mac OS X, etc.). And, while I only had a few problems with it, most of my problems were PEBKACs.
Sadly, the memory leak in my GUI, caused by the use of Bitmaps, was not among my PEBKACs. This is currently tracked as an open bug against Wx. It is unfortunate that this issue has apparently not received much attention since it was noted three years ago…
Continue reading →
April 26th, 2007 — Ruby, Skype
This one adds a moderate helping of contact management not limited to but include the ability to access lists of online friends, users awaiting authorization, all known users, and others. Also, it adds the ability to access various pieces of information about known users, blocking and unblocking of users, and much more.
0.2.0 may be the last release for a while as it should accomodate most of the features that I will need for my coming Skype project.
Download link and as well as gem install instructions and sample code are here.
April 24th, 2007 — Ruby
Working on rb-skypemac 0.2.0, I found myself in the position of either implementing 40 getter/setter pairs by hand or writing some meta code. I always prefer to write meta code. If you don’t, seek treatment — or else you will soon find yourself in treatment of the straight jacket variety.
Anyhow, as I’m writing this meta code, I realized that I needed to delay the evaluation of a variable inside a String, i.e., delaying the evaluation of #{stuff} within “This is a load of #{stuff}”. Why? Because I didn’t have the variable yet! The variable is an instance variable and my meta code generating method is at the class level. So I began to stress. And then I figured, what the hell; I’ll just escape the ‘#’ because that would just make sense.
You know what? It just worked.
Matz did one fine job designing several portions of this language!
Example below:
class User
def User.skypeattrreader(attrsym)
attrsym.each do |a|
moduleeval %{def #{a.tos}
# The line below is the REALLY cool part
r = Skype.send_ :command => “get user \#{@handle} #{a.to_s}”
r.sub(/^.#{a.to_s.upcase} /, “”)
end}
end
end
skype_attr_reader :fullname, :birthday, :sex, :language, :country, :province
April 22nd, 2007 — Ruby, Skype
April 21st, 2007 — Appscript, Mac OS X Software, RubyOSA, Skype
Since I discovered rubyosa, I’ve made it one of my side projects to improve the accessibility of my wife’s iMac. She loves to use Skype to video chat with her mother in Maryland and her brother in New York. However, the tiny buttons in Skype cause the UI to be problematic for her.
What to do?
I planned (and still do) to write a simple UI for Skype with larger buttons and fonts. However, in order to do so, I needed an interface that would allow me to do more than merely send commands to Skype. Sadly, rubyosa falls down here.
But then I found rb-appscript or just appscript. Appscript seems to provide a more direct connection to the Applescript Event layer and it provides return values from Applescript unlike the current 0.4.0 version of rubyosa.
All said, I implemented a small subset of the Skype API as a gem. I’ve submitted it to RubyForge for addition as a project. Until then, I give you rb-skypemac-0.1.0.
I have yet to decide if I will take this gem further. If it proves adequate for my needs, I may just move on to my next project: a more feature complete version of rb-itunes than what has been submitted to RubyForge.
[Get it here: rb-skypemac]
April 17th, 2007 — Ruby, WIN32OLE, iTunes
I wrote this one for my father as he has several audio tapes worth of MP3s to put into iTunes on Windows. It reads down through a directory structure for music files, using the nested directory names as metadata. It expects a nested directory structure as follows:
Root Dir
|- Artist Dirs
|- Album Dirs
|- Music files
Admittedly, this is my first usage of yield in anger. It hurt — but now my brain has been further fortified with vitamin Ruby.
Code follows…
Continue reading →
April 15th, 2007 — Ruby, Ruby on Rails, WIN32OLE, iTunes
Ok, I’ve been a bit compulsive about having artwork for my movies and music in iTunes since we got our AppleTV. Ok, maybe more than a bit.
Even so, this little Rails application should give you some idea of how simple it is. It uses Amazon’s web service (which, it turns out, I misjudged), to look up candidate artwork for each album and displays them to you. You simply click on the desired image (higher resolution is typically better) and it will insert that artwork into iTunes for each track in your album.
I won’t pretend that this is the cleanest implementation but it gets the job done. If any of you watching at home want to play along, you will also need ruby/amazon installed.
FYI: Amazon’s search engine may not resolve all of your album names. You may want to manually search Amazon, in the case of stubborn albums, to determine what Amazon calls the album. However, more often than not, this shouldn’t be a problem if you ripped using iTunes.
Finally, this program could be easily adapted for hunting down artwork for your movie collection as well.
Code follows:
Continue reading →
April 10th, 2007 — Ruby, RubyOSA, Skype
For my next trick, I was going to sling together a UI to help my wife manage Skype. But then I found that the Skype API is a little more painful than just RubyOSA.
I discovered that RubyOSA comes with a built in script to generate RDoc for any AppleScript-supporting application that has a defined AppleScript definition. How handy! “rdoc –name Skype” and off I went. Or so I thought. Skype’s AppleScript API is simple: they give you one command that accepts commands using their protocol.
Not entirely dissuaded, I started my campaign to create a script to change the status of my iChat, Adium, and Skype (yes, I need all three — don’t you???) simultaneously.
To automate things further, I deposited the script in ~/Library/Application Support/Quicksilver/Actions. I then input the command (on, off, or away) via Quicksilver using ‘.’ to let me enter a command and then my script shows up as a target. I then created Quicksilver hotkeys for online (CTRL-CMD-UP), offline (CTRL-CMD-DOWN), and away (CTRL-CMD-LEFT or “exit stage left” as I see it). So, finally, my IM status should reasonably reflect when I’m actually on or off.
If you want to use this script:
- Bear in mind, your Ruby binary is probably installed somewhere other than /usr/local/bin/ruby so you’ll need to tweak that line.
- You’ll need rubygems installed
- You’ll need the RubyOSA gem installed
No, Steve, I was not up all night working on this.
[Download] (right click “Save Link As”)
Update (3/12/07): Since made some minor tweaks to support custom away messages for Adium and iTunes. Of course, to make this “sexy” (extensible), I’d scan a subdirectory for “plugins” that would manage the status per IM application allowing for you Mac users who use Fire instead of Adium, for example.
#!/usr/local/bin/ruby
require 'rubygems'
require 'rbosa'
def get_app(app_name)
app = OSA.app(app_name)
if app.nil?
puts "#{app} does not exist"
exit
end
app
end
$Adium = get_app "Adium"
$iChat = get_app "iChat"
$MESSAGE = {
:on => "Available",
:away => "Away",
:off => "" # moot anyway
}
$STATUS = {
:Skype => {
:off => "OFFLINE",
:on => "ONLINE",
:away => "AWAY"
},
:Adium => {
:off => OSA::Adium::ASST::OFFLINE,
:on => OSA::Adium::ASST::AVAILABLE,
:away => OSA::Adium::ASST::AWAY
},
:iChat => {
:off => OSA::IChat::MSTA::OFFLINE,
:on => OSA::IChat::MSTA::AVAILABLE,
:away => OSA::IChat::MSTA::AWAY
}
}
def is_known_status?(app, status)
$STATUS[app].has_key? status
end
def set_Skype_status_to(status)
if not is_known_status? :Skype, status
# No custom statuses with Skype, sorry!
status = :away
end
app = get_app “Skype”
request = “SET USERSTATUS #{$STATUS[:Skype][status]}”
app.send2 request, “”
end
def set_Adium_status_to(status)
if is_known_status? :Adium, status
$Adium.adium_controller.my_status_type = $STATUS[:Adium][status]
$Adium.adium_controller.my_status_message = $MESSAGE[status]
else
$Adium.adium_controller.my_status_type = $STATUS[:Adium][:away]
$Adium.adium_controller.my_status_message = status.to_s
end
if status == :on
$Adium.adium_controller.accounts.each { |a| a.connect }
end
end
def set_iChat_status_to(status)
if is_known_status? :iChat, status
$iChat.status = $STATUS[:iChat][status]
$iChat.status_message = $MESSAGE[status]
else
$iChat.status = $STATUS[:iChat][:away]
$iChat.status_message = status
end
end
status = ARGV[0].intern
set_Skype_status_to status
set_Adium_status_to status
set_iChat_status_to status
April 8th, 2007 — Amazon, Ruby, iTunes
I have a problem. Or rather my wife does. She loves the AppleTV but it’s difficult for her to find content for her to watch. Why? Because our video content, other than genre metadata (added by hand — blech!), contains no metadata! Once again, coding to the rescue.
The ingredients:
- Ruby (my language of choice du jour)
- ruby-amazon - Clients itself to Amazon’s web service to perform keyword searches. Major caveat: The search results are nowhere near as accurate as those provided on the Amazon web site. I found this surprising. Why this has not been made into a Winblows XP Media Center Edition 2005 so that the wifey can have her relatively stable Windows Media Center as opposed to our previously slightly less stable, although somewhat more hacker friendly, SageTV.
At the moment, the program fetches descriptions, years (from the DVD release date, sadly, and not the original movie release, and DVD cover artwork from Amazon.com). As Amazon’s web service provides spurious accuracy, the program prompts me to select from one of ten candidate Amazon products to use as a source of metadata for any given movie.
The obnoxious part? I have yet to figure out how to programatically add artwork to a movie (IITTrack.AddArtworkFromFile barfs all over me) even though I am fetching it from Amazon.
require 'amazon/search'
require 'pp'
require 'win32ole'
#require 'net/http'
require 'uri'
$AWS_KEY = 'XXXXXXXXXXXXXXXXXXXX' # bleeped out to protect the innocent
$ART_PATH = 'f:/movies/artwork/'
$app = WIN32OLE.new 'iTunes.Application'
exit if $app.nil?
$movies = $app.LibrarySource.Playlists.ItemByName 'Movies'
def find_dvd(title)
retval = []
req = Amazon::Search::Request.new $AWS_KEY
res = req.keyword_search(title, ‘dvd’)
i=1
res.products.each do |p|
puts “#{i}. #{p.product_name} (#{p.release_date})”
i+=1
end
print “>> ”
input = gets
if input.match /s/
return nil
end
input.match /(\\d+)/
res.products[$1.to_i - 1]
end
def get_artwork(movie_track, movie_meta)
response = Net::HTTP.get_response(URI.parse(movie_meta.image_url_large))
title = movie_track.Name
title.gsub! ‘:’, ‘-’
art_filename = “”
art_filename << $ART_PATH << title << ".jpg"
File.open( art_filename, 'wb') do |f|
f << response.body
f.flush
end
art_filename
end
def update_metadata_for(movie_track)
track = movie_track
meta = find_dvd movie_track.Name
if meta.nil?
return
end
if meta.release_date
meta.release_date.match /, (\\d+)$/
track.Year = $1
end
art_filename = get_artwork track, meta
if track.Artwork
puts track.Artwork
track.AddArtworkFromFile art_filename
end
if meta.product_description
meta.product_description.gsub!( /<(\\/?)(\\w+)>/, “”)
meta.product_description.gsub!( /\\s\\s.*/, “”)
puts meta.product_description
track.Description = meta.product_description
end
end
idx = 1
count = $movies.Tracks.Count
while idx <= count do
movie = $movies.Tracks.Item idx
puts movie.Name
if movie.Description == ""
update_metadata_for movie
end
idx += 1
end