Created
October 17, 2009 15:43
-
-
Save roblingle/212375 to your computer and use it in GitHub Desktop.
Use iTunes on Windows to control what's playing in XBMC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assumes that your Music library is shared out | |
# and XBMC accesses it via Windows filesharing. | |
# | |
# Install the xbmc gem: gem install xbmc (may also need to run 'gem sources -a http://gemcutter.org') | |
# Edit the variables below and save as intune.rb | |
# Run 'ruby intune.rb'. | |
require 'win32ole' | |
require 'xbmc' | |
# h:\music\library is shared as "music" by "luna", the fileserver | |
server_library = 'H:/Music/Library/' | |
xbmc_library = 'smb://luna/music/' | |
xbmc_host = 'xbox' | |
period = 2 # time between checks, in seconds | |
xbox = XBMC.new(xbmc_host) | |
itunes = WIN32OLE.new('iTunes.Application') | |
current_track = nil | |
track_completed = false | |
loop do | |
begin | |
if itunes.PlayerState == 1 # if iTunes is playing | |
xbox.clear_playlist unless current_track | |
xbox.unpause if xbox.paused? | |
if current_track != itunes.CurrentTrack.Name | |
track = itunes.CurrentTrack.Location.gsub("\\","/") | |
track.gsub!(server_library,xbmc_library) | |
xbox.queue(track) | |
xbox.play_next unless track_completed && xbox.playing? | |
current_track = itunes.CurrentTrack.Name | |
puts "Queued: #{current_track}" | |
end | |
track_completed = (itunes.CurrentTrack.Duration - itunes.PlayerPosition) <= period | |
else | |
xbox.pause unless xbox.paused? | |
end | |
rescue Exception => e | |
current_track = nil | |
puts e | |
puts | |
end | |
sleep period | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment