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.

89 lines
2.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_duration,
  7. parse_iso8601,
  8. )
  9. class MnetIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?mnet\.(?:com|interest\.me)/tv/vod/(?:.*?\bclip_id=)?(?P<id>[0-9]+)'
  11. _TESTS = [{
  12. 'url': 'http://www.mnet.com/tv/vod/171008',
  13. 'info_dict': {
  14. 'id': '171008',
  15. 'title': 'SS_이해인@히든박스',
  16. 'description': 'md5:b9efa592c3918b615ba69fe9f8a05c55',
  17. 'duration': 88,
  18. 'upload_date': '20151231',
  19. 'timestamp': 1451564040,
  20. 'age_limit': 0,
  21. 'thumbnails': 'mincount:5',
  22. 'thumbnail': r're:^https?://.*\.jpg$',
  23. 'ext': 'flv',
  24. },
  25. 'params': {
  26. # rtmp download
  27. 'skip_download': True,
  28. },
  29. }, {
  30. 'url': 'http://mnet.interest.me/tv/vod/172790',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'http://www.mnet.com/tv/vod/vod_view.asp?clip_id=172790&tabMenu=',
  34. 'only_matching': True,
  35. }]
  36. def _real_extract(self, url):
  37. video_id = self._match_id(url)
  38. # TODO: extract rtmp formats
  39. # no stype -> rtmp url
  40. # stype=H -> m3u8 url
  41. # stype=M -> mpd url
  42. info = self._download_json(
  43. 'http://content.api.mnet.com/player/vodConfig',
  44. video_id, 'Downloading vod config JSON', query={
  45. 'id': video_id,
  46. 'ctype': 'CLIP',
  47. 'stype': 'H',
  48. })['data']['info']
  49. title = info['title']
  50. cdn_data = self._download_json(
  51. info['cdn'], video_id, 'Downloading vod cdn JSON')['data'][0]
  52. m3u8_url = cdn_data['url']
  53. token = cdn_data.get('token')
  54. if token and token != '-':
  55. m3u8_url += '?' + token
  56. formats = self._extract_wowza_formats(
  57. m3u8_url, video_id, skip_protocols=['rtmp', 'rtsp', 'f4m'])
  58. self._sort_formats(formats)
  59. description = info.get('ment')
  60. duration = parse_duration(info.get('time'))
  61. timestamp = parse_iso8601(info.get('date'), delimiter=' ')
  62. age_limit = info.get('adult')
  63. if age_limit is not None:
  64. age_limit = 0 if age_limit == 'N' else 18
  65. thumbnails = [{
  66. 'id': thumb_format,
  67. 'url': thumb['url'],
  68. 'width': int_or_none(thumb.get('width')),
  69. 'height': int_or_none(thumb.get('height')),
  70. } for thumb_format, thumb in info.get('cover', {}).items() if thumb.get('url')]
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'description': description,
  75. 'duration': duration,
  76. 'timestamp': timestamp,
  77. 'age_limit': age_limit,
  78. 'thumbnails': thumbnails,
  79. 'formats': formats,
  80. }