[request] media player classic announcer

Discussion about Perl, TCL or Python scripts and C/C++ plugins (using and writing them).

[request] media play

Postby dexelio » 18 Apr 2010 15:43

I've been looking for a MPC announcer, perl script preferred but either way is fine, anybody?
dexelio
 
Posts: 2
Joined: 18 Apr 2010 15:39

Here's a python code

Postby dexelio » 18 Apr 2010 15:57

# -*- coding: utf-8 -*-
import sys, os, codecs

# HACK: Set default encoding to UTF-8
if (sys.getdefaultencoding() != "utf-8"):
oldout, olderr = sys.stdout, sys.stderr # Backup stdout and stderr
reload(sys) # This call resets stdout and stderr
sys.setdefaultencoding('utf-8') # Change encoding
sys.stdout = codecs.getwriter('utf-8')(oldout) # Set old stdout
sys.stderr = codecs.getwriter('utf-8')(olderr) # Set old stderr

import xchat
#Add plugin directory to module search path for next import
if xchat.get_info("xchatdir") not in sys.path: sys.path.append(xchat.get_info("xchatdir"))

import _mpcinfo

__module_name__ = "MPCInfo"
__module_version__ = "1.3.1"
__module_description__ = "Displays information about Media Player Classic status."

def mpc(word, word_eol, userdata):

try:
filename, size, position = _mpcinfo.filename(), _mpcinfo.size(), _mpcinfo.position()

# Clean filename, convert file byte size to megabytes, format position
filename = os.path.split(filename)[1].replace("_", " ")
size = "%.2f mb" % (size / 1024.0 / 1024.0,)

pos = position[0].strftime("%H:%M:%S") if position[0].hour > 0 else position[0].strftime("%M:%S")
dur = position[1].strftime("%H:%M:%S") if position[1].hour > 0 else position[1].strftime("%M:%S")
min_or_hour = "h" if position[1].hour > 0 else "min"

# Determine player state
if _mpcinfo.paused():
state = " (paused)"
elif _mpcinfo.stopped():
state = " (stopped)"
else:
state = ""

vars = {"filename" : filename, "size" : size, "state" : state, "position": "%s/%s %s" % (pos, dur, min_or_hour),
"B" : "\002", "U" : "\037", "O" : "\017" }

# Output string
string = "%(B)sMPC%(O)s: %(filename)s %(U)s:%(O)s [%(position)s%(state)s] %(U)s:%(O)s Size: %(size)s" % vars

#if string.encode("latin_1", "replace") != string:
# print "Notice:\tNon-ASCII-characters were replaced during string formating"

xchat.command(u"SAY %s" % string)
except RuntimeError:
print "Error:\tMedia Player Classic is not running."

return xchat.EAT_ALL

xchat.hook_command("MPC", mpc,
help="/MPC Sends information about MPC to the current channel")
xchat.hook_command("MPCINFO", mpc,
help="/MPCINFO Sends information about MPC to the current channel")
print __module_name__, __module_version__, "loaded."
dexelio
 
Posts: 2
Joined: 18 Apr 2010 15:39

Postby nob0dy » 18 Apr 2010 17:26

nob0dy
 
Posts: 193
Joined: 06 Nov 2005 14:29

Re: [request] media player classic announcer

Postby nob0dy » 14 Apr 2011 19:37

sadly this one no longer works

source/_mpcinfo.cpp
_mpcinfo.pyd
mpcinfo.py
readme.1st.txt

http://ircsvet.com/index.php?option=com ... 20&cid=172
nob0dy
 
Posts: 193
Joined: 06 Nov 2005 14:29

Re: [request] media player classic announcer

Postby nob0dy » 14 Jul 2012 11:48

All you have to do is to enable web interface in options first and type /np on irc.


http://sourceforge.net/apps/trac/mpc-hc/wiki/WebUI

Code: Select all
############ MPC-HC 0.3 - © 2012, vBm <vbm@omertabeyond.com> ###################
#!/usr/bin/perl

use strict;
use warnings;
use Xchat qw( :all );
use LWP::UserAgent;

#############################################################################

my $version = "0.3";
Xchat::register("MPC-HC API", $version, "Displays MPC-HC Player Info!","");
Xchat::print('Loaded - MPC-HC API - Use: /np :: Setup: Open MPC-HC > Options -> Player -> Web interface -> listen on port');

#############################################################################

Xchat::hook_command("np", "mpchc");

#############################################################################

sub mpchc {
   my $browser      = LWP::UserAgent->new;         # Create A session!
   my $url         = 'http://localhost:13579/info.html';   # HTML File Here!
   $browser->timeout(3);                  # How Long to Wait!
   $browser->env_proxy;                  # Proxy Mode!
   my $response = $browser->get($url);            # Get Info!

   #Report Back if its Wrong!
   if ( !$response->is_success ) {
      Xchat::command("echo - Could Not Get: $url . Open MPC-HC > Options -> Player -> Web interface -> listen on port");
   }

   #Report Back if its Right!
   else {
      # Get Results into Variable!
      my $content = $response->content;
      my @temptext = split("\n", $content);
      my $mpchcnp = $temptext[7];
      # Remove html, remove whitespace at beginning and end of string and replace entities.
      $mpchcnp =~ s/<[^>]*>//g;
      $mpchcnp =~ s/^\s+|\s+$//g;
      $mpchcnp =~ s/&laquo;/\xab/g;
      # Couldn't find proper way to replace it so i'm using plain hypen as separator ;x
      $mpchcnp =~ s/&bull;/\x2D/g;
      $mpchcnp =~ s/&raquo;/\xbb/g;
      Xchat::command("say $mpchcnp");
   }
   return Xchat::EAT_ALL;
}
#############################################################################


Any idea how to modify the output?
nob0dy
 
Posts: 193
Joined: 06 Nov 2005 14:29


Return to Scripts and Plugins

Who is online

Users browsing this forum: No registered users and 4 guests