Created
June 15, 2009 17:18
-
-
Save JamesHarrison/130222 to your computer and use it in GitHub Desktop.
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
# this goes in xchat's program files directory | |
title = 'Unknown Song' if title.empty? | |
artist = 'Unknown Artist' if artist.empty? | |
srate = track.samplerate / 1000.0 | |
string = "me is listening to \"\0034\002#{title}\002\003\" by \0034#{artist}\003" | |
string = "#{string} from \0034#{album}\003" unless album.empty? | |
string = "#{string} [#{position}..#{length}/#{track.bitrate}kbps/#{srate % 1 == 0 ? srate.to_i : srate}khz]" | |
puts string | |
## install: just put these files in the right place and /rb load itunes.rb |
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
# Goes into C:\Documents and Settings\USERNAME\Application Data\X-Chat 2 | |
require 'win32ole' | |
require 'stringio' | |
include XChatRuby | |
class ITunesAnnounce < XChatRubyPlugin | |
def initialize | |
helpstr = <<HELPSTR | |
[Help] iTunesAnnounce | |
/itunes (announce current song to the active channel window) | |
/itunes play (play track) | |
/itunes pause (pause track) | |
/itunes stop (stop playing) | |
/itunes replay (replay track or play previous track if at the beginning of the current track) | |
/itunes forward (fast forward track) | |
/itunes rewind (rewind track) | |
/itunes resume (stop fast forwarding or rewinding and resume normal playback) | |
/itunes next (play next track) | |
/itunes prev (play previous track) | |
/itunes quit (quit iTunes) | |
/itunes mute (mute iTunes player) | |
/itunes unmute (unmute iTunes player) | |
/itunes vol=n (adjust the volume of iTunes, where `n' is a number from 0 to 100) | |
/itunes volume=n (same as /itunes vol=n) | |
HELPSTR | |
hook_command('np', XCHAT_PRI_NORM, method(:announce), helpstr) | |
end | |
def announce(words, words_eol, data) | |
app = WIN32OLE.new('iTunes.Application') | |
track = app.CurrentTrack | |
if words[1] | |
words[1].strip! | |
case words[1].downcase | |
when 'play' then app.Play | |
when 'pause' then app.Pause | |
when 'stop' then app.Stop | |
when 'replay' then app.BackTrack | |
when 'forward' then app.FastForward | |
when 'rewind' then app.Rewind | |
when 'resume' then app.Resume | |
when 'next' then app.NextTrack | |
when 'prev' then app.PreviousTrack | |
when 'quit' then app.Quit | |
when 'mute' then app.Mute = true | |
when 'unmute' then app.Mute = false | |
when /^vol(?:ume)?=(\d+)$/ | |
vol = $1.to_i | |
if vol < 0 or vol > 100 | |
puts "iTunesAnnounce: Volume must be set between 0-100" | |
else | |
app.SoundVolume = $1 | |
end | |
else puts "iTunesAnnounce: Unknown command: #{words[1]}" | |
end | |
return XCHAT_EAT_ALL | |
end | |
unless track | |
puts "iTunesAnnounce: iTunes isn't playing anything" | |
return XCHAT_EAT_ALL | |
end | |
title = track.Name.strip | |
artist = track.Artist.strip | |
album = track.Album.strip | |
position = "#{(_pos = app.PlayerPosition) / 60}:#{'%02d' % (_pos % 60)}" | |
length = track.Time.strip | |
samplerate = track.SampleRate.to_i | |
bitrate = track.BitRate.to_i | |
$stdout = StringIO.new(_str = '') | |
Kernel.module_eval(File.read('announce.rb')) | |
_str.strip! | |
if _str.empty? | |
puts "iTunesAnnounce: Nothing to output!" | |
else | |
command(_str) | |
end | |
return XCHAT_EAT_ALL | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment