huajiao.py 1.8 KB

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