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.

63 lines
2.0 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': '',
  11. 'info_dict': {
  12. 'id': '3116640',
  13. 'ext': 'mp4',
  14. 'title': '我是歌手第四季双年巅峰会:韩红李玟“双王”领军对抗',
  15. 'description': '我是歌手第四季双年巅峰会',
  16. 'duration': 7461,
  17. 'thumbnail': 're:^https?://.*\.jpg$',
  18. },
  19. 'params': {
  20. 'skip_download': True, # m3u8 download
  21. },
  22. }
  23. _FORMAT_MAP = {
  24. '标清': ('Standard', 0),
  25. '高清': ('High', 1),
  26. '超清': ('SuperHigh', 2),
  27. }
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. api_data = self._download_json(
  31. 'http://v.api.mgtv.com/player/video', video_id,
  32. query={'video_id': video_id})['data']
  33. info = api_data['info']
  34. formats = []
  35. for idx, stream in enumerate(api_data['stream']):
  36. format_name = stream.get('name')
  37. format_id, preference = self._FORMAT_MAP.get(format_name, (None, None))
  38. format_info = self._download_json(
  39. stream['url'], video_id,
  40. note='Download video info for format %s' % format_id or '#%d' % idx)
  41. formats.append({
  42. 'format_id': format_id,
  43. 'url': format_info['info'],
  44. 'ext': 'mp4', # These are m3u8 playlists
  45. 'preference': preference,
  46. })
  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. }