logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

huajiao.py (1850B)


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