Author | Message | Time |
---|---|---|
Newby | I'm developing a plugin for X-Chat that utilizes XMMS. Sort of like a Battle.net bot that utilizes Winamp. Here's what I have so far. If you want to help correct sloppy errors/bugs, feel free. Take note: I did not know Perl before I undertook this project. That's why my Perl is horrible. :P Also take note: There's no documentation on how to use Xmms() or Xmms::Remote, so I had to use the 'test.pl' that came with it as a reference of what functions I could access. Damn that source is sloppy. :( I also used the documentation for X-Chat Perl plugins located here. Requires: X-Chat 2.0.8 or higher, Xmms(), and Xmms::Remote() [code]#!/usr/bin/perl -w # XMMS / X-Chat Plugin # Written by newby # http://www.x86labs.org use Xmms (); use Xmms::Remote (); # Register the plugin with X-Chat. Xchat::register("x86-xmms-xchat", "0.2", "XMMS plugin for X-Chat", \&unload); Xchat::print("Loading x86-xmms-xchat... please wait."); # Register the "mp3" command for now. # We're going to register it to a variable, so we can unhook it later. my $mp3hook = Xchat::hook_command("mp3", \&sendmp3tochannel); # This sub is called whenever the plugin is unloaded. sub unload() { Xchat::unhook($mp3hook); Xchat::print("Unloading x86-xmms-xchat... please wait."); } # DO NOT EDIT FROM BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING. # Ok fine, that's a lie. Just don't blame me if you break something. =P sub sendmp3tochannel() { my $xmms = Xmms::Remote->new; if (! $xmms->is_running) { Xchat::command("say Error: xmms is not currently running! Boo! Turn on xmms loser! :("); } else { my $song = $xmms->get_playlist_pos(); my $song2 = $xmms->get_playlist_title(); my $songpos = parse_time($xmms->get_output_time); my $songlen = parse_time($xmms->get_playlist_time); my @songinfo = $xmms->get_info(); Xchat::command("me is currently listening to $song. $song2 [$songpos of $songlen] [".($songinfo[0]/1000)."kbps]"); # my $file = $xmms->get_playlist_file($song); } } sub parse_time() { my $xmms_time = shift; my $seconds = $xmms_time / 1000; my $minutes = $seconds / 60; $seconds = $seconds % 60; return sprintf("%02d:%02d", $minutes, $seconds); }[/code] Thoughts? Comments? :) EDIT -- I eventually plan to read the individual tags out of the MP3 file, so that I can allow for an easier customization. But for now, I'm happy with this. | July 8, 2005, 8:11 PM |