Package Skype4Py :: Module voicemail
[frames] | no frames]

Source Code for Module Skype4Py.voicemail

  1  '''Voicemails. 
  2  ''' 
  3   
  4  from utils import * 
  5  from enums import * 
  6   
  7   
8 -class IVoicemail(Cached):
9 '''Represents a voicemail. 10 ''' 11
12 - def __repr__(self):
13 return '<%s with Id=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id))
14
15 - def _Alter(self, AlterName, Args=None):
16 return self._Skype._Alter('VOICEMAIL', self._Id, AlterName, Args)
17
18 - def _Init(self, Id, Skype):
19 self._Id = int(Id) 20 self._Skype = Skype
21
22 - def _Property(self, PropName, Set=None, Cache=True):
23 return self._Skype._Property('VOICEMAIL', self._Id, PropName, Set, Cache)
24
25 - def CaptureMicDevice(self, DeviceType=None, Set=None):
26 '''Queries or sets the mic capture device. 27 28 @param DeviceType: Mic capture device type or None. 29 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 30 @param Set: Value the device should be set to or None. 31 @type Set: unicode, int or None 32 @return: If DeviceType and Set are None, returns a dictionary of device types and their 33 values. Dictionary contains only those device types, whose values were set. If the 34 DeviceType is not None but Set is None, returns the current value of the device or 35 None if the device wasn't set. If Set is not None, sets a new value for the device. 36 @rtype: unicode, dict or None 37 ''' 38 if Set == None: # get 39 args = args2dict(self._Property('CAPTURE_MIC', Cache=False)) 40 for t in args: 41 if t == callIoDeviceTypePort: 42 args[t] = int(args[t]) 43 if DeviceType == None: # get active devices 44 return args 45 return args.get(DeviceType, None) 46 elif DeviceType != None: # set 47 self._Alter('SET_CAPTURE_MIC', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 48 else: 49 raise TypeError('DeviceType must be specified if Set is used')
50
51 - def Delete(self):
52 '''Deletes this voicemail. 53 ''' 54 self._Alter('DELETE')
55
56 - def Download(self):
57 '''Downloads this voicemail object from the voicemail server to a local computer. 58 ''' 59 self._Alter('DOWNLOAD')
60
61 - def InputDevice(self, DeviceType=None, Set=None):
62 '''Queries or sets the sound input device. 63 64 @param DeviceType: Sound input device type or None. 65 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 66 @param Set: Value the device should be set to or None. 67 @type Set: unicode, int or None 68 @return: If DeviceType and Set are None, returns a dictionary of device types and their 69 values. Dictionary contains only those device types, whose values were set. If the 70 DeviceType is not None but Set is None, returns the current value of the device or 71 None if the device wasn't set. If Set is not None, sets a new value for the device. 72 @rtype: unicode, dict or None 73 ''' 74 if Set == None: # get 75 args = args2dict(self._Property('INPUT', Cache=False)) 76 for t in args: 77 if t == callIoDeviceTypePort: 78 args[t] = int(args[t]) 79 if DeviceType == None: # get active devices 80 return args 81 return args.get(DeviceType, None) 82 elif DeviceType != None: # set 83 self._Alter('SET_INPUT', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 84 else: 85 raise TypeError('DeviceType must be specified if Set is used')
86
87 - def Open(self):
88 '''Opens and plays this voicemail. 89 ''' 90 self._Skype._DoCommand('OPEN VOICEMAIL %s' % self._Id)
91
92 - def OutputDevice(self, DeviceType=None, Set=None):
93 '''Queries or sets the sound output device. 94 95 @param DeviceType: Sound output device type or None. 96 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 97 @param Set: Value the device should be set to or None. 98 @type Set: unicode, int or None 99 @return: If DeviceType and Set are None, returns a dictionary of device types and their 100 values. Dictionary contains only those device types, whose values were set. If the 101 DeviceType is not None but Set is None, returns the current value of the device or 102 None if the device wasn't set. If Set is not None, sets a new value for the device. 103 @rtype: unicode, dict or None 104 ''' 105 if Set == None: # get 106 args = args2dict(self._Property('OUTPUT', Cache=False)) 107 for t in args: 108 if t == callIoDeviceTypePort: 109 args[t] = int(args[t]) 110 if DeviceType == None: # get active devices 111 return args 112 return args.get(DeviceType, None) 113 elif DeviceType != None: # set 114 self._Alter('SET_OUTPUT', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 115 else: 116 raise TypeError('DeviceType must be specified if Set is used')
117
118 - def SetUnplayed(self):
119 '''Changes the status of a voicemail from played to unplayed. 120 ''' 121 # Note. Due to a bug in Skype (tested using 3.8.0.115) the reply from 122 # [ALTER VOICEMAIL <id> SETUNPLAYED] is [ALTER VOICEMAIL <id> DELETE] 123 # causing the _Alter method to fail. Therefore we have to use a direct 124 # _DoCommand instead. 125 126 #self._Alter('SETUNPLAYED') 127 self._Skype._DoCommand('ALTER VOICEMAIL %d SETUNPLAYED' % self._Id, 128 'ALTER VOICEMAIL %d' % self._Id)
129
130 - def StartPlayback(self):
131 '''Starts playing downloaded voicemail. 132 ''' 133 self._Alter('STARTPLAYBACK')
134
135 - def StartPlaybackInCall(self):
136 '''Starts playing downloaded voicemail during a call. 137 ''' 138 self._Alter('STARTPLAYBACKINCALL')
139
140 - def StartRecording(self):
141 '''Stops playing a voicemail greeting and starts recording a voicemail message. 142 ''' 143 self._Alter('STARTRECORDING')
144
145 - def StopPlayback(self):
146 '''Stops playing downloaded voicemail. 147 ''' 148 self._Alter('STOPPLAYBACK')
149
150 - def StopRecording(self):
151 '''Ends the recording of a voicemail message. 152 ''' 153 self._Alter('STOPRECORDING')
154
155 - def Upload(self):
156 '''Uploads recorded voicemail from a local computer to the voicemail server. 157 ''' 158 self._Alter('UPLOAD')
159
160 - def _GetAllowedDuration(self):
161 return int(self._Property('ALLOWED_DURATION'))
162 163 AllowedDuration = property(_GetAllowedDuration, 164 doc='''Maximum voicemail duration in seconds allowed to leave to partner 165 166 @type: int 167 ''') 168
169 - def _GetDatetime(self):
170 from datetime import datetime 171 return datetime.fromtimestamp(self.Timestamp)
172 173 Datetime = property(_GetDatetime, 174 doc='''Timestamp of this voicemail expressed using datetime. 175 176 @type: datetime.datetime 177 ''') 178
179 - def _GetDuration(self):
180 return int(self._Property('DURATION'))
181 182 Duration = property(_GetDuration, 183 doc='''Actual voicemail duration in seconds. 184 185 @type: int 186 ''') 187
188 - def _GetFailureReason(self):
189 return self._Property('FAILUREREASON')
190 191 FailureReason = property(_GetFailureReason, 192 doc='''Voicemail failure reason. Read if L{Status} == L{vmsFailed<enums.vmsFailed>}. 193 194 @type: L{Voicemail failure reason<enums.vmrUnknown>} 195 ''') 196
197 - def _GetId(self):
198 return self._Id
199 200 Id = property(_GetId, 201 doc='''Unique voicemail Id. 202 203 @type: int 204 ''') 205
206 - def _GetPartnerDisplayName(self):
207 return self._Property('PARTNER_DISPNAME')
208 209 PartnerDisplayName = property(_GetPartnerDisplayName, 210 doc='''DisplayName for voicemail sender (for incoming) or recipient (for outgoing). 211 212 @type: unicode 213 ''') 214
215 - def _GetPartnerHandle(self):
216 return self._Property('PARTNER_HANDLE')
217 218 PartnerHandle = property(_GetPartnerHandle, 219 doc='''Skypename for voicemail sender (for incoming) or recipient (for outgoing). 220 221 @type: unicode 222 ''') 223
224 - def _GetStatus(self):
225 return self._Property('STATUS')
226 227 Status = property(_GetStatus, 228 doc='''Voicemail status. 229 230 @type: L{Voicemail status<enums.vmsUnknown>} 231 ''') 232
233 - def _GetTimestamp(self):
234 return float(self._Property('TIMESTAMP'))
235 236 Timestamp = property(_GetTimestamp, 237 doc='''Timestamp of this voicemail. 238 239 @type: float 240 ''') 241
242 - def _GetType(self):
243 return self._Property('TYPE')
244 245 Type = property(_GetType, 246 doc='''Voicemail type. 247 248 @type: L{Voicemail type<enums.vmtUnknown>} 249 ''')
250