Clan x86

Technical (Development, Security, etc.) => General Programming => Topic started by: Newby on October 30, 2005, 12:58:13 am

Title: Perl MP3 Script for X-Chat
Post by: Newby on October 30, 2005, 12:58:13 am
Yes. I figured I'd post it, since it's so totally amazingly elite.

x86-xmms-xchat.pl (http://www.newbyproductions.net/downloads/x86-xmms-xchat.pl)

#!/usr/bin/perl -w

# http://www.x86labs.org/
# http://www.slacktech.com/~newby/
# Special thanks to whatever tutorials helped me along the way.
# Come chat with us on irc.tehnet.org!

use Xmms::Remote ();

# Register the plugin with X-Chat.

Xchat::register("x86-xmms-xchat", "0.3", "XMMS plugin for X-Chat", \&unload);
Xchat::print("Loading x86-xmms-xchat... please wait.");

# Register the command to a variable.

my $mp3hook = Xchat::hook_command("mp3", \&sendmp3tochannel);

# Randomize the seed!

srand();

# This sub is called whenever the plugin is unloaded.

sub unload()
{
    Xchat::unhook($mp3hook);
    Xchat::print("Unloading x86-xmms-xchat... please wait.");
}

######################################################################################################################
# This is for the mp3 command stuff.                                                #
######################################################################################################################

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()) + 1);
        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();
        my $prefix = get_prefix();
        Xchat::command("me $prefix $song. $song2 [$songpos of $songlen] [".($songinfo[0]/1000)."kbps]");
#       my $file = $xmms->get_playlist_file($song);
#       We'll finally use this when I get unlazy and figure out how to parse tags out of a file! :P
    }
}

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);
}

sub get_prefix()
{
    open(FILE, "prefix-list.txt") || return "is currently listening to";
    my @prefixes = <FILE>;
    my $prefix = $prefixes[rand @prefixes];
    close(FILE);
    chomp($prefix);
    return $prefix;
}

Example output:

Quote
* newby_ is currently listening to Aggression - Metal Slaughter [02:14 of 03:57] [320kbps]
* newby_ is currently listening to Aggression - Metal Slaughter [02:14 of 03:57] [320kbps]
* newby_ is currently listening to Aggression - Metal Slaughter [02:15 of 03:57] [320kbps]
* newby_ is currently listening to Aggression - Metal Slaughter [02:15 of 03:57] [320kbps]
* newby_ eats babies while listening to Aggression - Metal Slaughter [02:23 of 03:57] [320kbps]
* newby_ starts a circle pit to Tempter - Don't Get Mad...Get Evil [00:16 of 03:53] [320kbps]
* newby_ starts a circle pit to Tempter - Don't Get Mad...Get Evil [00:17 of 03:53] [320kbps]
* newby_ is headbanging to Tempter - Don't Get Mad...Get Evil [00:18 of 03:53] [320kbps]
* newby_ thrashes out to Tempter - Don't Get Mad...Get Evil [00:19 of 03:53] [320kbps]
* newby_ is getting his ass kicked by Tempter - Don't Get Mad...Get Evil [00:20 of 03:53] [320kbps]
Title: Re: Perl MP3 Script for X-Chat
Post by: Sidoh on October 30, 2005, 01:20:27 am
Leetness man.
Title: Re: Perl MP3 Script for X-Chat
Post by: Joe on November 03, 2005, 08:11:16 pm
 Error loading '/home/joe/.xchat2/plugins/x86-xmms-xchat.pl':
 Can't locate Xmms/Remote.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.7 /usr/local/share/perl/5.8.7 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at (eval 3) line 8.
 BEGIN failed--compilation aborted at (eval 3) line 8


lolcrap.
Title: Re: Perl MP3 Script for X-Chat
Post by: Newby on November 03, 2005, 08:17:15 pm
Try installing it.
Title: Re: Perl MP3 Script for X-Chat
Post by: iago on November 03, 2005, 08:21:28 pm
Typically, cpan is used to install Perl modules.  Run cpan as root. 

<edit> Yup, cpan has it.

cpan> install Xmms::Remote
Running install for module Xmms::Remote
Running make for D/DO/DOUGM/Xmms-Perl-0.12.tar.gz
........

It aso looks after dependencies and stuff. 
Title: Re: Perl MP3 Script for X-Chat
Post by: Newby on November 03, 2005, 08:35:32 pm
perl -MCPAN -e 'install Xmms::Bundle'