| 1 |
"""Wrapper around vlc module in order to ease the use of vlc.Object |
|---|
| 2 |
class (completion in ipython, access variable as attributes, etc). |
|---|
| 3 |
|
|---|
| 4 |
$Id$ |
|---|
| 5 |
""" |
|---|
| 6 |
import vlc |
|---|
| 7 |
import vlcinternal |
|---|
| 8 |
|
|---|
| 9 |
class VLCObject(object): |
|---|
| 10 |
def __init__(self, id): |
|---|
| 11 |
object.__setattr__(self, '_o', vlcinternal.Object(id)) |
|---|
| 12 |
|
|---|
| 13 |
def find(self, typ): |
|---|
| 14 |
"""Returns a VLCObject for the given child. |
|---|
| 15 |
|
|---|
| 16 |
See vlc.Object.find_object.__doc__ for the different values of typ. |
|---|
| 17 |
""" |
|---|
| 18 |
t=self._o.find_object(typ) |
|---|
| 19 |
if t is not None: |
|---|
| 20 |
return VLCObject(t.info()['object-id']) |
|---|
| 21 |
else: |
|---|
| 22 |
return None |
|---|
| 23 |
|
|---|
| 24 |
def __str__(self): |
|---|
| 25 |
"""Returns a string representation of the object. |
|---|
| 26 |
""" |
|---|
| 27 |
i=self._o.info() |
|---|
| 28 |
return "VLCObject %d (%s) : %s" % (i['object-id'], |
|---|
| 29 |
i['object-type'], |
|---|
| 30 |
i['object-name']) |
|---|
| 31 |
|
|---|
| 32 |
def tree(self, prefix=" "): |
|---|
| 33 |
"""Displays all children as a tree of VLCObject |
|---|
| 34 |
""" |
|---|
| 35 |
res=prefix + str(self) + "\n" |
|---|
| 36 |
for i in self._o.children(): |
|---|
| 37 |
t=VLCObject(i) |
|---|
| 38 |
res += t.tree(prefix=prefix + " ") |
|---|
| 39 |
return res |
|---|
| 40 |
|
|---|
| 41 |
def __getattribute__(self, attr): |
|---|
| 42 |
"""Converts attribute access to access to variables. |
|---|
| 43 |
""" |
|---|
| 44 |
if attr == '__members__': |
|---|
| 45 |
|
|---|
| 46 |
o=object.__getattribute__(self, '_o') |
|---|
| 47 |
l=dir(o) |
|---|
| 48 |
l.extend([ n.replace('-','_') for n in o.list() ]) |
|---|
| 49 |
return l |
|---|
| 50 |
try: |
|---|
| 51 |
return object.__getattribute__ (self, attr) |
|---|
| 52 |
except AttributeError, e: |
|---|
| 53 |
try: |
|---|
| 54 |
return self._o.__getattribute__ (attr) |
|---|
| 55 |
except AttributeError, e: |
|---|
| 56 |
attr=attr.replace('_', '-') |
|---|
| 57 |
if attr in self._o.list(): |
|---|
| 58 |
return self._o.get(attr) |
|---|
| 59 |
else: |
|---|
| 60 |
raise e |
|---|
| 61 |
|
|---|
| 62 |
def __setattr__(self, name, value): |
|---|
| 63 |
"""Handle attribute assignment. |
|---|
| 64 |
""" |
|---|
| 65 |
n=name.replace('_', '-') |
|---|
| 66 |
if n in self._o.list(): |
|---|
| 67 |
self._o.set(n, value) |
|---|
| 68 |
else: |
|---|
| 69 |
object.__setattr__(self, name, value) |
|---|
| 70 |
|
|---|
| 71 |
def test(f='/tmp/k.mpg'): |
|---|
| 72 |
global mc,o |
|---|
| 73 |
mc=vlc.MediaControl() |
|---|
| 74 |
mc.playlist_add_item(f) |
|---|
| 75 |
mc.start(0) |
|---|
| 76 |
mc.pause(0) |
|---|
| 77 |
o=VLCObject(0) |
|---|
| 78 |
v=o.find('vout') |
|---|
| 79 |
|
|---|