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.

87 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. qualities,
  8. unified_strdate,
  9. )
  10. class MgoonIE(InfoExtractor):
  11. _VALID_URL = r'''(?x)https?://(?:www\.)?
  12. (?:(:?m\.)?mgoon\.com/(?:ch/(?:.+)/v|play/view)|
  13. video\.mgoon\.com)/(?P<id>[0-9]+)'''
  14. _API_URL = 'http://mpos.mgoon.com/player/video?id={0:}'
  15. _TESTS = [
  16. {
  17. 'url': 'http://m.mgoon.com/ch/hi6618/v/5582148',
  18. 'md5': 'dd46bb66ab35cf6d51cc812fd82da79d',
  19. 'info_dict': {
  20. 'id': '5582148',
  21. 'uploader_id': 'hi6618',
  22. 'duration': 240.419,
  23. 'upload_date': '20131220',
  24. 'ext': 'mp4',
  25. 'title': 'md5:543aa4c27a4931d371c3f433e8cebebc',
  26. 'thumbnail': 're:^https?://.*\.jpg$',
  27. }
  28. },
  29. {
  30. 'url': 'http://www.mgoon.com/play/view/5582148',
  31. 'only_matching': True,
  32. },
  33. {
  34. 'url': 'http://video.mgoon.com/5582148',
  35. 'only_matching': True,
  36. },
  37. ]
  38. def _real_extract(self, url):
  39. mobj = re.match(self._VALID_URL, url)
  40. video_id = mobj.group('id')
  41. data = self._download_json(self._API_URL.format(video_id), video_id)
  42. if data.get('errorInfo', {}).get('code') != 'NONE':
  43. raise ExtractorError('%s encountered an error: %s' % (
  44. self.IE_NAME, data['errorInfo']['message']), expected=True)
  45. v_info = data['videoInfo']
  46. title = v_info.get('v_title')
  47. thumbnail = v_info.get('v_thumbnail')
  48. duration = v_info.get('v_duration')
  49. upload_date = unified_strdate(v_info.get('v_reg_date'))
  50. uploader_id = data.get('userInfo', {}).get('u_alias')
  51. if duration:
  52. duration /= 1000.0
  53. age_limit = None
  54. if data.get('accessInfo', {}).get('code') == 'VIDEO_STATUS_ADULT':
  55. age_limit = 18
  56. formats = []
  57. get_quality = qualities(['360p', '480p', '720p', '1080p'])
  58. for fmt in data['videoFiles']:
  59. formats.append({
  60. 'format_id': fmt['label'],
  61. 'quality': get_quality(fmt['label']),
  62. 'url': fmt['url'],
  63. 'ext': fmt['format'],
  64. })
  65. self._sort_formats(formats)
  66. return {
  67. 'id': video_id,
  68. 'title': title,
  69. 'formats': formats,
  70. 'thumbnail': thumbnail,
  71. 'duration': duration,
  72. 'upload_date': upload_date,
  73. 'uploader_id': uploader_id,
  74. 'age_limit': age_limit,
  75. }