Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
py-vlcclient
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
py-vlcclient
Commits
63f869c6
Commit
63f869c6
authored
May 27, 2012
by
Michael Mayr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First version
parent
be8f50fa
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
278 additions
and
4 deletions
+278
-4
COPYING
COPYING
+24
-0
README.md
README.md
+0
-4
Readme.rst
Readme.rst
+69
-0
setup.py
setup.py
+21
-0
vlcclient.py
vlcclient.py
+164
-0
No files found.
COPYING
0 → 100644
View file @
63f869c6
Copyright (c) 2012 Michael Mayr <michael@michfrm.net>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
README.md
deleted
100644 → 0
View file @
be8f50fa
py-vlcclient
============
A VLC client written in python
\ No newline at end of file
Readme.rst
0 → 100644
View file @
63f869c6
py-vlcclient
============
This module allows to control a VLC instance using Python. This
module uses the telnet interface of VLC and has no external dependencies.
More information about the telnet interface:
http://wiki.videolan.org/Documentation:Streaming_HowTo/VLM
The clients supports some basic commands to modify playlists and control the playback.
How to Use
==========
First start VLC and enable the telnet interface. You can either enable
it when starting VLC::
$ vlc --intf telnet
or via the menus (depending on your platform, mostly View ->
Add Interface -> Telnet).
For example::
>>> from vlcclient import VLCClient
>>> vlc = VLCClient("::1")
>>> vlc.connect()
>>>
>>> r.add("/home/mitch/Music/a_song.ogg")
>>> r.volume(300)
>>> r.rewind()
>>> r.status()
'( new input: file:///.... )
( audio volume: 200 )
( state playing )'
Implemented Commands
====================
The following commands are currently implemented:
generic
-------
* help
* status
* info
playlists and controls
----------------------
* add
* enqueue
* seek
* play
* pause
* stop
* rewind
* next
* prev
* clear
volume
------
* volume (get/set)
* volup
* voldown
setup.py
0 → 100644
View file @
63f869c6
import
os
from
setuptools
import
setup
,
find_packages
setup
(
name
=
'vlcclient'
,
version
=
'0.1.0'
,
description
=
"Control VLC instances using python."
,
long_description
=
open
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'README.rst'
))
.
read
(),
license
=
'BSD'
,
url
=
"https://github.com/DerMitch/py-vlcclient"
,
author
=
'Michael Mayr'
,
author_email
=
'michael@michfrm.net'
,
py_modules
=
[
'vlcclient'
],
classifiers
=
[
'Development Status :: 4 - Beta'
,
'License :: OSI Approved :: BSD License'
,
],
)
\ No newline at end of file
vlcclient.py
0 → 100644
View file @
63f869c6
# coding: utf-8
"""
VLCClient
~~~~~~~~~
This module allows to control a VLC instance to be controlled
via telnet. You need to enable the telnet interface, e.g. start
VLC like this:
$ vlc --intf telnet
More information about the telnet interface:
http://wiki.videolan.org/Documentation:Streaming_HowTo/VLM
:author: Michael Mayr <michael@michfrm.net>
:licence: MIT License
:version: 0.1.0
"""
"""
ToDo:
- Connection error handling
"""
import
sys
import
telnetlib
class
VLCClient
(
object
):
"""Connection to a running VLC instance."""
def
__init__
(
self
,
server
,
port
=
4212
,
password
=
"admin"
):
self
.
server
=
server
self
.
port
=
port
self
.
password
=
password
self
.
telnet
=
None
def
connect
(
self
):
"""Connect to VLC and login"""
assert
self
.
telnet
is
None
,
"connect() called twice"
self
.
telnet
=
telnetlib
.
Telnet
()
self
.
telnet
.
open
(
self
.
server
,
self
.
port
)
# Login
self
.
telnet
.
read_until
(
"Password: "
)
self
.
telnet
.
write
(
self
.
password
)
self
.
telnet
.
write
(
"
\n
"
)
# Password correct?
result
=
self
.
telnet
.
expect
([
"Password: "
,
">"
])
if
"Password"
in
result
[
2
]:
raise
WrongPasswordError
()
def
disconnect
(
self
):
"""Disconnect and close connection"""
self
.
telnet
.
close
()
self
.
telnet
=
None
def
send_command
(
self
,
line
):
"""Sends a command to VLC and returns the text reply.
This command may block."""
self
.
telnet
.
write
(
line
+
"
\n
"
)
return
self
.
telnet
.
read_until
(
">"
)[
1
:
-
3
]
#
# Commands
#
def
help
(
self
):
"""Returns the full command reference"""
return
self
.
send_command
(
"help"
)
def
status
(
self
):
"""current playlist status"""
return
self
.
send_command
(
"status"
)
def
info
(
self
):
"""information about the current stream"""
return
self
.
send_command
(
"info"
)
#
# Playlist
#
def
add
(
self
,
filename
):
"""Add a file to the playlist and play it.
This command always succeeds."""
return
self
.
send_command
(
"add {0}"
.
format
(
filename
))
def
enqueue
(
self
,
filename
):
"""Add a file to the playlist. This command always succeeds."""
return
self
.
send_command
(
"enqueue {0}"
.
format
(
filename
))
def
seek
(
self
,
second
):
"""Jump to a position at the current stream if supported."""
return
self
.
send_command
(
"seek {0}"
.
format
(
second
))
def
play
(
self
):
"""Start/Continue the current stream"""
return
self
.
send_command
(
"play"
)
def
pause
(
self
):
"""Pause playing"""
return
self
.
send_command
(
"pause"
)
def
stop
(
self
):
"""Stop stream"""
return
self
.
send_command
(
"stop"
)
def
rewind
(
self
):
"""Rewind stream"""
return
self
.
send_command
(
"rewind"
)
def
next
(
self
):
"""Play next item in playlist"""
return
self
.
send_command
(
"next"
)
def
prev
(
self
):
"""Play previous item in playlist"""
return
self
.
send_command
(
"prev"
)
def
clear
(
self
):
"""Clear all items in playlist"""
return
self
.
send_command
(
"clear"
)
#
# Volume
#
def
volume
(
self
,
vol
=
None
):
"""Get the current volume or set it"""
if
vol
:
return
self
.
send_command
(
"volume {0}"
.
format
(
vol
))
else
:
return
self
.
send_command
(
"volume"
)
.
strip
()
def
volup
(
self
,
steps
=
1
):
"""Increase the volume"""
return
self
.
send_command
(
"volup {0}"
.
format
(
steps
))
def
voldown
(
self
,
steps
=
1
):
"""Decrease the volume"""
return
self
.
send_command
(
"voldown {0}"
.
format
(
steps
))
class
WrongPasswordError
(
Exception
):
pass
def
main
():
vlc
=
VLCClient
(
"::1"
)
vlc
.
connect
()
try
:
command
=
getattr
(
vlc
,
sys
.
argv
[
1
])
except
IndexError
:
print
"usage: vlcclient.py command [argument]"
sys
.
exit
(
1
)
attr
=
sys
.
argv
[
2
]
if
len
(
sys
.
argv
)
>
2
else
None
try
:
print
command
(
attr
)
except
TypeError
:
print
command
()
if
__name__
==
'__main__'
:
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment