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.

70 lines
2.5 KiB

8 years ago
8 years ago
8 years ago
  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. _TESTS = [{
  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. # no tbr extracted from stream_url
  21. 'url': 'http://www.mgtv.com/v/1/1/f/3324755.html',
  22. 'only_matching': True,
  23. }]
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. api_data = self._download_json(
  27. 'http://v.api.mgtv.com/player/video', video_id,
  28. query={'video_id': video_id},
  29. headers=self.geo_verification_headers())['data']
  30. info = api_data['info']
  31. formats = []
  32. for idx, stream in enumerate(api_data['stream']):
  33. stream_url = stream.get('url')
  34. if not stream_url:
  35. continue
  36. tbr = int_or_none(self._search_regex(
  37. r'(\d+)\.mp4', stream_url, 'tbr', default=None))
  38. def extract_format(stream_url, format_id, idx, query={}):
  39. format_info = self._download_json(
  40. stream_url, video_id,
  41. note='Download video info for format %s' % (format_id or '#%d' % idx),
  42. query=query)
  43. return {
  44. 'format_id': format_id,
  45. 'url': format_info['info'],
  46. 'ext': 'mp4',
  47. 'tbr': tbr,
  48. }
  49. formats.append(extract_format(
  50. stream_url, 'hls-%d' % tbr if tbr else None, idx * 2))
  51. formats.append(extract_format(stream_url.replace(
  52. '/playlist.m3u8', ''), 'http-%d' % tbr if tbr else None, idx * 2 + 1, {'pno': 1031}))
  53. self._sort_formats(formats)
  54. return {
  55. 'id': video_id,
  56. 'title': info['title'].strip(),
  57. 'formats': formats,
  58. 'description': info.get('desc'),
  59. 'duration': int_or_none(info.get('duration')),
  60. 'thumbnail': info.get('thumb'),
  61. }