saitosan.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from .common import InfoExtractor
  2. from ..utils import ExtractorError, try_get
  3. class SaitosanIE(InfoExtractor):
  4. IE_NAME = 'Saitosan'
  5. _VALID_URL = r'https?://(?:www\.)?saitosan\.net/bview.html\?id=(?P<id>[0-9]+)'
  6. _TESTS = [{
  7. 'url': 'http://www.saitosan.net/bview.html?id=10031846',
  8. 'info_dict': {
  9. 'id': '10031846',
  10. 'ext': 'mp4',
  11. 'title': '井下原 和弥',
  12. 'uploader': '井下原 和弥',
  13. 'thumbnail': 'http://111.171.196.85:8088/921f916f-7f55-4c97-b92e-5d9d0fef8f5f/thumb',
  14. 'is_live': True,
  15. },
  16. 'params': {
  17. # m3u8 download
  18. 'skip_download': True,
  19. },
  20. 'skip': 'Broadcasts are ephemeral',
  21. },
  22. {
  23. 'url': 'http://www.saitosan.net/bview.html?id=10031795',
  24. 'info_dict': {
  25. 'id': '10031795',
  26. 'ext': 'mp4',
  27. 'title': '橋本',
  28. 'uploader': '橋本',
  29. 'thumbnail': 'http://111.171.196.85:8088/1a3933e1-a01a-483b-8931-af15f37f8082/thumb',
  30. 'is_live': True,
  31. },
  32. 'params': {
  33. # m3u8 download
  34. 'skip_download': True,
  35. },
  36. 'skip': 'Broadcasts are ephemeral',
  37. }]
  38. def _real_extract(self, url):
  39. b_id = self._match_id(url)
  40. base = 'http://hankachi.saitosan-api.net:8002/socket.io/?transport=polling&EIO=3'
  41. sid = self._download_socket_json(base, b_id, note='Opening socket').get('sid')
  42. base += '&sid=' + sid
  43. self._download_webpage(base, b_id, note='Polling socket')
  44. payload = '420["room_start_join",{"room_id":"%s"}]' % b_id
  45. payload = '%s:%s' % (len(payload), payload)
  46. self._download_webpage(base, b_id, data=payload, note='Polling socket with payload')
  47. response = self._download_socket_json(base, b_id, note='Polling socket')
  48. if not response.get('ok'):
  49. err = response.get('error') or {}
  50. raise ExtractorError(
  51. '%s said: %s - %s' % (self.IE_NAME, err.get('code', '?'), err.get('msg', 'Unknown')) if err
  52. else 'The socket reported that the broadcast could not be joined. Maybe it\'s offline or the URL is incorrect',
  53. expected=True, video_id=b_id)
  54. self._download_webpage(base, b_id, data='26:421["room_finish_join",{}]', note='Polling socket')
  55. b_data = self._download_socket_json(base, b_id, note='Getting broadcast metadata from socket')
  56. m3u8_url = b_data.get('url')
  57. self._download_webpage(base, b_id, data='1:1', note='Closing socket', fatal=False)
  58. return {
  59. 'id': b_id,
  60. 'title': b_data.get('name'),
  61. 'formats': self._extract_m3u8_formats(m3u8_url, b_id, 'mp4', live=True),
  62. 'thumbnail': m3u8_url.replace('av.m3u8', 'thumb'),
  63. 'uploader': try_get(b_data, lambda x: x['broadcast_user']['name']), # same as title
  64. 'is_live': True
  65. }