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.

68 lines
2.3 KiB

9 years ago
9 years ago
9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import int_or_none
  6. class MGTVIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?mgtv\.com/(v|b)/(?:[^/]+/)*(?P<id>\d+)\.html'
  8. IE_DESC = '芒果TV'
  9. _TESTS = [{
  10. 'url': 'http://www.mgtv.com/v/1/290525/f/3116640.html',
  11. 'md5': 'b1ffc0fc163152acf6beaa81832c9ee7',
  12. 'info_dict': {
  13. 'id': '3116640',
  14. 'ext': 'mp4',
  15. 'title': '我是歌手第四季双年巅峰会:韩红李玟“双王”领军对抗',
  16. 'description': '我是歌手第四季双年巅峰会',
  17. 'duration': 7461,
  18. 'thumbnail': r're:^https?://.*\.jpg$',
  19. },
  20. }, {
  21. 'url': 'http://www.mgtv.com/b/301817/3826653.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://pcweb.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. title = info['title'].strip()
  32. stream_domain = api_data['stream_domain'][0]
  33. formats = []
  34. for idx, stream in enumerate(api_data['stream']):
  35. stream_path = stream.get('url')
  36. if not stream_path:
  37. continue
  38. format_data = self._download_json(
  39. stream_domain + stream_path, video_id,
  40. note='Download video info for format #%d' % idx)
  41. format_url = format_data.get('info')
  42. if not format_url:
  43. continue
  44. tbr = int_or_none(self._search_regex(
  45. r'_(\d+)_mp4/', format_url, 'tbr', default=None))
  46. formats.append({
  47. 'format_id': compat_str(tbr or idx),
  48. 'url': format_url,
  49. 'ext': 'mp4',
  50. 'tbr': tbr,
  51. 'protocol': 'm3u8_native',
  52. })
  53. self._sort_formats(formats)
  54. return {
  55. 'id': video_id,
  56. 'title': title,
  57. 'formats': formats,
  58. 'description': info.get('desc'),
  59. 'duration': int_or_none(info.get('duration')),
  60. 'thumbnail': info.get('thumb'),
  61. }