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.
Activating web interface: Open VLC goto Tools--->Preferences-----> Main Interface
as shown below tick mark the web
option.
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
.
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
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 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) given length of the current item being played and get_title() to get the title number and get_state(self) 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