nate.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import itertools
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. str_or_none,
  6. traverse_obj,
  7. unified_strdate,
  8. )
  9. class NateIE(InfoExtractor):
  10. _VALID_URL = r'https?://tv\.nate\.com/clip/(?P<id>[0-9]+)'
  11. _TESTS = [{
  12. 'url': 'https://tv.nate.com/clip/1848976',
  13. 'info_dict': {
  14. 'id': '1848976',
  15. 'ext': 'mp4',
  16. 'title': '[결승 오프닝 타이틀] 2018 LCK 서머 스플릿 결승전 kt Rolster VS Griffin',
  17. 'description': 'md5:e1b79a7dcf0d8d586443f11366f50e6f',
  18. 'thumbnail': r're:^https?://.*\.jpg',
  19. 'upload_date': '20180908',
  20. 'age_limit': 15,
  21. 'duration': 73,
  22. 'uploader': '2018 LCK 서머 스플릿(롤챔스)',
  23. 'channel': '2018 LCK 서머 스플릿(롤챔스)',
  24. 'channel_id': '3606',
  25. 'uploader_id': '3606',
  26. 'tags': 'count:59',
  27. },
  28. 'params': {'skip_download': True},
  29. }, {
  30. 'url': 'https://tv.nate.com/clip/4300566',
  31. 'info_dict': {
  32. 'id': '4300566',
  33. 'ext': 'mp4',
  34. 'title': '[심쿵엔딩] 이준호x이세영, 서로를 기억하며 끌어안는 두 사람!💕, MBC 211204 방송',
  35. 'description': 'md5:be1653502d9c13ce344ddf7828e089fa',
  36. 'thumbnail': r're:^https?://.*\.jpg',
  37. 'upload_date': '20211204',
  38. 'age_limit': 15,
  39. 'duration': 201,
  40. 'uploader': '옷소매 붉은 끝동',
  41. 'channel': '옷소매 붉은 끝동',
  42. 'channel_id': '27987',
  43. 'uploader_id': '27987',
  44. 'tags': 'count:20',
  45. },
  46. 'params': {'skip_download': True},
  47. }]
  48. _QUALITY = {
  49. '36': 2160,
  50. '35': 1080,
  51. '34': 720,
  52. '33': 480,
  53. '32': 360,
  54. '31': 270,
  55. }
  56. def _real_extract(self, url):
  57. video_id = self._match_id(url)
  58. video_data = self._download_json(f'https://tv.nate.com/api/v1/clip/{video_id}', video_id)
  59. formats = [{
  60. 'format_id': f_url[-2:],
  61. 'url': f_url,
  62. 'height': self._QUALITY.get(f_url[-2:]),
  63. 'quality': int_or_none(f_url[-2:]),
  64. } for f_url in video_data.get('smcUriList') or []]
  65. return {
  66. 'id': video_id,
  67. 'title': video_data.get('clipTitle'),
  68. 'description': video_data.get('synopsis'),
  69. 'thumbnail': video_data.get('contentImg'),
  70. 'upload_date': unified_strdate(traverse_obj(video_data, 'broadDate', 'regDate')),
  71. 'age_limit': video_data.get('targetAge'),
  72. 'duration': video_data.get('playTime'),
  73. 'formats': formats,
  74. 'uploader': video_data.get('programTitle'),
  75. 'channel': video_data.get('programTitle'),
  76. 'channel_id': str_or_none(video_data.get('programSeq')),
  77. 'uploader_id': str_or_none(video_data.get('programSeq')),
  78. 'tags': video_data['hashTag'].split(',') if video_data.get('hashTag') else None,
  79. }
  80. class NateProgramIE(InfoExtractor):
  81. _VALID_URL = r'https?://tv\.nate\.com/program/clips/(?P<id>[0-9]+)'
  82. _TESTS = [{
  83. 'url': 'https://tv.nate.com/program/clips/27987',
  84. 'playlist_mincount': 191,
  85. 'info_dict': {
  86. 'id': '27987',
  87. },
  88. }, {
  89. 'url': 'https://tv.nate.com/program/clips/3606',
  90. 'playlist_mincount': 15,
  91. 'info_dict': {
  92. 'id': '3606',
  93. },
  94. }]
  95. def _entries(self, playlist_id):
  96. for page_num in itertools.count(1):
  97. program_data = self._download_json(
  98. f'https://tv.nate.com/api/v1/program/{playlist_id}/clip/ranking?size=20&page={page_num}',
  99. playlist_id, note=f'Downloading page {page_num}')
  100. for clip in program_data.get('content') or []:
  101. clip_id = clip.get('clipSeq')
  102. if clip_id:
  103. yield self.url_result(
  104. f'https://tv.nate.com/clip/{clip_id}', NateIE, playlist_id)
  105. if program_data.get('last'):
  106. break
  107. def _real_extract(self, url):
  108. playlist_id = self._match_id(url)
  109. return self.playlist_result(self._entries(playlist_id), playlist_id=playlist_id)