]> git.sesse.net Git - vlc/blob - bindings/python-ctypes/override.py
python-ctypes: define additional docstrings
[vlc] / bindings / python-ctypes / override.py
1 class Instance:
2     """Create a new Instance instance.
3
4     It may take as parameter either:
5       - a string
6       - a list of strings as first parameters
7       - the parameters given as the constructor parameters (must be strings)
8       - a MediaControl instance
9     """
10     def __new__(cls, *p):
11         if p and p[0] == 0:
12             return None
13         elif p and isinstance(p[0], (int, long)):
14             # instance creation from ctypes
15             o=object.__new__(cls)
16             o._as_parameter_=ctypes.c_void_p(p[0])
17             return o
18         elif len(p) == 1 and isinstance(p[0], basestring):
19             # Only 1 string parameter: should be a parameter line
20             p=p[0].split(' ')
21         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
22             p=p[0]
23
24         if p and isinstance(p[0], MediaControl):
25             return p[0].get_instance()
26         else:
27             e=VLCException()
28             return libvlc_new(len(p), p, e)
29
30     def media_player_new(self, uri=None):
31         """Create a new Media Player object.
32
33         @param uri: an optional URI to play in the player.
34         """
35         e=VLCException()
36         p=libvlc_media_player_new(self, e)
37         if uri:
38             p.set_media(self.media_new(uri))
39         p._instance=self
40         return p
41
42     def media_list_player_new(self):
43         """Create an empty Media Player object
44         """
45         e=VLCException()
46         p=libvlc_media_list_player_new(self, e)
47         p._instance=self
48         return p
49
50 class MediaControl:
51     """Create a new MediaControl instance
52
53     It may take as parameter either:
54       - a string
55       - a list of strings as first parameters
56       - the parameters given as the constructor parameters (must be strings)
57       - a vlc.Instance
58     """
59     def __new__(cls, *p):
60         if p and p[0] == 0:
61             return None
62         elif p and isinstance(p[0], (int, long)):
63             # instance creation from ctypes
64             o=object.__new__(cls)
65             o._as_parameter_=ctypes.c_void_p(p[0])
66             return o
67         elif len(p) == 1 and isinstance(p[0], basestring):
68             # Only 1 string parameter: should be a parameter line
69             p=p[0].split(' ')
70         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
71             p=p[0]
72
73         if p and isinstance(p[0], Instance):
74             e=MediaControlException()
75             return mediacontrol_new_from_instance(p[0], e)
76         else:
77             e=MediaControlException()
78             return mediacontrol_new(len(p), p, e)
79
80     def get_media_position(self, origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime):
81         e=MediaControlException()
82         p=mediacontrol_get_media_position(self, origin, key, e)
83         if p:
84             return p.contents
85         else:
86             return None
87
88     def set_media_position(self, pos):
89         """Set the media position.
90
91         @param pos: a MediaControlPosition or an integer (in ms)
92         """
93         if not isinstance(pos, MediaControlPosition):
94             pos=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(pos))
95         e=MediaControlException()
96         mediacontrol_set_media_position(self, pos, e)
97
98     def start(self, pos=0):
99         """Start the player at the given position.
100
101         @param pos: a MediaControlPosition or an integer (in ms)
102         """
103         if not isinstance(pos, MediaControlPosition):
104             pos=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(pos))
105         e=MediaControlException()
106         mediacontrol_start(self, pos, e)
107
108     def snapshot(self, pos=0):
109         """Take a snapshot.
110
111         Note: the position parameter is not properly implemented. For
112         the moment, the only valid position is the 0-relative position
113         (i.e. the current position).
114
115         @param pos: a MediaControlPosition or an integer (in ms)
116         """
117         if not isinstance(pos, MediaControlPosition):
118             pos=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(pos))
119         e=MediaControlException()
120         p=mediacontrol_snapshot(self, pos, e)
121         if p:
122             return p.contents
123         else:
124             return None
125
126     def display_text(self, message='', begin=0, end=1000):
127         """Display a caption between begin and end positions.
128
129         @param message: the caption to display
130         @param begin: the begin position
131         @param end: the end position
132         """
133         if not isinstance(begin, MediaControlPosition):
134             begin=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(begin))
135         if not isinstance(end, MediaControlPosition):
136             begin=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(end))
137         e=MediaControlException()
138         mediacontrol_display_text(self, message, begin, end, e)
139
140     def get_stream_information(self, key=PositionKey.MediaTime):
141         """Return information about the stream.
142         """
143         e=MediaControlException()
144         return mediacontrol_get_stream_information(self, key, e).contents
145
146 class MediaPlayer:
147     """Create a new MediaPlayer instance.
148
149     It may take as parameter either:
150       - a string (media URI). In this case, a vlc.Instance will be created.
151       - a vlc.Instance
152     """
153     def __new__(cls, *p):
154         if p and p[0] == 0:
155             return None
156         elif p and isinstance(p[0], (int, long)):
157             # instance creation from ctypes
158             o=object.__new__(cls)
159             o._as_parameter_=ctypes.c_void_p(p[0])
160             return o
161
162         if p and isinstance(p[0], Instance):
163             return p[0].media_player_new()
164         else:
165             i=Instance()
166             o=i.media_player_new()
167             if p:
168                 o.set_media(i.media_new(p[0]))
169             return o
170
171     def get_instance(self):
172         """Return the associated vlc.Instance.
173         """
174         return self._instance
175
176 class MediaListPlayer:
177     """Create a new MediaPlayer instance.
178
179     It may take as parameter either:
180       - a vlc.Instance
181       - nothing
182     """
183     def __new__(cls, *p):
184         if p and p[0] == 0:
185             return None
186         elif p and isinstance(p[0], (int, long)):
187             # instance creation from ctypes
188             o=object.__new__(cls)
189             o._as_parameter_=ctypes.c_void_p(p[0])
190             return o
191         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
192             p=p[0]
193
194         if p and isinstance(p[0], Instance):
195             return p[0].media_list_player_new()
196         else:
197             i=Instance()
198             o=i.media_list_player_new()
199             return o
200
201     def get_instance(self):
202         """Return the associated vlc.Instance.
203         """
204         return self._instance
205
206 class LogIterator:
207     def __iter__(self):
208         return self
209
210     def next(self):
211         if not self.has_next():
212             raise StopIteration
213         buffer=LogMessage()
214         e=VLCException()
215         ret=libvlc_log_iterator_next(self, buffer, e)
216         return ret
217
218 class Log:
219     def __iter__(self):
220         return self.get_iterator()