How to monitor VLC media player on Windows 7 using Python?
Question: I want to know what's currently playing on [VLC media
player](http://en.wikipedia.org/wiki/VLC_media_player) (Windows 7) using
Python 2.7. Just knowing the details of the track/video is sufficient.

**Research:** I came to know that VLC media player has [python-
bindings](https://wiki.videolan.org/Python_bindings). I also found out a way
to play some track using a
[Python](http://en.wikipedia.org/wiki/Python_%28programming_language%29)
script. But I couldn't find a suitable way to check what's being played on VLC
media player.

**Clarification:** I have the script running. I play a audio track on my VLC
media player manually on my machine, and I want that script to detect and show
the details of the track present for the file playing.


Answer: As per my understanding of your question:

> I have the script running. I play a audio track on my VLC manually on my
> machine and I want that script to detect and show the details of the track
> present for the file playing.

There could be two possibilities to retrieve the information of the current
item being played in the VLC player.

**First method** : Tested on Windows 7 OS and VLC v2.1.3

You have to first setup the web interface in the VLC player and then activate
it. Then you can access all the information of currently playing track from a
XML file by visiting this link `http://localhost:8080/requests/status.xml`.
You can create a simple script in python that will visit the link above and
fetch the information.

**Dummy code** : This code will simply display the complete information of the
file currently being played in the VLC player, you can try to extract what you
need:

    
    
    import requests
    def getInfo():
        s = requests.Session()
        s.auth = ('', 'password')# Username is blank, just provide the password
        r = s.get('http://localhost:8080/requests/status.xml', verify=False)
        print r.text
    
    getInfo()
    

You cab get Requests lib [here](http://docs.python-requests.org/en/latest/).

**Activating web interface** : Open VLC goto `Tools--->Preferences-----> Main
Interface` as shown below tick mark the `web` option.
![player1](http://i.stack.imgur.com/wo3It.png)

Then click on `Lua` option on the left pane. Enter the password in the
`password` field and enter `C:\Program Files\VideoLAN\VLC\lua\http` in the
`source directory` field as shown below. Verify that you have status.xml file
at the location that you provided in the `source directory`. ![player
2](http://i.stack.imgur.com/EFTo4.png)

**Testing** : Start the VLC player and play some file. Visit
`http://localhost:8080/requests/status.xml` and you shall see a login page,
leave the username field blank and enter the password that you entered in the
VLC. If you logged in successfully you shall see the XML file!

If you don't see any thing then do the following as shown in the image below:
goto `View--->Add Interface----->Select web`
![player3](http://i.stack.imgur.com/qGaPg.png)

If everything works fine now run the script that I provided above. You shall
see the information of the file in the console, now you can modify the script
to get only the information that you desire. _PS: The username field is blank,
just enter your password in the script._

**Second method** : (_I think this is not what you desired!_) This case is
when you'll play the file using python binding itself.
[Here](http://liris.cnrs.fr/advene/download/python-ctypes/doc/vlc.MediaPlayer-
class.html) you can find many different methods that can be used to get the
information of the current playing item in the VLC.

For an instance:
[get_length(self)](http://liris.cnrs.fr/advene/download/python-
ctypes/doc/vlc.MediaPlayer-class.html#get_length) given length of the current
item being played and
[get_title()](http://liris.cnrs.fr/advene/download/python-
ctypes/doc/vlc.MediaPlayer-class.html#get_title) to get the title number and
[get_state(self)](http://liris.cnrs.fr/advene/download/python-
ctypes/doc/vlc.MediaPlayer-class.html#get_state) to know if the player is
playing something or is it paused/stopped. `get_mrl()` gives the location of
the track and also contains the track name at last, so you can figure out how
to get track name from the location string using python.

**Dummy code** :

    
    
    import vlc
    
    def setup_player(filename):
        vlc_instance = vlc.Instance()
        media = vlc_instance.media_new(filename)
        player = vlc_instance.media_player_new()
        player.set_media(media)
        print media.get_mrl()# File location to get title ;)
        print player.get_length()#Time duration of file
        print player.get_state()#Player's state
    
    setup_player(filename)#Put file name/location here
    

