mnet.py 2.8 KB

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