user_tune.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. """
  2. SleekXMPP: The Sleek XMPP Library
  3. Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
  4. This file is part of SleekXMPP.
  5. See the file LICENSE for copying permission.
  6. """
  7. import logging
  8. from sleekxmpp.plugins.base import BasePlugin
  9. from sleekxmpp.plugins.xep_0118 import stanza, UserTune
  10. log = logging.getLogger(__name__)
  11. class XEP_0118(BasePlugin):
  12. """
  13. XEP-0118: User Tune
  14. """
  15. name = 'xep_0118'
  16. description = 'XEP-0118: User Tune'
  17. dependencies = set(['xep_0163'])
  18. stanza = stanza
  19. def plugin_end(self):
  20. self.xmpp['xep_0030'].del_feature(feature=UserTune.namespace)
  21. self.xmpp['xep_0163'].remove_interest(UserTune.namespace)
  22. def session_bind(self, jid):
  23. self.xmpp['xep_0163'].register_pep('user_tune', UserTune)
  24. def publish_tune(self, artist=None, length=None, rating=None, source=None,
  25. title=None, track=None, uri=None, options=None,
  26. ifrom=None, block=True, callback=None, timeout=None):
  27. """
  28. Publish the user's current tune.
  29. Arguments:
  30. artist -- The artist or performer of the song.
  31. length -- The length of the song in seconds.
  32. rating -- The user's rating of the song (from 1 to 10)
  33. source -- The album name, website, or other source of the song.
  34. title -- The title of the song.
  35. track -- The song's track number, or other unique identifier.
  36. uri -- A URL to more information about the song.
  37. options -- Optional form of publish options.
  38. ifrom -- Specify the sender's JID.
  39. block -- Specify if the send call will block until a response
  40. is received, or a timeout occurs. Defaults to True.
  41. timeout -- The length of time (in seconds) to wait for a response
  42. before exiting the send call if blocking is used.
  43. Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
  44. callback -- Optional reference to a stream handler function. Will
  45. be executed when a reply stanza is received.
  46. """
  47. tune = UserTune()
  48. tune['artist'] = artist
  49. tune['length'] = length
  50. tune['rating'] = rating
  51. tune['source'] = source
  52. tune['title'] = title
  53. tune['track'] = track
  54. tune['uri'] = uri
  55. return self.xmpp['xep_0163'].publish(tune,
  56. node=UserTune.namespace,
  57. options=options,
  58. ifrom=ifrom,
  59. block=block,
  60. callback=callback,
  61. timeout=timeout)
  62. def stop(self, ifrom=None, block=True, callback=None, timeout=None):
  63. """
  64. Clear existing user tune information to stop notifications.
  65. Arguments:
  66. ifrom -- Specify the sender's JID.
  67. block -- Specify if the send call will block until a response
  68. is received, or a timeout occurs. Defaults to True.
  69. timeout -- The length of time (in seconds) to wait for a response
  70. before exiting the send call if blocking is used.
  71. Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
  72. callback -- Optional reference to a stream handler function. Will
  73. be executed when a reply stanza is received.
  74. """
  75. tune = UserTune()
  76. return self.xmpp['xep_0163'].publish(tune,
  77. node=UserTune.namespace,
  78. ifrom=ifrom,
  79. block=block,
  80. callback=callback,
  81. timeout=timeout)