douyutv.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. unescapeHTML,
  7. )
  8. class DouyuTVIE(InfoExtractor):
  9. IE_DESC = '斗鱼'
  10. _VALID_URL = r'https?://(?:www\.)?douyu(?:tv)?\.com/(?:[^/]+/)*(?P<id>[A-Za-z0-9]+)'
  11. _TESTS = [{
  12. 'url': 'http://www.douyutv.com/iseven',
  13. 'info_dict': {
  14. 'id': '17732',
  15. 'display_id': 'iseven',
  16. 'ext': 'mp4',
  17. 'title': 're:^清晨醒脑!T-ARA根本停不下来! [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  18. 'description': r're:.*m7show@163\.com.*',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. 'uploader': '7师傅',
  21. 'is_live': True,
  22. },
  23. 'params': {
  24. 'skip_download': True,
  25. },
  26. }, {
  27. 'url': 'http://www.douyutv.com/85982',
  28. 'info_dict': {
  29. 'id': '85982',
  30. 'display_id': '85982',
  31. 'ext': 'mp4',
  32. 'title': 're:^小漠从零单排记!——CSOL2躲猫猫 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  33. 'description': 'md5:746a2f7a253966a06755a912f0acc0d2',
  34. 'thumbnail': r're:^https?://.*\.jpg$',
  35. 'uploader': 'douyu小漠',
  36. 'is_live': True,
  37. },
  38. 'params': {
  39. 'skip_download': True,
  40. },
  41. 'skip': 'Room not found',
  42. }, {
  43. 'url': 'http://www.douyutv.com/17732',
  44. 'info_dict': {
  45. 'id': '17732',
  46. 'display_id': '17732',
  47. 'ext': 'mp4',
  48. 'title': 're:^清晨醒脑!T-ARA根本停不下来! [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  49. 'description': r're:.*m7show@163\.com.*',
  50. 'thumbnail': r're:^https?://.*\.jpg$',
  51. 'uploader': '7师傅',
  52. 'is_live': True,
  53. },
  54. 'params': {
  55. 'skip_download': True,
  56. },
  57. }, {
  58. 'url': 'http://www.douyu.com/xiaocang',
  59. 'only_matching': True,
  60. }, {
  61. # \"room_id\"
  62. 'url': 'http://www.douyu.com/t/lpl',
  63. 'only_matching': True,
  64. }]
  65. # Decompile core.swf in webpage by ffdec "Search SWFs in memory". core.swf
  66. # is encrypted originally, but ffdec can dump memory to get the decrypted one.
  67. _API_KEY = 'A12Svb&%1UUmf@hC'
  68. def _real_extract(self, url):
  69. video_id = self._match_id(url)
  70. if video_id.isdigit():
  71. room_id = video_id
  72. else:
  73. page = self._download_webpage(url, video_id)
  74. room_id = self._html_search_regex(
  75. r'"room_id\\?"\s*:\s*(\d+),', page, 'room id')
  76. room = self._download_json(
  77. 'http://m.douyu.com/html5/live?roomId=%s' % room_id, video_id,
  78. note='Downloading room info')['data']
  79. # 1 = live, 2 = offline
  80. if room.get('show_status') == '2':
  81. raise ExtractorError('Live stream is offline', expected=True)
  82. formats = self._extract_m3u8_formats(
  83. room['hls_url'], video_id, ext='mp4')
  84. title = self._live_title(unescapeHTML(room['room_name']))
  85. description = room.get('show_details')
  86. thumbnail = room.get('room_src')
  87. uploader = room.get('nickname')
  88. return {
  89. 'id': room_id,
  90. 'display_id': video_id,
  91. 'formats': formats,
  92. 'title': title,
  93. 'description': description,
  94. 'thumbnail': thumbnail,
  95. 'uploader': uploader,
  96. 'is_live': True,
  97. }