• Welcome to Valhalla Legends Archive.
 

[PERL] XMMS Current MP3

Started by Joe[x86], November 04, 2005, 07:44 PM

Previous topic - Next topic

Joe[x86]

A few things
1) This is my very first time ever using perl. When run in a terminal, it will output an error (about the way I call main()). If someone would like to fix this (or provide a link to information about this problem), it'd be apreciated. When run with JavaOp's /run command (which is why I made this), it doesn't output the error. Hm.
2) This will either output "XMMS Not Running" or the current MP3 using echo. In JavaOp, this is outputted to the chat window (in blue, ooh).
3) This is much easier to use if you move it to /usr/bin, asuming you have root access.
4) This code was written by Newby as an X-Chat perl script for the exact same purpose. All I did was basically stab it repetedly until it printed to the screen (it was rather easy too).

Without further ado, I present to you..
#!/usr/bin/perl -w

# http://www.x86labs.org/
# http://www.javaop.com/~joe/
# Special thanks to Newby[x86]!

use Xmms::Remote ();
my $xmms = Xmms::Remote->new;

main();

sub main() {
  if (! $xmms->is_running) {
    system("echo 'XMMS Not Loaded'");
  }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 = "Current MP3:";
    my $message = "$prefix $song2 [$songpos of $songlen] [".($songinfo[0]/1000)."kbps]";
    system("echo $message");
  }
}

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);
}
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Kp

No need to use echo, just print it directly.  I can't debug your other problem though, since I don't have XMMS integration in Perl.

--- a/joe.pl 1970-01-01 00:00:00.000000000 -0000
+++ b/joe.pl 1970-01-01 00:00:00.000000000 -0000
@@ -11,7 +11,7 @@

sub main() {
   if (! $xmms->is_running) {
-    system("echo 'XMMS Not Loaded'");
+    print "XMMS Not Loaded\n";
   }else{
     my $song = (($xmms->get_playlist_pos()) + 1);
     my $song2 = $xmms->get_playlist_title();
@@ -20,7 +20,7 @@
     my @songinfo = $xmms->get_info();
     my $prefix = "Current MP3:";
     my $message = "$prefix $song2 [$songpos of $songlen] [".($songinfo[0]/1000)."kbps]";
-    system("echo $message");
+ print "$message\n";
   }
}
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Joe[x86]

The other thing is a perl problem, not an XMMS problem.

This post and the one below it should have XMMS Remote up and running in less than 5 minutes, if you want it.

Also, thanks. =)
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Newby

#3
I see. People respond to his, but when it comes down to my original post and coding, it goes ignored.

At this point, why do you even bother having the $prefix variable if you aren't going to use my prefix-retrieval sub?

Also, the $song variable goes un-used. You really didn't do a very good job of slicing up my source, did you?
- Newby

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

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Joe[x86]

Quote<TehUser> Shut up, newby, you're here too often to know anything about women.

<3.

Anyhow, it works for my cause, so eh? And I used prefix because I'm too lazy to not do it (even though its obviously far too easy for even me to not know how).
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.