Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env perl -w
- use strict;
- use vars qw($VERSION %IRSSI);
- use Irssi;
- $VERSION = '0.1';
- %IRSSI = (
- authors => 'rebirth',
- name => 'VLC Now Playing Script',
- description => 'Scrape basic information from VLC web interface',
- license => 'GPLv3',
- changed => 'Fri May 06 20:58 EST 2016'
- );
- sub get_data {
- # you will need to enable web interface of VLC first, and set a password
- my $url = "http://localhost:8080/requests/status.xml";
- my $pw = ""; #!# YOU MUST ENTER YOUR PASSWORD HERE OR THE SCRIPT WON'T WORK #!#
- return(`wget -qO- $url --user= --password=$pw`);
- }
- sub scrape {
- my ($tag, @data) = @_;
- my $match;
- foreach my $line (@data) {
- $line =~ s/&/&/g;
- $line =~ s/'/'/g;
- if (!$match) {
- if ($line =~ /<info name='$tag'>(.*?)<\/info>/) {
- $match = $1;
- }
- }
- }
- return($match);
- }
- sub convert_seconds {
- my $time = $_[0];
- my $hours = $time / 60 / 60;
- my $minutes = $time / 60 % 60;
- my $seconds = $time % 60;
- if ($hours >= 1) {
- return(sprintf("%d:%02d:%02d", $hours, $minutes, $seconds));
- }
- else {
- return(sprintf("%02d:%02d", $minutes, $seconds));
- }
- }
- sub get_tag {
- my ($tag, @data) = @_;
- my $match;
- foreach my $line (@data) {
- if (!$match) {
- if ($line =~ /<$tag>(.*?)<\/$tag>/) {
- $match = $1;
- }
- }
- }
- return ($match);
- }
- sub main {
- my @data = get_data;
- my $vlc = "\0037[\003VLC\0037]\003";
- my $position = convert_seconds(get_tag('time', @data));
- my $length = convert_seconds(get_tag('length', @data));
- my $resolution = scrape('Resolution', @data);
- my $output;
- if (!$resolution) {
- my $artist = scrape('artist', @data);
- my $album = scrape('album', @data);
- my $title = scrape('title', @data);
- my $year = scrape('date', @data);
- my $bitrate = scrape('Bitrate', @data);
- if (!$bitrate) {
- $bitrate = "[Lossless]";
- }
- else {
- $bitrate = "@ " . $bitrate;
- }
- $output = sprintf("%s %s by %s from %s (%s) %s | %s/%s\n", $vlc,
- $title, $artist,
- $album, $year,
- $bitrate, $position,
- $length);
- }
- else {
- my $filename = scrape('filename', @data);
- $output = sprintf("%s %s | %s | %s/%s\n", $vlc, $filename, $resolution,
- $position, $length);
- }
- Irssi::active_win->command("say $output");
- }
- Irssi::command_bind('np', 'main');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement