This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
mpc.hc.np.pl
51 lines (43 loc) · 1.9 KB
/
mpc.hc.np.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
#/**
#* mpc.hc.np.pl, snippet to display now-playing info for MPC-HC
#* Released under the terms of MIT license
#*
#* https://github.com/mpc-hc/snippets
#*
#* Copyright (C) 2012-2013 MPC-HC Team
#*/
use strict;
use warnings;
use Xchat qw( :all );
use LWP::UserAgent;
#############################################################################
my $version = "0.4";
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", sub {
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 it's wrong
if (!$response->is_success) {
Xchat::command("echo - Could not get: $url. Open MPC-HC -> Options -> Player -> Web Interface -> Listen on port");
}
else { # Report back if it's right
# Get results into variable
my $mpchcnp = $response->decoded_content;
$mpchcnp =~ s{.+<p id="mpchc_np">(.+?)</p>.+}{$1}s; # Extract np text from the html
# Remove whitespace at beginning and end of string and replace entities
$mpchcnp =~ s/^\s+|\s+$//g;
$mpchcnp =~ s/«/\xab/g;
# Couldn't find proper way to replace it so I'm using plain hyphen as separator ;x
$mpchcnp =~ s/•/\x2D/g;
$mpchcnp =~ s/»/\xbb/g;
Xchat::command("say $mpchcnp");
}
return Xchat::EAT_ALL;
});
#############################################################################