Author Topic: Perl MP3 Script for X-Chat  (Read 4180 times)

0 Members and 1 Guest are viewing this topic.

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Perl MP3 Script for X-Chat
« 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

#!/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]
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Perl MP3 Script for X-Chat
« Reply #1 on: October 30, 2005, 01:20:27 am »
Leetness man.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Perl MP3 Script for X-Chat
« Reply #2 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.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: Perl MP3 Script for X-Chat
« Reply #3 on: November 03, 2005, 08:17:15 pm »
Try installing it.
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT. 

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: Perl MP3 Script for X-Chat
« Reply #4 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. 
« Last Edit: November 03, 2005, 08:26:17 pm by iago »

Offline Newby

  • Moderator
  • Hero Member
  • *****
  • Posts: 10877
  • Thrash!
    • View Profile
Re: Perl MP3 Script for X-Chat
« Reply #5 on: November 03, 2005, 08:35:32 pm »
perl -MCPAN -e 'install Xmms::Bundle'
- Newby
http://www.x86labs.org

Quote
[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

I'd bet that you're currently bloated like a water ballon on a hot summer's day.

That analogy doesn't even make sense.  Why would a water balloon be especially bloated on a hot summer's day? For your sake, I hope there wasn't too much logic testing on your LSAT.