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.

65 lines
2.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. class MGTVIE(InfoExtractor):
  6. _VALID_URL = r'https?://www\.mgtv\.com/v/(?:[^/]+/)*(?P<id>\d+)\.html'
  7. IE_DESC = '芒果TV'
  8. _TEST = {
  9. 'url': 'http://www.mgtv.com/v/1/290525/f/3116640.html',
  10. 'md5': '1bdadcf760a0b90946ca68ee9a2db41a',
  11. 'info_dict': {
  12. 'id': '3116640',
  13. 'ext': 'mp4',
  14. 'title': '我是歌手第四季双年巅峰会:韩红李玟“双王”领军对抗',
  15. 'description': '我是歌手第四季双年巅峰会',
  16. 'duration': 7461,
  17. 'thumbnail': 're:^https?://.*\.jpg$',
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. api_data = self._download_json(
  23. 'http://v.api.mgtv.com/player/video', video_id,
  24. query={'video_id': video_id},
  25. headers=self.geo_verification_headers())['data']
  26. info = api_data['info']
  27. formats = []
  28. for idx, stream in enumerate(api_data['stream']):
  29. stream_url = stream.get('url')
  30. if not stream_url:
  31. continue
  32. tbr = int_or_none(self._search_regex(
  33. r'(\d+)\.mp4', stream_url, 'tbr', default=None))
  34. def extract_format(stream_url, format_id, idx, query={}):
  35. format_info = self._download_json(
  36. stream_url, video_id,
  37. note='Download video info for format %s' % format_id or '#%d' % idx, query=query)
  38. return {
  39. 'format_id': format_id,
  40. 'url': format_info['info'],
  41. 'ext': 'mp4',
  42. 'tbr': tbr,
  43. }
  44. formats.append(extract_format(
  45. stream_url, 'hls-%d' % tbr if tbr else None, idx * 2))
  46. formats.append(extract_format(stream_url.replace(
  47. '/playlist.m3u8', ''), 'http-%d' % tbr if tbr else None, idx * 2 + 1, {'pno': 1031}))
  48. self._sort_formats(formats)
  49. return {
  50. 'id': video_id,
  51. 'title': info['title'].strip(),
  52. 'formats': formats,
  53. 'description': info.get('desc'),
  54. 'duration': int_or_none(info.get('duration')),
  55. 'thumbnail': info.get('thumb'),
  56. }