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

Source Code for Module Skype4Py.call

  1  '''Calls, conferences. 
  2  ''' 
  3   
  4  from utils import * 
  5  from enums import * 
  6  from errors import * 
  7   
  8   
9 -class ICall(Cached):
10 '''Represents a voice/video call. 11 ''' 12
13 - def __repr__(self):
14 return '<%s with Id=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id))
15
16 - def _Alter(self, AlterName, Args=None):
17 return self._Skype._Alter('CALL', self._Id, AlterName, Args)
18
19 - def _Init(self, Id, Skype):
20 self._Skype = Skype 21 self._Id = int(Id)
22
23 - def _Property(self, PropName, Set=None, Cache=True):
24 return self._Skype._Property('CALL', self._Id, PropName, Set, Cache)
25
26 - def Answer(self):
27 '''Answers the call. 28 ''' 29 self._Property('STATUS', 'INPROGRESS')
30
31 - def CanTransfer(self, Target):
32 '''Queries if a call can be transferred to a contact or phone number. 33 34 @param Target: Skypename or phone number the call is to be transfered to. 35 @type Target: unicode 36 @return: True if call can be transfered, False otherwise. 37 @rtype: bool 38 ''' 39 return self._Property('CAN_TRANSFER %s' % Target) == 'TRUE'
40
41 - def CaptureMicDevice(self, DeviceType=None, Set=None):
42 '''Queries or sets the mic capture device. 43 44 @param DeviceType: Mic capture device type or None. 45 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 46 @param Set: Value the device should be set to or None. 47 @type Set: unicode, int or None 48 @return: If DeviceType and Set are None, returns a dictionary of device types and their 49 values. Dictionary contains only those device types, whose values were set. If the 50 DeviceType is not None but Set is None, returns the current value of the device or 51 None if the device wasn't set. If Set is not None, sets a new value for the device. 52 @rtype: unicode, dict or None 53 54 @note: This command functions for active calls only. 55 ''' 56 if Set == None: # get 57 args = args2dict(self._Property('CAPTURE_MIC', Cache=False)) 58 for t in args: 59 if t == callIoDeviceTypePort: 60 args[t] = int(args[t]) 61 if DeviceType == None: # get active devices 62 return args 63 return args.get(DeviceType, None) 64 elif DeviceType != None: # set 65 self._Alter('SET_CAPTURE_MIC', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 66 else: 67 raise TypeError('DeviceType must be specified if Set is used')
68
69 - def Finish(self):
70 '''Ends the call. 71 ''' 72 self._Property('STATUS', 'FINISHED')
73
74 - def Forward(self):
75 '''Forwards a call. 76 ''' 77 self._Alter('END', 'FORWARD_CALL')
78
79 - def Hold(self):
80 '''Puts the call on hold. 81 ''' 82 self._Property('STATUS', 'ONHOLD')
83
84 - def InputDevice(self, DeviceType=None, Set=None):
85 '''Queries or sets the sound input device. 86 87 @param DeviceType: Sound input device type or None. 88 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 89 @param Set: Value the device should be set to or None. 90 @type Set: unicode, int or None 91 @return: If DeviceType and Set are None, returns a dictionary of device types and their 92 values. Dictionary contains only those device types, whose values were set. If the 93 DeviceType is not None but Set is None, returns the current value of the device or 94 None if the device wasn't set. If Set is not None, sets a new value for the device. 95 @rtype: unicode, dict or None 96 97 @note: This command functions for active calls only. 98 ''' 99 if Set == None: # get 100 args = args2dict(self._Property('INPUT', Cache=False)) 101 for t in args: 102 if t == callIoDeviceTypePort: 103 args[t] = int(args[t]) 104 if DeviceType == None: # get active devices 105 return args 106 return args.get(DeviceType, None) 107 elif DeviceType != None: # set 108 self._Alter('SET_INPUT', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 109 else: 110 raise TypeError('DeviceType must be specified if Set is used')
111
112 - def Join(self, Id):
113 '''Joins with another call to form a conference. 114 115 @param Id: Call Id of the other call to join to the conference. 116 @type Id: int 117 @return: Conference object. 118 @rtype: L{IConference} 119 ''' 120 reply = self._Skype._DoCommand('SET CALL %s JOIN_CONFERENCE %s' % (self._Id, Id), 121 'CALL %s CONF_ID' % self._Id) 122 return IConference(reply.split()[-1], self._Skype)
123
124 - def MarkAsSeen(self):
125 '''Marks the call as seen. 126 ''' 127 self.Seen = True
128
129 - def OutputDevice(self, DeviceType=None, Set=None):
130 '''Queries or sets the sound output device. 131 132 @param DeviceType: Sound output device type or None. 133 @type DeviceType: L{Call IO device type<enums.callIoDeviceTypeUnknown>} or None 134 @param Set: Value the device should be set to or None. 135 @type Set: unicode, int or None 136 @return: If DeviceType and Set are None, returns a dictionary of device types and their 137 values. Dictionary contains only those device types, whose values were set. If the 138 DeviceType is not None but Set is None, returns the current value of the device or 139 None if the device wasn't set. If Set is not None, sets a new value for the device. 140 @rtype: unicode, dict or None 141 142 @note: This command functions for active calls only. 143 ''' 144 if Set == None: # get 145 args = args2dict(self._Property('OUTPUT', Cache=False)) 146 for t in args: 147 if t == callIoDeviceTypePort: 148 args[t] = int(args[t]) 149 if DeviceType == None: # get active devices 150 return args 151 return args.get(DeviceType, None) 152 elif DeviceType != None: # set 153 self._Alter('SET_OUTPUT', '%s=%s' % (DeviceType, quote(unicode(Set), True))) 154 else: 155 raise TypeError('DeviceType must be specified if Set is used')
156
157 - def RedirectToVoicemail(self):
158 '''Redirects a call to voicemail. 159 ''' 160 self._Alter('END', 'REDIRECT_TO_VOICEMAIL')
161
162 - def Resume(self):
163 '''Resumes the held call. 164 ''' 165 self.Answer()
166
167 - def StartVideoReceive(self):
168 '''Starts video receive. 169 ''' 170 self._Alter('START_VIDEO_RECEIVE')
171
172 - def StartVideoSend(self):
173 '''Starts video send. 174 ''' 175 self._Alter('START_VIDEO_SEND')
176
177 - def StopVideoReceive(self):
178 '''Stops video receive. 179 ''' 180 self._Alter('STOP_VIDEO_RECEIVE')
181
182 - def StopVideoSend(self):
183 '''Stops video send. 184 ''' 185 self._Alter('STOP_VIDEO_SEND')
186
187 - def Transfer(self, *Targets):
188 '''Transfers a call to one or more contacts or phone numbers. 189 190 @param Targets: one or more phone numbers or Skypenames the call is beeing transferred to. 191 @type Targets: unicode 192 @see: L{CanTransfer} 193 194 @note: You can transfer an incoming call to a group by specifying more than one 195 target, first one of the group to answer will get the call. 196 ''' 197 self._Alter('TRANSFER', ', '.join(Targets))
198
199 - def _GetConferenceId(self):
200 return int(self._Property('CONF_ID'))
201 202 ConferenceId = property(_GetConferenceId, 203 doc='''ConferenceId. 204 205 @type: int 206 ''') 207
208 - def _GetDatetime(self):
209 from datetime import datetime 210 return datetime.fromtimestamp(self.Timestamp)
211 212 Datetime = property(_GetDatetime, 213 doc='''Date and time of the call. 214 215 @type: datetime.datetime 216 @see: L{Timestamp} 217 ''') 218
219 - def _SetDTMF(self, value):
220 self._Property('DTMF', value)
221 222 DTMF = property(fset=_SetDTMF, 223 doc='''Set this property to send DTMF codes. 224 225 @type: unicode 226 227 @note: This command functions for active calls only. 228 ''') 229
230 - def _GetDuration(self):
231 return int(self._Property('DURATION', Cache=False))
232 233 Duration = property(_GetDuration, 234 doc='''Duration of the call in seconds. 235 236 @type: int 237 ''') 238
239 - def _GetFailureReason(self):
240 return int(self._Property('FAILUREREASON'))
241 242 FailureReason = property(_GetFailureReason, 243 doc='''Call failure reason. Read if L{Status} == L{clsFailed<enums.clsFailed>}. 244 245 @type: L{Call failure reason<enums.cfrUnknown>} 246 ''') 247
248 - def _GetForwardedBy(self):
249 return self._Property('FORWARDED_BY')
250 251 ForwardedBy = property(_GetForwardedBy, 252 doc='''Skypename of the user who forwarded a call. 253 254 @type: unicode 255 ''') 256
257 - def _GetId(self):
258 return self._Id
259 260 Id = property(_GetId, 261 doc='''Call Id. 262 263 @type: int 264 ''') 265
266 - def _GetInputStatus(self):
267 return self._Property('VAA_INPUT_STATUS') == 'TRUE'
268 269 InputStatus = property(_GetInputStatus, 270 doc='''True if call voice input is enabled. 271 272 @type: bool 273 ''') 274
275 - def _GetParticipants(self):
276 count = int(self._Property('CONF_PARTICIPANTS_COUNT')) 277 return tuple(IParticipant((self._Id, x), self._Skype) for x in xrange(count))
278 279 Participants = property(_GetParticipants, 280 doc='''Participants of a conference call not hosted by the user. 281 282 @type: tuple of L{IParticipant} 283 ''') 284
285 - def _GetPartnerDisplayName(self):
286 return self._Property('PARTNER_DISPNAME')
287 288 PartnerDisplayName = property(_GetPartnerDisplayName, 289 doc='''The DisplayName of the remote caller. 290 291 @type: unicode 292 ''') 293
294 - def _GetPartnerHandle(self):
295 return self._Property('PARTNER_HANDLE')
296 297 PartnerHandle = property(_GetPartnerHandle, 298 doc='''The Skypename of the remote caller. 299 300 @type: unicode 301 ''') 302
303 - def _GetPstnNumber(self):
304 return self._Property('PSTN_NUMBER')
305 306 PstnNumber = property(_GetPstnNumber, 307 doc='''PSTN number of the call. 308 309 @type: unicode 310 ''') 311
312 - def _GetPstnStatus(self):
313 return self._Property('PSTN_STATUS')
314 315 PstnStatus = property(_GetPstnStatus, 316 doc='''PSTN number status. 317 318 @type: unicode 319 ''') 320
321 - def _GetRate(self):
322 return int(self._Property('RATE'))
323 324 Rate = property(_GetRate, 325 doc='''Call rate. Expressed using L{RatePrecision}. If you're just interested in the call rate 326 expressed in current currency, use L{RateValue} instead. 327 328 @type: int 329 @see: L{RateCurrency}, L{RatePrecision}, L{RateToText}, L{RateValue} 330 ''') 331
332 - def _GetRateCurrency(self):
333 return self._Property('RATE_CURRENCY')
334 335 RateCurrency = property(_GetRateCurrency, 336 doc='''Call rate currency. 337 338 @type: unicode 339 @see: L{Rate}, L{RatePrecision}, L{RateToText}, L{RateValue} 340 ''') 341
342 - def _GetRatePrecision(self):
343 return int(self._Property('RATE_PRECISION'))
344 345 RatePrecision = property(_GetRatePrecision, 346 doc='''Call rate precision. Expressed as a number of times the call rate has to be divided by 10. 347 348 @type: int 349 @see: L{Rate}, L{RateCurrency}, L{RateToText}, L{RateValue} 350 ''') 351
352 - def _GetRateToText(self):
353 return (u'%s %.3f' % (self.RateCurrency, self.RateValue)).strip()
354 355 RateToText = property(_GetRateToText, 356 doc='''Returns the call rate as a text with currency and properly formatted value. 357 358 @type: unicode 359 @see: L{Rate}, L{RateCurrency}, L{RatePrecision}, L{RateValue} 360 ''') 361
362 - def _GetRateValue(self):
363 if self.Rate < 0: 364 return 0.0 365 return float(self.Rate) / (10 ** self.RatePrecision)
366 367 RateValue = property(_GetRateValue, 368 doc='''Call rate value. Expressed in current currency. 369 370 @type: float 371 @see: L{Rate}, L{RateCurrency}, L{RatePrecision}, L{RateToText} 372 ''') 373
374 - def _GetSeen(self):
375 return self._Property('SEEN') == 'TRUE'
376
377 - def _SetSeen(self, value):
378 self._Property('SEEN', cndexp(value, 'TRUE', 'FALSE'))
379 380 Seen = property(_GetSeen, _SetSeen, 381 doc='''Queries/sets the seen status of the call. True if the call was seen, False otherwise. 382 383 @type: bool 384 385 @note: You cannot alter the call seen status from seen to unseen. 386 ''') 387
388 - def _GetStatus(self):
389 return self._Property('STATUS')
390
391 - def _SetStatus(self, value):
392 self._Property('STATUS', str(value))
393 394 Status = property(_GetStatus, _SetStatus, 395 doc='''The call status. 396 397 @type: L{Call status<enums.clsUnknown>} 398 ''') 399
400 - def _GetSubject(self):
401 return self._Property('SUBJECT')
402 403 Subject = property(_GetSubject, 404 doc='''Call subject. 405 406 @type: unicode 407 ''') 408
409 - def _GetTargetIdentify(self):
410 return self._Property('TARGET_IDENTIFY')
411 412 TargetIdentify = property(_GetTargetIdentify, 413 doc='''Target number for incoming SkypeIn calls. 414 415 @type: unicode 416 ''') 417
418 - def _GetTimestamp(self):
419 return float(self._Property('TIMESTAMP'))
420 421 Timestamp = property(_GetTimestamp, 422 doc='''Call date and time expressed as a timestamp. 423 424 @type: float 425 @see: L{Datetime} 426 ''') 427
428 - def _GetTransferActive(self):
429 return self._Property('TRANSFER_ACTIVE') == 'TRUE'
430 431 TransferActive = property(_GetTransferActive, 432 doc='''Returns True if the call has been transfered. 433 434 @type: bool 435 ''') 436
437 - def _GetTransferredBy(self):
438 return self._Property('TRANSFERRED_BY')
439 440 TransferredBy = property(_GetTransferredBy, 441 doc='''Returns the Skypename of the user who transferred the call. 442 443 @type: unicode 444 ''') 445
446 - def _GetTransferredTo(self):
447 return self._Property('TRANSFERRED_TO')
448 449 TransferredTo = property(_GetTransferredTo, 450 doc='''Returns the Skypename of the user or phone number the call has been transferred to. 451 452 @type: unicode 453 ''') 454
455 - def _GetTransferStatus(self):
456 return self._Property('TRANSFER_STATUS')
457 458 TransferStatus = property(_GetTransferStatus, 459 doc='''Returns the call transfer status. 460 461 @type: L{Call status<enums.clsUnknown>} 462 ''') 463
464 - def _GetType(self):
465 return self._Property('TYPE')
466 467 Type = property(_GetType, 468 doc='''Call type. 469 470 @type: L{Call type<enums.cltUnknown>} 471 ''') 472
473 - def _GetVideoReceiveStatus(self):
474 return self._Property('VIDEO_RECEIVE_STATUS')
475 476 VideoReceiveStatus = property(_GetVideoReceiveStatus, 477 doc='''Call video receive status. 478 479 @type: L{Call video send status<enums.vssUnknown>} 480 ''') 481
482 - def _GetVideoSendStatus(self):
483 return self._Property('VIDEO_SEND_STATUS')
484 485 VideoSendStatus = property(_GetVideoSendStatus, 486 doc='''Call video send status. 487 488 @type: L{Call video send status<enums.vssUnknown>} 489 ''') 490
491 - def _GetVideoStatus(self):
492 return self._Property('VIDEO_STATUS')
493 494 VideoStatus = property(_GetVideoStatus, 495 doc='''Call video status. 496 497 @type: L{Call video status<enums.cvsUnknown>} 498 ''') 499
500 - def _GetVmAllowedDuration(self):
501 return int(self._Property('VM_ALLOWED_DURATION'))
502 503 VmAllowedDuration = property(_GetVmAllowedDuration, 504 doc='''Returns the permitted duration of a voicemail in seconds. 505 506 @type: int 507 ''') 508
509 - def _GetVmDuration(self):
510 return int(self._Property('VM_DURATION'))
511 512 VmDuration = property(_GetVmDuration, 513 doc='''Returns the duration of a voicemail. 514 515 @type: int 516 ''')
517 518
519 -class IParticipant(Cached):
520 '''Represents a conference call participant. 521 ''' 522
523 - def __repr__(self):
524 return '<%s with Id=%s, Idx=%s, Handle=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id), repr(self.Idx), repr(self.Handle))
525
526 - def _Init(self, (Id, Idx), Skype):
527 self._Skype = Skype 528 self._Id = int(Id) 529 self._Idx = int(Idx)
530
531 - def _Property(self, Prop):
532 reply = self._Skype._Property('CALL', self._Id, 'CONF_PARTICIPANT %d' % self._Idx) 533 return chop(reply, 3)[Prop]
534
535 - def _GetCallStatus(self):
536 return self._Property(2)
537 538 CallStatus = property(_GetCallStatus, 539 doc='''Call status of a participant in a conference call. 540 541 @type: L{Call status<enums.clsUnknown>} 542 ''') 543
544 - def _GetCallType(self):
545 return self._Property(1)
546 547 CallType = property(_GetCallType, 548 doc='''Call type in a conference call. 549 550 @type: L{Call type<enums.cltUnknown>} 551 ''') 552
553 - def _GetDisplayName(self):
554 return self._Property(3)
555 556 DisplayName = property(_GetDisplayName, 557 doc='''DisplayName of a participant in a conference call. 558 559 @type: unicode 560 ''') 561
562 - def _GetHandle(self):
563 return self._Property(0)
564 565 Handle = property(_GetHandle, 566 doc='''Skypename of a participant in a conference call. 567 568 @type: unicode 569 ''') 570
571 - def _GetId(self):
572 return self._Id
573 574 Id = property(_GetId, 575 doc='''Call Id. 576 577 @type: int 578 ''') 579
580 - def _GetIdx(self):
581 return self._Idx
582 583 Idx = property(_GetIdx, 584 doc='''Call participant index. 585 586 @type: int 587 ''')
588 589
590 -class IConference(Cached):
591 '''Represents a conference call. 592 ''' 593
594 - def __repr__(self):
595 return '<%s with Id=%s>' % (Cached.__repr__(self)[1:-1], repr(self.Id))
596
597 - def _Init(self, Id, Skype):
598 self._Skype = Skype 599 self._Id = int(Id)
600
601 - def Finish(self):
602 '''Finishes a conference so all active calls have the status L{clsFinished<enums.clsFinished>}. 603 ''' 604 for c in self._GetCalls(): 605 c.Finish()
606
607 - def Hold(self):
608 '''Places all calls in a conference on hold so all active calls have the status L{clsLocalHold<enums.clsLocalHold>}. 609 ''' 610 for c in self._GetCalls(): 611 c.Hold()
612
613 - def Resume(self):
614 '''Resumes a conference that was placed on hold so all active calls have the status L{clsInProgress<enums.clsInProgress>}. 615 ''' 616 for c in self._GetCalls(): 617 c.Resume()
618
619 - def _GetActiveCalls(self):
620 return tuple(x for x in self._Skype.ActiveCalls if x.ConferenceId == self._Id)
621 622 ActiveCalls = property(_GetActiveCalls, 623 doc='''Active calls with the same conference ID. 624 625 @type: tuple of L{ICall} 626 ''') 627
628 - def _GetCalls(self):
629 return tuple(x for x in self._Skype.Calls() if x.ConferenceId == self._Id)
630 631 Calls = property(_GetCalls, 632 doc='''Calls with the same conference ID. 633 634 @type: tuple of L{ICall} 635 ''') 636
637 - def _GetId(self):
638 return self._Id
639 640 Id = property(_GetId, 641 doc='''Id of a conference. 642 643 @type: int 644 ''')
645