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.

64 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})['data']
  25. info = api_data['info']
  26. formats = []
  27. for idx, stream in enumerate(api_data['stream']):
  28. stream_url = stream.get('url')
  29. if not stream_url:
  30. continue
  31. tbr = int_or_none(self._search_regex(
  32. r'(\d+)\.mp4', stream_url, 'tbr', default=None))
  33. def extract_format(stream_url, format_id, idx, query={}):
  34. format_info = self._download_json(
  35. stream_url, video_id,
  36. note='Download video info for format %s' % format_id or '#%d' % idx, query=query)
  37. return {
  38. 'format_id': format_id,
  39. 'url': format_info['info'],
  40. 'ext': 'mp4',
  41. 'tbr': tbr,
  42. }
  43. formats.append(extract_format(
  44. stream_url, 'hls-%d' % tbr if tbr else None, idx * 2))
  45. formats.append(extract_format(stream_url.replace(
  46. '/playlist.m3u8', ''), 'http-%d' % tbr if tbr else None, idx * 2 + 1, {'pno': 1031}))
  47. self._sort_formats(formats)
  48. return {
  49. 'id': video_id,
  50. 'title': info['title'].strip(),
  51. 'formats': formats,
  52. 'description': info.get('desc'),
  53. 'duration': int_or_none(info.get('duration')),
  54. 'thumbnail': info.get('thumb'),
  55. }