Changes between Version 22 and Version 23 of WebUI


Ignore:
Timestamp:
2014-07-20T17:29:13+02:00 (5 years ago)
Author:
xhmikosr
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WebUI

    v22 v23  
    1010
    1111
    12 Feel free to submit any changes you think that should be made on [https://github.com/mpc-hc/snippets GitHub].
    13 
    14 
    15 {{{
    16 ;/**
    17 ;* mpc.hc.np.mrc, snippet to display now-playing info for MPC-HC
    18 ;* Released under the terms of MIT license
    19 ;*
    20 ;* https://github.com/mpc-hc/snippets
    21 ;*
    22 ;* Copyright (C) 2012-2013 MPC-HC Team
    23 ;*/
    24 
    25 ;In order to use it you need to enable web interface in options first
    26 ;Type /np to show info in active channel
    27 
    28 alias nohtml {
    29   var %nohtml = $regsubex($regsubex($1,/<.+?>/g,),/&#(\d+);/g,$fixentities(\t))
    30   %nohtml = $replacecs(%nohtml,&laquo;,«,&raquo;,»,&bull;,•)
    31   return %nohtml
    32 }
    33 
    34 alias np {
    35   var %mpchc.host 127.0.0.1
    36   var %mpchc.port 13579
    37   .sockclose mpchc.np
    38   .sockopen mpchc.np %mpchc.host %mpchc.port
    39   .sockmark mpchc.np $active
    40 }
    41 
    42 on *:sockopen:mpchc.np:{
    43   sockwrite $sockname GET /info.html HTTP/1.1 $+ $crlf Host: $sock($sockname).ip $crlf $+ $crlf
    44 }
    45 
    46 on *:sockread:mpchc.np:{
    47   var %temptext
    48   sockread %temptext
    49   if (*<p id="mpchc_np">* iswm %temptext) {
    50     %temptext = $regsubex(%temptext, /^\s+/, $null)
    51     msg $sock($sockname).mark $nohtml(%temptext)
    52   }
    53 }
    54 
    55 }}}
    56 
    57 Or if you don't like mIRC get this snippet for X-Chat / !HexChat written in Perl.
    58 The place for suggestions or fixes is again on [https://github.com/mpc-hc/snippets GitHub].
    59 
    60 
    61 {{{
    62 #!perl
    63 #!/usr/bin/perl
    64 
    65 #/**
    66 #* mpc.hc.np.pl, snippet to display now-playing info for MPC-HC
    67 #* Released under the terms of MIT license
    68 #*
    69 #* https://github.com/mpc-hc/snippets
    70 #*
    71 #* Copyright (C) 2012-2013 MPC-HC Team
    72 #*/
    73 
    74 use strict;
    75 use warnings;
    76 use Xchat qw( :all );
    77 use LWP::UserAgent;
    78 
    79 #############################################################################
    80 
    81 my $version = "0.4";
    82 Xchat::register("MPC-HC API", $version, "Displays MPC-HC Player Info!", "");
    83 Xchat::print("Loaded - MPC-HC API - Use: /np :: Setup: Open MPC-HC -> Options -> Player -> Web Interface -> Listen on port");
    84 
    85 #############################################################################
    86 
    87 Xchat::hook_command("np", sub {
    88     my $browser = LWP::UserAgent->new;                  # Create a session
    89     my $url     = "http://localhost:13579/info.html";   # HTML file here
    90     $browser->timeout(3);                               # How long to wait
    91     $browser->env_proxy;                                # Proxy mode
    92     my $response = $browser->get($url);                 # Get info
    93 
    94     # Report back if it's wrong
    95     if (!$response->is_success) {
    96         Xchat::command("echo - Could not get: $url. Open MPC-HC -> Options -> Player -> Web Interface -> Listen on port");
    97     }
    98     else {  # Report back if it's right
    99         # Get results into variable
    100         my $content = $response->content;
    101         my @temptext = split("\n", $content);
    102         my $mpchcnp = $temptext[9];
    103         # Remove html, remove whitespace at beginning and end of string and replace entities
    104         $mpchcnp =~ s/<[^>]*>//g;
    105         $mpchcnp =~ s/^\s+|\s+$//g;
    106         $mpchcnp =~ s/&laquo;/\xab/g;
    107         # Couldn't find proper way to replace it so I'm using plain hyphen as separator ;x
    108         $mpchcnp =~ s/&bull;/\x2D/g;
    109         $mpchcnp =~ s/&raquo;/\xbb/g;
    110         Xchat::command("say $mpchcnp");
    111     }
    112     return Xchat::EAT_ALL;
    113 });
    114 
    115 #############################################################################
    116 
    117 }}}
    118 
    119 In case you like Python flavor more then Perl then we have something for you as well.
    120 The place for suggestions or fixes is again on [https://github.com/mpc-hc/snippets GitHub].
    121 
    122 
    123 {{{
    124 #!python
    125 # -*- coding: utf-8 -*-
    126 
    127 #/**
    128 #* mpc.hc.np.py, snippet to display now-playing info for MPC-HC
    129 #* Released under the terms of MIT license
    130 #*
    131 #* https://github.com/mpc-hc/snippets
    132 #*
    133 #* Copyright (C) 2013 MPC-HC Team
    134 #*/
    135 
    136 
    137 __module_name__ = "MPC-HC NP snippet"
    138 __module_version__ = "0.2"
    139 __module_description__ = "Displays MPC-HC Player Info!"
    140 
    141 import xchat
    142 import urllib2
    143 import re
    144 
    145 ###############################################################################
    146 # Setup
    147 
    148 MPC_HC_PORT = "13579"      # Default port
    149 MPC_HC_PAGE = "info.html"  # Page where "now playing" info is displayed
    150 
    151 ###############################################################################
    152 
    153 MPC_HC_URL = "http://{0}:{1}/{2}".format("localhost", MPC_HC_PORT, MPC_HC_PAGE)
    154 
    155 MPC_HC_REGEXP = re.compile(r"\<p\ id\=\"mpchc_np\"\>(.*)\<\/p\>")
    156 
    157 
    158 def mpc_hc(caller, callee, helper):
    159     data = urllib2.urlopen(MPC_HC_URL).read()
    160     mpc_hc_np = MPC_HC_REGEXP.findall(data)[0].replace("&laquo;", "«")
    161     mpc_hc_np = mpc_hc_np.replace("&raquo;", "»")
    162     mpc_hc_np = mpc_hc_np.replace("&bull;", "•")
    163     xchat.command("say %s" % mpc_hc_np)
    164     return xchat.EAT_ALL
    165 
    166 xchat.hook_command(
    167     "np",
    168     mpc_hc,
    169     help="Use: /np :: Setup: Options -> Player -> Web Interface -> Listen on port"
    170 )
    171 
    172 }}}
     12Source code for the snippets is on [https://github.com/mpc-hc/snippets GitHub]. Feel free to submit pull requests there :)