2007/05/19

rubyosa-0.4.0 - iTunes

rubyosa の OSA.app('iTunes') を細分化してみた。

# Created by midore on 2007-05-16.
# 2007-04-25.rb
# ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
# rubyosa-0.4.0
# iTunes 7.11

class Song < Struct.new(:song, :name, :artist, :album, :yearr)

  def to_s
   "#{self.name} : #{self.album} (#{self.artist})_#{self.yearr}"
  end

  def self.song
    self.song
  end

end

class SongList

  def initialize(songs=Itunes.new.librarysongs)
    @songs = songs
  end

end
  
class Itunes

  def initialize
    @itunes = OSA.app('iTunes')
  end

  def librarysongs
    songs(obj_library)
  end

  def top25songs
    songs(obj_top25)
  end

  def songs(list)
    ary = Array.new
    list.tracks.each{ |song| 
      ary << Song.new(song, song.name, song.artist, song.album, song.year)
    }
    return ary
  end

  private

  def obj_library
    obj_playlists.find{ |x| x.name == "ライブラリ"}
  end

  def obj_top25
    obj_playlists.find{ |x| x.name == "トップ 25"}
  end

  def obj_playlists
    obj_sources.each { |source| return source.playlists}
    #<OSA::ObjectSpecifierList:0x326004 desired_class=OSA::ITunes::Playlist>
  end

  def obj_sources
    @itunes.sources    #OSA::ObjectSpecifierList
  end

end

require 'rbosa'
OSA.utf8_strings = true

song = Itunes.new.top25songs.first.song
puts song.name
song.play

song = Itunes.new.obj_library.first.song
とすると、
曲はスタートするがウィンドウのカレントの曲を示すアイコンが移動しない。くわえてメニューの現在の曲の情報もみられないのはなぜだろう。

--imported_from
http://www.midore.net/daybook/2007/05/1179559483.html

+++ 追記 +++
2010-02-06

関連する記事
"RubyOSA"ラベルがついた全ての記事

0 件のコメント: