live.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # TODO: should these return the full dict? i.e. not get() the inner data when there's only one top field
  2. # doing so at least makes the return type consistent (always dict, unless it's like, is_live)
  3. class LiveEndpointsMixin:
  4. """
  5. For endpoints in */api/live/*
  6. """
  7. def bradaru_texts(self, room_id):
  8. """
  9. Returns a list of canned responses, e.g.:
  10. [
  11. {"text":"Bravo time will end in 30 seconds!","id":1},
  12. {"text":"How did you like the performance?","id":2}, ...
  13. ]
  14. :param room_id: numerical room_id (either as a str or an int)
  15. :return:
  16. """
  17. endpoint = "/api/live/bradaru_texts"
  18. results = self._api_get(endpoint, params={"room_id": room_id})
  19. return results.get('texts')
  20. def comment_log(self, room_id, is_delay=None):
  21. """
  22. Get a live room's comment log
  23. :param room_id:
  24. :param is_delay:
  25. :return: a list of comment dicts
  26. """
  27. endpoint = "/api/live/comment_log"
  28. # TODO: test whether is_delay is valid (should be an int, not sure otherwise)
  29. # default is {"comment_log":[]}, if this returns None there was an error
  30. results = self._api_get(endpoint, params={"room_id": room_id, "is_delay": is_delay})
  31. return results.get('comment_log')
  32. def onlives(self):
  33. endpoint = "/api/live/onlives"
  34. results = self._api_get(endpoint)
  35. # TODO: helper method to make this simpler to use?
  36. return results.get("onlives")
  37. def onlive_num(self):
  38. endpoint = "/api/live/onlive_num"
  39. results = self._api_get(endpoint)
  40. return results.get("num")
  41. def telop(self, room_id):
  42. """
  43. Get a live room's current telop
  44. :param room_id:
  45. :return: the telop as a string
  46. """
  47. endpoint = "/api/live/telop"
  48. results = self._api_get(endpoint, params={"room_id": room_id})
  49. return results.get('telop')
  50. def streaming_url(self, room_id):
  51. endpoint = "/api/live/streaming_url"
  52. results = self._api_get(endpoint, params={"room_id": room_id})
  53. return results.get('streaming_url_list')
  54. def current_user(self, room_id):
  55. endpoint = "/api/live/current_user"
  56. results = self._api_get(endpoint, params={"room_id": room_id})
  57. return results.get('streaming_url_list')
  58. def gift_list(self, room_id):
  59. endpoint = "/api/live/gift_list"
  60. results = self._api_get(endpoint, params={"room_id": room_id})
  61. # TODO: are there other names for the top field? e.g. performance_time, enquete_time
  62. return results.get("bravo_time")
  63. def gift_log(self, room_id):
  64. endpoint = "/api/live/gift_log"
  65. results = self._api_get(endpoint, params={"room_id": room_id})
  66. # TODO: are there other names for the top field? e.g. performance_time, enquete_time
  67. return results.get("gift_log")
  68. def summary_ranking(self, room_id):
  69. endpoint = "/api/live/summary_ranking"
  70. results = self._api_get(endpoint, params={"room_id": room_id})
  71. # TODO: are there other names for the top field? e.g. performance_time, enquete_time
  72. return results.get("ranking")
  73. def live_info(self, room_id):
  74. endpoint = "/api/live/live_info"
  75. results = self._api_get(endpoint, params={"room_id": room_id})
  76. # TODO: helper methods to get specific fields from this
  77. # TODO: document fields, e.g. what do the different values of live_status mean
  78. return results
  79. def stage_user_list(self, room_id):
  80. endpoint = "/api/live/stage_user_list"
  81. results = self._api_get(endpoint, params={"room_id": room_id})
  82. return results.get('stage_user_list')
  83. def stage_gift_list(self, room_id):
  84. endpoint = "/api/live/stage_gift_list"
  85. results = self._api_get(endpoint, params={"room_id": room_id})
  86. return results.get('stage_gift_list')
  87. def polling(self, room_id):
  88. endpoint = "/api/live/polling"
  89. results = self._api_get(endpoint, params={"room_id": room_id})
  90. return results.get('stage_gift_list')
  91. def enquete_result(self, room_id):
  92. endpoint = "/api/live/enquete_result"
  93. results = self._api_get(endpoint, params={"room_id": room_id})
  94. # TODO: make this human readable (need to find a recent poll)
  95. # {"l":[],"v":"v1","i":"https://image.showroom-live.com/showroom-prod/assets/img/gift"}
  96. return results
  97. def poll_result(self, room_id):
  98. return self.enquete_result(room_id)
  99. def upcoming(self, genre_id):
  100. # TODO: helper methods for getting specific genre
  101. endpoint = "/api/live/upcoming"
  102. results = self._api_get(endpoint, params={"genre_id": genre_id})
  103. return results.get('upcomings')
  104. def verify_age(self):
  105. # does this require auth?
  106. endpoint = "/api/live/age_verification"
  107. result = self._api_post(endpoint, data=dict(
  108. room_id=int,
  109. year=int,
  110. month=int,
  111. day=int,
  112. csrf_token=self._csrf_token
  113. ))
  114. return result
  115. def send_free_gift(self, gift_id, live_id, num, is_delay=None, latitude=None, longitude=None, radius=None):
  116. """
  117. Requires auth
  118. valid free gift_ids = 1, 2, 1001, 1002, 1003
  119. TODO: are there other valid gift ids? e.g. for amateur rooms?
  120. :return:
  121. """
  122. if int(gift_id) not in (1, 2, 1001, 1002, 1003):
  123. raise ValueError("Invalid Free Gift ID")
  124. if not (0 <= int(num) <= 10):
  125. raise ValueError("Invalid Free Gift Count")
  126. endpoint = "/api/live/gifting_free"
  127. result = self._api_post(endpoint, data=dict(
  128. gift_id=gift_id,
  129. live_id=live_id,
  130. num=num,
  131. is_delay=is_delay,
  132. lat=latitude,
  133. lon=longitude,
  134. rad=radius,
  135. csrf_token=self._csrf_token
  136. ))
  137. return result
  138. def send_paid_gift(self, gift_id, live_id, num, is_delay=None, latitude=None, longitude=None, radius=None):
  139. """
  140. Requires auth
  141. :return:
  142. """
  143. endpoint = "/api/live/gifting_point_use"
  144. result = self._api_post(endpoint, data=dict(
  145. gift_id=gift_id,
  146. live_id=live_id,
  147. num=num, # TODO: bounds check
  148. is_delay=is_delay,
  149. lat=latitude,
  150. lon=longitude,
  151. rad=radius,
  152. csrf_token=self._csrf_token
  153. ))
  154. return result
  155. def send_comment(self, live_id, comment, is_delay=None, latitude=None, longitude=None, radius=None):
  156. """
  157. Requires auth
  158. :return:
  159. """
  160. endpoint = "/api/live/post_live_comment"
  161. result = self._api_post(endpoint, data=dict(
  162. live_id=live_id,
  163. comment=comment, # TODO: character limit ?
  164. is_delay=is_delay,
  165. lat=latitude,
  166. lon=longitude,
  167. rad=radius,
  168. csrf_token=self._csrf_token
  169. ))
  170. return result