VLC Now Playing

By TheNitelyfe on Apr 28, 2010

Now playing script for the best media player out there. Obviously you gotta have the VLC media player to use this script. Usage: /vlc -l to echo or -m to message active window. To use this, first you must open VLC and go to View > Add Interface > Web Interface, and you might get a firewall pop up, just click allow. All set.

alias vlc { 
  if (!$istok(-l -m,$1,32)) { echo 2 -ta * /vlc insufficient paramaters: /vlc -l to echo, -m to message active | return }
  if (!$sock(vlc)) {
    sockopen vlc 127.0.0.1 8080
    sockmark vlc $iif($1 == -m,msg $active,echo -a)
  }
}
on *:sockopen:vlc:{
  sockwrite -nt vlc GET /requests/status.xml HTTP/1.1
  sockwrite -nt vlc Host: 127.0.0.1 $str($crlf,2)
}
on *:sockread:vlc:{
  if ($sockerr) { echo -a Error: $sock(vlc).wsmsg }
  var %v
  sockread %v
  if (<length>0</length> isin %v) { echo -a Error: Not playing any songs! | sockclose vlc }
  else {
    if ($regex(%v,/<(length)>([^>]+)<\/length>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='(artist|album|title|bitrate|type|sample rate)'>([^>]+)<\/info>/i)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) } }    
    if (</information> isin %v) { 
      $sock(vlc).mark [VLC] (Type:) %v.ty >> %v.ar - %v.ti < $+ %v.al $+ > (Length:) %v.le (Bit Rate:) %v.bi ( $+ %v.sa $+ ) 
      unset %v.*
      sockclose vlc
    }
  }
}
alias -l hf { return $remove($replace($1-,&quot;,",&apos;,',&amp;,&,&lt;,<,&gt;,>,&nbsp;,$chr(32),&#039;,'),<![CDATA[,]]>) }

Comments

Sign in to comment.
Devilin_Pixy   -  Mar 07, 2014

VLC updated quite some time ago and I am having a problem. VLC changed with a login to access the web interface. A window pops up and it needs a password to be able to use the web interface. There are actually two input fields, but the username should be left blank. I can't figure out how to log in using mIRC. I know how to log in to web pages, but this is a system popup. Any help on how to get my mIRC bot to access the web interface through this log in would be appreciated. Also requested help on the VLC forum in this topic: https://forum.videolan.org/viewtopic.php?f=16&t=116246

 Respond  
wickedradio   -  Mar 13, 2013

anyway to get this to display a video title? like how it shows int he vlc title bar? it works great for songs but when i play a video it displays a blank title to the channel.

illhawkthat  -  Mar 17, 2013

Check out this pastebin http://pastebin.com/GQpCiiTv - the elseif in the sockread catches the movie title. You can also look for and if you want more info. PM me on here for more help.

Sign in to comment

nettocash   -  Feb 15, 2013

I've been using aimp tools with winamp to display mp3s with mirc, but i'm on linux now, and vlc was already installed, and i'm too lazy to even see if winamp is supported by linux so I just googled for vlc mirc mp3 player. I ended up here, but the above code didn't work for me, so I had to do a little coding of my own to make it work, and this is what I came up with....

displays on irc like this when you type /vlc

(10:55a|2/15) * ~nettocash np: Franz Ferdinand - Take Me Out [181.FM - The Buzz (Your Alternative Station!)]
(11:04a|2/15) * ~nettocash np: Live - Lightning Crashes [181.FM - The Buzz (Your Alternative Station!)]
(11:05a|2/15) * ~nettocash np: Imagine Dragons - Radioactive [181.FM - The Buzz (Your Alternative Station!)]

what I put in mirc remote editor

alias vlc { 
  if (!$sock(vlc)) {
    sockopen vlc 127.0.0.1 8080
    sockmark vlc $iif($1 == echo,echo -a,describe $active)
  }
}
on *:sockopen:vlc:{
  sockwrite -nt vlc GET /requests/status.xml HTTP/1.1
  sockwrite -nt vlc Host: 127.0.0.1 $str($crlf,2)
}
on *:sockread:vlc:{
  if ($sockerr) { echo -a Error: $sock(vlc).wsmsg }
  window -hde @ $+ $sockName -1 -1 500 500
  var %v
  sockread %v
  aline -p @ $+ $sockName : $+ %v
  if (<state>stopped</state> isin %v || <state>paused</state> isin %v ) { echo -a Error: Not playing any songs! | sockclose vlc }
  else {
    if ($regex(%v,/<(length)>([^>]+)<\/length>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='title'>([^>]+)<\/info>/i)) { set %v.title $regml(1),2) }
    if ($regex(%v,/<info name='now_playing'>([^>]+)<\/info>/i)) { set %v.lc.np $regml(1),2)  }
    if (</root> isin %v) { 
      $sock(vlc).mark np: %v.lc.np $chr(91) $+ %v.title $+ $chr(93) 
      unset %v.*
      sockclose vlc
      window -c @vlc
    }
  }
}

alias -l hf { return $remove($replace($1-,&quot;,",&apos;,',&amp;,&,&lt;,<,&gt;,>,&nbsp;,$chr(32),&#39;,'),<![CDATA[,]]>) } 

I'm using VLC 2.0.4 TwoFlower, dont forget to add "web interface" like the original author stated in the first post. good luck

also, thanks to the two guys who coded most of this script!!! much appreciate it

 Respond  
iamselosa   -  Sep 09, 2012

comment deleted

 Respond  
Devilin_Pixy   -  Sep 09, 2012

@iamselosa You can use it to show title and duration. The code goes into the remote or create a new remote for it. Make sure to use the right tags for title and duration (v%.ti and %v.le). Depending on the streaming software you use you can make it show on stream. I use XSplit myself and you could output both fields to a text file and then use a remote title in XSplit to read this info for example. To just output it to IRC with the bot it's easy though. Use the right fields that show title and duration/length, then make your !now playing command show the %v.ti and %v.le. So you might want to change the code somewhat and add an 'on TEXT' for your '!now playing'. You do need to use the VLC webinterface as well of course.

@TheWhistler You can show any information a radio station provides. Use the debug window in the code to find what info is put between which tags and use those fields to message to IRC.

If either of you needs more info or help, then don't hestitate to reply or contact me.

 Respond  
TheWhistler   -  Sep 08, 2012

any way to get this to display a shoutcast radio to a channel with VLC , if so i sure would love to have it

 Respond  
iamselosa   -  Sep 07, 2012

comment deleted

 Respond  
iamselosa   -  Sep 07, 2012

comment deleted

 Respond  
JDHammer67   -  Aug 21, 2012

Thanks !!!

 Respond  
Devilin_Pixy   -  Aug 19, 2012

@Ragematix Ok, here is the full script as TheNitelyfe started it with the changes to make it work. This is not the actual script I use myself. I added a debug window to the script which will show the actual output from the status.xml in line 14 and 17. I use this script myself but made changes to display the fields I want it to show in a way I like and made quite a few more edits myself. I added the debug window to make it easier to understand the way this script works to allow your own edits and use other fields if you like. That would need editing this code of course.

alias vlc { 
  if (!$istok(-l -m,$1,32)) { echo 2 -ta * /vlc insufficient paramaters: /vlc -l to echo, -m to message active | return }
  if (!$sock(vlc)) {
    sockopen vlc 127.0.0.1 8080
    sockmark vlc $iif($1 == -m,msg $active,echo -a)
  }
}
on *:sockopen:vlc:{
  sockwrite -nt vlc GET /requests/status.xml HTTP/1.1
  sockwrite -nt vlc Host: 127.0.0.1 $str($crlf,2)
}
on *:sockread:vlc:{
  if ($sockerr) { echo -a Error: $sock(vlc).wsmsg }
  window -de @ $+ $sockName -1 -1 500 500
  var %v
  sockread %v
  aline -p @ $+ $sockName : $+ %v
  if (<state>stopped</state> isin %v || <state>paused</state> isin %v ) { echo -a Error: Not playing any songs! | sockclose vlc }
  else {
    if ($regex(%v,/<(length)>([^>]+)<\/length>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='(artist|album|title|bitrate|type|sample rate)'>([^>]+)<\/info>/i)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if (</root> isin %v) { 
      $sock(vlc).mark [VLC] (Type:) %v.ty >> %v.ar - %v.ti < $+ %v.al $+ > (Length:) %v.le (Bit Rate:) %v.bi ( $+ %v.sa $+ ) 
      unset %v.*
      sockclose vlc
    }
  }
}
alias -l hf { return $remove($replace($1-,&quot;,",&apos;,',&amp;,&,&lt;,<,&gt;,>,&nbsp;,$chr(32),&#39;,'),<![CDATA[,]]>) }

Any questions, just reply in this thread since I am still following this post.

 Respond  
Ragematix   -  Aug 18, 2012

Like paste the whole script with the new changes? thanks

 Respond  
Ragematix   -  Aug 18, 2012

Yea.. Could somebody paste the new code with the changes? I have almost 0 knowledge about this stuff.

 Respond  
Devilin_Pixy   -  Aug 05, 2012

@JDHammer67: I just changed the part of the code to get the original code by TheNiteLyfe working again. I use the code when streaming on Twitch TV or Justin TV, but I have edited my own code and integrated it into my chat bot, so there are quite a few changes in my code and I added some code as well to make it work for me. My bot only shows 'now playing' info in chat that I find useful. I do not use the bitrate, type or sample rate, but I use the artist, album, title and a few more fields I added to show 'now playing' correctly for me. Different sources use different tags for the media info. For example, a radio station would use text or text or text. Not sure what exactly isn't shown or handled right in your Videos, but you might want to check the fields/tags VLC outputs in the status.xml. Another change i made in the original code is that I am not letting the script look for the tag, but instead changed that to the tag. This way I am sure I get the full output as well, because there are more fields/tags used after that and the tag seemed to be buggy when I tested it. Speaking of radio stations, the original code echos an error saying there is no song playing when 0 is found in the output status.xml. Well, radiostations playing always show a length of 0 or -1 in some cases, so this doesn't mean nothing is playing. I changed that into checking for stopped or paused instead.

Anyways, I have been fiddling around with the code and changed it to work for me. You might want to add a debug window echoing the actual output to make things more clear. If you can be more specific about the issues you have, I might be able to help you out.

 Respond  
JDHammer67   -  Aug 05, 2012

I got a friend to look this over and post the code for me... but didnt realize I had it working..
It just doesnt handle Videos right

 Respond  
JDHammer67   -  Aug 05, 2012

Any way to post the whole working code in one snippet? I've tried reading this all over and cutting and pasting.. but cant get it to work.. sorry.. would love a working VLC mirc script.. thanks.. Peace

 Respond  
TheNitelyfe   -  Jul 24, 2012

wow its been a long time :o im gonna update it with jethro's fix (thank you buddy)

 Respond  
Jethro   -  Jul 24, 2012

Indeed you can shorten your regex using the pipe to separate each match:

if ($regex(%v,/<(length)>([^>]+)<\/length>/)) { 
   set %v. $+ $left($regml(1),2) $hf($regml(2)) 
    }
    if ($regex(%v,/<info name='(artist|album|title|bitrate|type|sample rate)'>([^>]+)<\/info>/i)) { 
    set %v. $+ $left($regml(1),2) $hf($regml(2)) 
    }
 Respond  
Devilin_Pixy   -  Jul 24, 2012

I am using VLC version 2.0.3 Twoflower and had the same problem. Reason the code does not work anymore is because there have been some changes in the status.xml file. I solved it by changing some of the code. Note that I am still learning how to use $regex() so I changed matching to single lines and not sure how to put it all into one. It does work however, although it might be done shorter.

Change,

  if (<length>0</length> isin %v) { echo -a Error: Not playing any songs! | sockclose vlc }
  else {
    if ($regex(%v,/<(length|title|artist|album)>(.+)<\/.+>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name="(Type|Sample rate|Bitrate)">(.+)<\/info>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if (</information> isin %v) { 
      $sock(vlc).mark [VLC] (Type:) %v.ty >> %v.ar - %v.ti < $+ %v.al $+ > (Length:) %v.le (Bit Rate:) %v.bi ( $+ %v.sa $+ ) 
      unset %v.*
      sockclose vlc
    }
  }
}
alias -l hf { return $remove($replace($1-,&quot;,",&apos;,',&amp;,&,&lt;,<,&gt;,>,&nbsp;,$chr(32),&#039;,'),<![CDATA[,]]>) }

to

  if (<length>0</length> isin %v) { echo -a Error: Not playing any songs! | sockclose vlc }
  else {
    if ($regex(%v,/<(length)>([^>]+)<\/length>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='(artist)'>([^>]+)<\/info>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='(album)'>([^>]+)<\/info>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='(title)'>([^>]+)<\/info>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='(Bitrate)'>([^>]+)<\/info>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='(Type)'>([^>]+)<\/info>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if ($regex(%v,/<info name='(Sample rate)'>([^>]+)<\/info>/)) { set %v. $+ $left($regml(1),2) $hf($regml(2)) }
    if (</information> isin %v) { 
      $sock(vlc).mark [VLC] (Type:) %v.ty >> %v.ar - %v.ti < $+ %v.al $+ > (Length:) %v.le (Bit Rate:) %v.bi ( $+ %v.sa $+ ) 
      unset %v.*
      sockclose vlc
    }
  }
}
alias -l hf { return $remove($replace($1-,&quot;,",&apos;,',&amp;,&,&lt;,<,&gt;,>,&nbsp;,$chr(32),&#39;,'),<![CDATA[,]]>) }

@TheNitelyfe: I hope you can use this to update your code ;-)

 Respond  
synthtech   -  May 14, 2012

i'm having that same problem

 Respond  
chachin   -  Apr 20, 2012

I guess its not working yet on vlc v1.1.11

[8:37:36pm] [VLC] (Type:) >> - <> (Length:) 3235 (Bit Rate:) ()
[8:37:39pm] D:

 Respond  
synthtech   -  Mar 24, 2012

does this code still work for the new version of VLC?

 Respond  
luism   -  Nov 13, 2011

this works great, thank you.

I was wondering if there was a way to add a timer to it, for instance

Now Playing: David Guetta - Getting Over You - 1:43/2:30mins

Thank you in advanced.

 Respond  
Raicho Ichisada   -  Sep 23, 2010

thx it works :D

 Respond  
michealkenny   -  Aug 04, 2010

thank you TheNitelyfe

 Respond  
TheNitelyfe   -  Aug 04, 2010

michealkenny if you're still wondering, change

$sock(vlc).mark [VLC] (Type:) %v.ty >> %v.ar - %v.ti < $+ %v.al $+ > (Length:) %v.le (Bit Rate:) %v.bi ( $+ %v.sa $+ )

to

$iif(Status Window = $active,echo -ts,describe $v2) is now playing: %v.ar - %v.ti
 Respond  
Jethro   -  Jul 24, 2010

Actually TheNitelyfe, it won't be as messy as you think. By regrouping the match strings in the same regex statement, you can use $regml(2) to refer to the second group of regex match to do its routine. But I understand you want 'em to be kept simple and clean.

 Respond  
michealkenny   -  Jul 24, 2010

is there anyway to just give the song name and nothing else

from:
[VLC] (Type:) Audio >> AnCafe - Smile Ichiban Ii Onna (Length:) 252 (Bit Rate:) 192 kb/s (44100 Hz)

to:
/me Is Playing: AnCafe - Smile Ichiban Ii Onna

thank you in advance.

 Respond  
TheNitelyfe   -  Jul 10, 2010

i could do that but it would be horridly messy

 Respond  
WorldDMT   -  Jul 10, 2010

@jethro_: TheNitelyfe does it 2 now he can regroup it in one too no? :D

 Respond  
TheNitelyfe   -  Jul 09, 2010

Yeah fixed

And @SoxFarxAway777
i dunno what to tell you man sorry this just sockreads a web interface xml file

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.