Commit 996aad90 authored by Michael Mayr's avatar Michael Mayr

Code Cleanup

parent b63c9337
...@@ -17,10 +17,14 @@ it when starting VLC:: ...@@ -17,10 +17,14 @@ it when starting VLC::
$ vlc --intf telnet $ vlc --intf telnet
or with network access:
$ vlc --intf telnet --lua-config "telnet={host='0.0.0.0:4212'}"
or via the menus (depending on your platform, mostly View -> or via the menus (depending on your platform, mostly View ->
Add Interface -> Telnet). Add Interface -> Telnet).
For example:: Example usage::
>>> from vlcclient import VLCClient >>> from vlcclient import VLCClient
>>> vlc = VLCClient("::1") >>> vlc = VLCClient("::1")
......
...@@ -3,16 +3,18 @@ ...@@ -3,16 +3,18 @@
VLCClient VLCClient
~~~~~~~~~ ~~~~~~~~~
This module allows to control a VLC instance to be controlled This module allows to control a VLC instance through a python interface.
via telnet. You need to enable the telnet interface, e.g. start
You need to enable the telnet interface, e.g. start
VLC like this: VLC like this:
$ vlc --intf telnet $ vlc --intf telnet
To start VLC with allowed remote admin: To start VLC with allowed remote admin:
$ vlc --intf telnet --lua-config "telnet={host='0.0.0.0:4212'}" $ vlc --intf telnet --lua-config "telnet={host='0.0.0.0:4212'}"
Replace --intf with --extraintf to start telnet and the regular GUI
More information about the telnet interface: More information about the telnet interface:
http://wiki.videolan.org/Documentation:Streaming_HowTo/VLM http://wiki.videolan.org/Documentation:Streaming_HowTo/VLM
...@@ -71,7 +73,7 @@ class VLCClient(object): ...@@ -71,7 +73,7 @@ class VLCClient(object):
self.telnet.close() self.telnet.close()
self.telnet = None self.telnet = None
def send_command(self, line): def _send_command(self, line):
"""Sends a command to VLC and returns the text reply. """Sends a command to VLC and returns the text reply.
This command may block.""" This command may block."""
self.telnet.write(line + "\n") self.telnet.write(line + "\n")
...@@ -90,16 +92,16 @@ class VLCClient(object): ...@@ -90,16 +92,16 @@ class VLCClient(object):
# #
def help(self): def help(self):
"""Returns the full command reference""" """Returns the full command reference"""
return self.send_command("help") return self._send_command("help")
def status(self): def status(self):
"""current playlist status""" """current playlist status"""
self._require_version("status", "2.0.0") self._require_version("status", "2.0.0")
return self.send_command("status") return self._send_command("status")
def info(self): def info(self):
"""information about the current stream""" """information about the current stream"""
return self.send_command("info") return self._send_command("info")
# #
# Playlist # Playlist
...@@ -107,43 +109,43 @@ class VLCClient(object): ...@@ -107,43 +109,43 @@ class VLCClient(object):
def add(self, filename): def add(self, filename):
"""Add a file to the playlist and play it. """Add a file to the playlist and play it.
This command always succeeds.""" This command always succeeds."""
return self.send_command("add {0}".format(filename)) return self._send_command("add {0}".format(filename))
def enqueue(self, filename): def enqueue(self, filename):
"""Add a file to the playlist. This command always succeeds.""" """Add a file to the playlist. This command always succeeds."""
return self.send_command("enqueue {0}".format(filename)) return self._send_command("enqueue {0}".format(filename))
def seek(self, second): def seek(self, second):
"""Jump to a position at the current stream if supported.""" """Jump to a position at the current stream if supported."""
return self.send_command("seek {0}".format(second)) return self._send_command("seek {0}".format(second))
def play(self): def play(self):
"""Start/Continue the current stream""" """Start/Continue the current stream"""
return self.send_command("play") return self._send_command("play")
def pause(self): def pause(self):
"""Pause playing""" """Pause playing"""
return self.send_command("pause") return self._send_command("pause")
def stop(self): def stop(self):
"""Stop stream""" """Stop stream"""
return self.send_command("stop") return self._send_command("stop")
def rewind(self): def rewind(self):
"""Rewind stream""" """Rewind stream"""
return self.send_command("rewind") return self._send_command("rewind")
def next(self): def next(self):
"""Play next item in playlist""" """Play next item in playlist"""
return self.send_command("next") return self._send_command("next")
def prev(self): def prev(self):
"""Play previous item in playlist""" """Play previous item in playlist"""
return self.send_command("prev") return self._send_command("prev")
def clear(self): def clear(self):
"""Clear all items in playlist""" """Clear all items in playlist"""
return self.send_command("clear") return self._send_command("clear")
# #
# Volume # Volume
...@@ -151,17 +153,17 @@ class VLCClient(object): ...@@ -151,17 +153,17 @@ class VLCClient(object):
def volume(self, vol=None): def volume(self, vol=None):
"""Get the current volume or set it""" """Get the current volume or set it"""
if vol: if vol:
return self.send_command("volume {0}".format(vol)) return self._send_command("volume {0}".format(vol))
else: else:
return self.send_command("volume").strip() return self._send_command("volume").strip()
def volup(self, steps=1): def volup(self, steps=1):
"""Increase the volume""" """Increase the volume"""
return self.send_command("volup {0}".format(steps)) return self._send_command("volup {0}".format(steps))
def voldown(self, steps=1): def voldown(self, steps=1):
"""Decrease the volume""" """Decrease the volume"""
return self.send_command("voldown {0}".format(steps)) return self._send_command("voldown {0}".format(steps))
class WrongPasswordError(Exception): class WrongPasswordError(Exception):
pass pass
...@@ -196,5 +198,6 @@ def main(): ...@@ -196,5 +198,6 @@ def main():
print command() print command()
except OldServerVersion as e: except OldServerVersion as e:
print "Error:", e print "Error:", e
if __name__ == '__main__': if __name__ == '__main__':
main() main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment