You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import ExtractorError
  5. class DouyuTVIE(InfoExtractor):
  6. _VALID_URL = r'http://(?:www\.)?douyutv\.com/(?P<id>[A-Za-z0-9]+)'
  7. _TEST = {
  8. 'url': 'http://www.douyutv.com/iseven',
  9. 'info_dict': {
  10. 'id': 'iseven',
  11. 'ext': 'flv',
  12. 'title': 're:^清晨醒脑!T-ara根本停不下来! [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  13. 'description': 'md5:9e525642c25a0a24302869937cf69d17',
  14. 'thumbnail': 're:^https?://.*\.jpg$',
  15. 'uploader': '7师傅',
  16. 'uploader_id': '431925',
  17. 'is_live': True,
  18. },
  19. 'params': {
  20. 'skip_download': True,
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. config = self._download_json(
  26. 'http://www.douyutv.com/api/client/room/%s' % video_id, video_id)
  27. data = config['data']
  28. error_code = config.get('error', 0)
  29. show_status = data.get('show_status')
  30. if error_code is not 0:
  31. raise ExtractorError(
  32. 'Server reported error %i' % error_code, expected=True)
  33. # 1 = live, 2 = offline
  34. if show_status == '2':
  35. raise ExtractorError(
  36. 'Live stream is offline', expected=True)
  37. base_url = data['rtmp_url']
  38. live_path = data['rtmp_live']
  39. title = self._live_title(data['room_name'])
  40. description = data.get('show_details')
  41. thumbnail = data.get('room_src')
  42. uploader = data.get('nickname')
  43. uploader_id = data.get('owner_uid')
  44. multi_formats = data.get('rtmp_multi_bitrate')
  45. if not isinstance(multi_formats, dict):
  46. multi_formats = {}
  47. multi_formats['live'] = live_path
  48. formats = [{
  49. 'url': '%s/%s' % (base_url, format_path),
  50. 'format_id': format_id,
  51. 'preference': 1 if format_id == 'live' else 0,
  52. } for format_id, format_path in multi_formats.items()]
  53. self._sort_formats(formats)
  54. return {
  55. 'id': video_id,
  56. 'title': title,
  57. 'description': description,
  58. 'thumbnail': thumbnail,
  59. 'uploader': uploader,
  60. 'uploader_id': uploader_id,
  61. 'formats': formats,
  62. 'is_live': True,
  63. }