douyutv.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. )
  7. class DouyutvIE(InfoExtractor):
  8. _VALID_URL = r'http://(?:www\.)?douyutv\.com/(?P<id>[A-Za-z0-9]+)'
  9. '''
  10. show_status: 1 直播中 ,2 没有直播
  11. '''
  12. _TEST = {
  13. 'url': 'http://www.douyutv.com/iseven',
  14. 'info_dict': {
  15. 'id': 'iseven',
  16. 'title': '清晨醒脑!T-ara根本停不下来!',
  17. 'ext': 'flv',
  18. 'thumbnail': 're:^https?://.*\.jpg$',
  19. 'is_live': True,
  20. }
  21. }
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. info_url = 'http://www.douyutv.com/api/client/room/' + video_id
  25. config = self._download_json(info_url, video_id)
  26. error_code = config.get('error')
  27. show_status = config['data'].get('show_status')
  28. if error_code is not 0:
  29. raise ExtractorError('Server reported error %i' % error_code,
  30. expected=True)
  31. if show_status == '2':
  32. raise ExtractorError('The live show has not yet started',
  33. expected=True)
  34. title = config['data'].get('room_name')
  35. rtmp_url = config['data'].get('rtmp_url')
  36. rtmp_live = config['data'].get('rtmp_live')
  37. thumbnail = config['data'].get('room_src')
  38. url = rtmp_url+'/'+rtmp_live
  39. return {
  40. 'id': video_id,
  41. 'title': title,
  42. 'ext':'flv',
  43. 'url': url,
  44. 'thumbnail': thumbnail,
  45. 'is_live': True,
  46. # TODO more properties (see youtube_dl/extractor/common.py)
  47. }