Author Topic: Control VLC Player using telnet and python  (Read 6136 times)

id3oM0T0R

  • Guest
Control VLC Player using telnet and python
« on: March 11, 2017, 07:17:56 AM »
Hello everyone.

You want to play music from your harddrive using voice commands, without needing to tab out of the game? Additionally you want to skip tracks, change the volume, or clear the playlist? Here is a way to do exactly this.

I am sharing a somewhat simple solution for controlling VLC audio using a telnet interface with voice attack. This whole thing is completely based on a youtube video I found after a few minutes of searching. So all credit goes to "Capn_Flint", who is providing a very comprehensive walkthrough. The video is called "Advanced VoiceAttack Tutorial incl. VLC Music Controls for Star Citizen & Elite Dangerous!!!" by Capn_Flint.

Both the video and the solution are 2 years old and unfortunately the used scripts were not working anymore on my system (Win 10, Python 3.6 and Voice Attack 1.6.1). So I came up with a little revision I want to share with you. Basically you proceed exactly how in Capn_Flints example. You only need to change the points down below.

Here we go:
1. Telnet is disabled by default in Windows 10. So enable it first.
2. start VLC with the parameters added by Steve. Might still work with the default solution, I did not try. But better be thorough and give telnet every detail you need.
3. I used the parameter "clear" to create the "stop music; clear playlist" command. By this I do not need to kill the vlc process and avoid any tabbing issues.
4. Python 3.6 throws type errors with the old python script. So you have to convert the to be read strings into a byte type (simply put a "b" in front of the string). The input strings however need to be clearly defined as string. I paste the new working script down below.
5. Set the window style to "hidden" instead of "minimized". My system would tab out of E:D otherwise.
Note: Telnet will not accept folder inputs sometimes (for the add to playlist command). As far as I know this depends on the location your python script is located in and / or  the number of subfolders you are using. I put my script in the same folder I copy the music in. The music itself is put directly into subfolders. I am only using these two levels. It should work fine for you, if you follow this as well. If not it can happen, that your files are not added to the playlist.

Revised Python script
Quote
#!/usr/bin/python
import sys
import telnetlib

HOST = "localhost"
password = "admin"
port = "4212"

cmd = " ".join(sys.argv[1:])
tn = telnetlib.Telnet(HOST, port)
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') +b"\n")
tn.read_until(b"> ")
tn.write(cmd.encode('ascii') + b"\n")
tn.close()

Enjoy!