huajiao.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from ..utils import parse_duration, parse_iso8601
  4. from .common import InfoExtractor
  5. class HuajiaoIE(InfoExtractor):
  6. IE_DESC = '花椒直播'
  7. _VALID_URL = r'https?://(?:www\.)?huajiao\.com/l/(?P<id>[0-9]+)'
  8. _TEST = {
  9. 'url': 'http://www.huajiao.com/l/38941232',
  10. 'md5': 'd08bf9ac98787d24d1e4c0283f2d372d',
  11. 'info_dict': {
  12. 'id': '38941232',
  13. 'ext': 'mp4',
  14. 'title': '#新人求关注#',
  15. 'description': 're:.*',
  16. 'duration': 2424.0,
  17. 'thumbnail': 're:^https?://.*\.jpg$',
  18. 'timestamp': 1475866459,
  19. 'upload_date': '20161007',
  20. 'uploader': 'Penny_余姿昀',
  21. 'uploader_id': '75206005',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. feed_json = self._search_regex(
  28. r'var\s*feed\s*=\s*({.*})', webpage, 'feed json str')
  29. feed = self._parse_json(feed_json, video_id)
  30. description = self._html_search_meta(
  31. 'description', webpage, 'description', fatal=False)
  32. return {
  33. 'id': video_id,
  34. 'title': feed['feed']['formated_title'],
  35. 'description': description,
  36. 'duration': parse_duration(feed['feed']['duration']),
  37. 'thumbnail': feed['feed']['image'],
  38. 'timestamp': parse_iso8601(feed['creatime'], ' '),
  39. 'uploader': feed['author']['nickname'],
  40. 'uploader_id': feed['author']['uid'],
  41. 'formats': self._extract_m3u8_formats(
  42. feed['feed']['m3u8'], video_id, 'mp4', 'm3u8_native'),
  43. }