mgoon.py 2.5 KB

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