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.

298 lines
11 KiB

11 years ago
11 years ago
11 years ago
9 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import itertools
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_parse_qs,
  8. compat_urllib_parse,
  9. compat_urllib_parse_unquote,
  10. compat_urlparse,
  11. )
  12. from ..utils import (
  13. int_or_none,
  14. str_to_int,
  15. xpath_text,
  16. unescapeHTML,
  17. )
  18. class DaumIE(InfoExtractor):
  19. _VALID_URL = r'https?://(?:(?:m\.)?tvpot\.daum\.net/v/|videofarm\.daum\.net/controller/player/VodPlayer\.swf\?vid=)(?P<id>[^?#&]+)'
  20. IE_NAME = 'daum.net'
  21. _TESTS = [{
  22. 'url': 'http://tvpot.daum.net/v/vab4dyeDBysyBssyukBUjBz',
  23. 'info_dict': {
  24. 'id': 'vab4dyeDBysyBssyukBUjBz',
  25. 'ext': 'mp4',
  26. 'title': '마크 헌트 vs 안토니오 실바',
  27. 'description': 'Mark Hunt vs Antonio Silva',
  28. 'upload_date': '20131217',
  29. 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
  30. 'duration': 2117,
  31. 'view_count': int,
  32. 'comment_count': int,
  33. },
  34. }, {
  35. 'url': 'http://m.tvpot.daum.net/v/65139429',
  36. 'info_dict': {
  37. 'id': '65139429',
  38. 'ext': 'mp4',
  39. 'title': '1297회, \'아빠 아들로 태어나길 잘 했어\' 민수, 감동의 눈물[아빠 어디가] 20150118',
  40. 'description': 'md5:79794514261164ff27e36a21ad229fc5',
  41. 'upload_date': '20150604',
  42. 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
  43. 'duration': 154,
  44. 'view_count': int,
  45. 'comment_count': int,
  46. },
  47. }, {
  48. 'url': 'http://tvpot.daum.net/v/07dXWRka62Y%24',
  49. 'only_matching': True,
  50. }, {
  51. 'url': 'http://videofarm.daum.net/controller/player/VodPlayer.swf?vid=vwIpVpCQsT8%24&ref=',
  52. 'info_dict': {
  53. 'id': 'vwIpVpCQsT8$',
  54. 'ext': 'flv',
  55. 'title': '01-Korean War ( Trouble on the horizon )',
  56. 'description': '\nKorean War 01\nTrouble on the horizon\n전쟁의 먹구름',
  57. 'upload_date': '20080223',
  58. 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
  59. 'duration': 249,
  60. 'view_count': int,
  61. 'comment_count': int,
  62. },
  63. }]
  64. def _real_extract(self, url):
  65. video_id = compat_urllib_parse_unquote(self._match_id(url))
  66. query = compat_urllib_parse.urlencode({'vid': video_id})
  67. movie_data = self._download_json(
  68. 'http://videofarm.daum.net/controller/api/closed/v1_2/IntegratedMovieData.json?' + query,
  69. video_id, 'Downloading video formats info')
  70. # For urls like http://m.tvpot.daum.net/v/65139429, where the video_id is really a clipid
  71. if not movie_data.get('output_list', {}).get('output_list') and re.match(r'^\d+$', video_id):
  72. return self.url_result('http://tvpot.daum.net/clip/ClipView.do?clipid=%s' % video_id)
  73. info = self._download_xml(
  74. 'http://tvpot.daum.net/clip/ClipInfoXml.do?' + query, video_id,
  75. 'Downloading video info')
  76. formats = []
  77. for format_el in movie_data['output_list']['output_list']:
  78. profile = format_el['profile']
  79. format_query = compat_urllib_parse.urlencode({
  80. 'vid': video_id,
  81. 'profile': profile,
  82. })
  83. url_doc = self._download_xml(
  84. 'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query,
  85. video_id, note='Downloading video data for %s format' % profile)
  86. format_url = url_doc.find('result/url').text
  87. formats.append({
  88. 'url': format_url,
  89. 'format_id': profile,
  90. 'width': int_or_none(format_el.get('width')),
  91. 'height': int_or_none(format_el.get('height')),
  92. 'filesize': int_or_none(format_el.get('filesize')),
  93. })
  94. self._sort_formats(formats)
  95. return {
  96. 'id': video_id,
  97. 'title': info.find('TITLE').text,
  98. 'formats': formats,
  99. 'thumbnail': xpath_text(info, 'THUMB_URL'),
  100. 'description': xpath_text(info, 'CONTENTS'),
  101. 'duration': int_or_none(xpath_text(info, 'DURATION')),
  102. 'upload_date': info.find('REGDTTM').text[:8],
  103. 'view_count': str_to_int(xpath_text(info, 'PLAY_CNT')),
  104. 'comment_count': str_to_int(xpath_text(info, 'COMMENT_CNT')),
  105. }
  106. class DaumClipIE(InfoExtractor):
  107. _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:clip/ClipView.(?:do|tv)|mypot/View.do)\?.*?clipid=(?P<id>\d+)'
  108. IE_NAME = 'daum.net:clip'
  109. _URL_TEMPLATE = 'http://tvpot.daum.net/clip/ClipView.do?clipid=%s'
  110. _TESTS = [{
  111. 'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
  112. 'info_dict': {
  113. 'id': '52554690',
  114. 'ext': 'mp4',
  115. 'title': 'DOTA 2GETHER 시즌2 6회 - 2부',
  116. 'description': 'DOTA 2GETHER 시즌2 6회 - 2부',
  117. 'upload_date': '20130831',
  118. 'thumbnail': 're:^https?://.*\.(?:jpg|png)',
  119. 'duration': 3868,
  120. 'view_count': int,
  121. },
  122. }, {
  123. 'url': 'http://m.tvpot.daum.net/clip/ClipView.tv?clipid=54999425',
  124. 'only_matching': True,
  125. }]
  126. @classmethod
  127. def suitable(cls, url):
  128. return False if DaumPlaylistIE.suitable(url) or DaumUserIE.suitable(url) else super(DaumClipIE, cls).suitable(url)
  129. def _real_extract(self, url):
  130. video_id = self._match_id(url)
  131. clip_info = self._download_json(
  132. 'http://tvpot.daum.net/mypot/json/GetClipInfo.do?clipid=%s' % video_id,
  133. video_id, 'Downloading clip info')['clip_bean']
  134. return {
  135. '_type': 'url_transparent',
  136. 'id': video_id,
  137. 'url': 'http://tvpot.daum.net/v/%s' % clip_info['vid'],
  138. 'title': unescapeHTML(clip_info['title']),
  139. 'thumbnail': clip_info.get('thumb_url'),
  140. 'description': clip_info.get('contents'),
  141. 'duration': int_or_none(clip_info.get('duration')),
  142. 'upload_date': clip_info.get('up_date')[:8],
  143. 'view_count': int_or_none(clip_info.get('play_count')),
  144. 'ie_key': 'Daum',
  145. }
  146. class DaumListIE(InfoExtractor):
  147. def _get_entries(self, list_id, list_id_type):
  148. name = None
  149. entries = []
  150. for pagenum in itertools.count(1):
  151. list_info = self._download_json(
  152. 'http://tvpot.daum.net/mypot/json/GetClipInfo.do?size=48&init=true&order=date&page=%d&%s=%s' % (
  153. pagenum, list_id_type, list_id), list_id, 'Downloading list info - %s' % pagenum)
  154. entries.extend([
  155. self.url_result(
  156. 'http://tvpot.daum.net/v/%s' % clip['vid'])
  157. for clip in list_info['clip_list']
  158. ])
  159. if not name:
  160. name = list_info.get('playlist_bean', {}).get('name') or \
  161. list_info.get('potInfo', {}).get('name')
  162. if not list_info.get('has_more'):
  163. break
  164. return name, entries
  165. def _check_clip(self, url, list_id):
  166. query_dict = compat_parse_qs(compat_urlparse.urlparse(url).query)
  167. if 'clipid' in query_dict:
  168. clip_id = query_dict['clipid'][0]
  169. if self._downloader.params.get('noplaylist'):
  170. self.to_screen('Downloading just video %s because of --no-playlist' % clip_id)
  171. return self.url_result(DaumClipIE._URL_TEMPLATE % clip_id, 'DaumClip')
  172. else:
  173. self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % list_id)
  174. class DaumPlaylistIE(DaumListIE):
  175. _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/mypot/(?:View\.do|Top\.tv)\?.*?playlistid=(?P<id>[0-9]+)'
  176. IE_NAME = 'daum.net:playlist'
  177. _URL_TEMPLATE = 'http://tvpot.daum.net/mypot/View.do?playlistid=%s'
  178. _TESTS = [{
  179. 'note': 'Playlist url with clipid',
  180. 'url': 'http://tvpot.daum.net/mypot/View.do?playlistid=6213966&clipid=73806844',
  181. 'info_dict': {
  182. 'id': '6213966',
  183. 'title': 'Woorissica Official',
  184. },
  185. 'playlist_mincount': 181
  186. }, {
  187. 'note': 'Playlist url with clipid - noplaylist',
  188. 'url': 'http://tvpot.daum.net/mypot/View.do?playlistid=6213966&clipid=73806844',
  189. 'info_dict': {
  190. 'id': '73806844',
  191. 'ext': 'mp4',
  192. 'title': '151017 Airport',
  193. 'upload_date': '20160117',
  194. },
  195. 'params': {
  196. 'noplaylist': True,
  197. 'skip_download': True,
  198. }
  199. }]
  200. @classmethod
  201. def suitable(cls, url):
  202. return False if DaumUserIE.suitable(url) else super(DaumPlaylistIE, cls).suitable(url)
  203. def _real_extract(self, url):
  204. list_id = self._match_id(url)
  205. clip_result = self._check_clip(url, list_id)
  206. if clip_result:
  207. return clip_result
  208. name, entries = self._get_entries(list_id, 'playlistid')
  209. return self.playlist_result(entries, list_id, name)
  210. class DaumUserIE(DaumListIE):
  211. _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/mypot/(?:View|Top)\.(?:do|tv)\?.*?ownerid=(?P<id>[0-9a-zA-Z]+)'
  212. IE_NAME = 'daum.net:user'
  213. _TESTS = [{
  214. 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0',
  215. 'info_dict': {
  216. 'id': 'o2scDLIVbHc0',
  217. 'title': '마이 리틀 텔레비전',
  218. },
  219. 'playlist_mincount': 213
  220. }, {
  221. 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0&clipid=73801156',
  222. 'info_dict': {
  223. 'id': '73801156',
  224. 'ext': 'mp4',
  225. 'title': '[미공개] 김구라, 오만석이 부릅니다 \'오케피\' - 마이 리틀 텔레비전 20160116',
  226. 'upload_date': '20160117',
  227. 'description': 'md5:5e91d2d6747f53575badd24bd62b9f36'
  228. },
  229. 'params': {
  230. 'noplaylist': True,
  231. 'skip_download': True,
  232. }
  233. }, {
  234. 'note': 'Playlist url has ownerid and playlistid, playlistid takes precedence',
  235. 'url': 'http://tvpot.daum.net/mypot/View.do?ownerid=o2scDLIVbHc0&playlistid=6196631',
  236. 'info_dict': {
  237. 'id': '6196631',
  238. 'title': '마이 리틀 텔레비전 - 20160109',
  239. },
  240. 'playlist_count': 11
  241. }, {
  242. 'url': 'http://tvpot.daum.net/mypot/Top.do?ownerid=o2scDLIVbHc0',
  243. 'only_matching': True,
  244. }, {
  245. 'url': 'http://m.tvpot.daum.net/mypot/Top.tv?ownerid=45x1okb1If50&playlistid=3569733',
  246. 'only_matching': True,
  247. }]
  248. def _real_extract(self, url):
  249. list_id = self._match_id(url)
  250. clip_result = self._check_clip(url, list_id)
  251. if clip_result:
  252. return clip_result
  253. query_dict = compat_parse_qs(compat_urlparse.urlparse(url).query)
  254. if 'playlistid' in query_dict:
  255. playlist_id = query_dict['playlistid'][0]
  256. return self.url_result(DaumPlaylistIE._URL_TEMPLATE % playlist_id, 'DaumPlaylist')
  257. name, entries = self._get_entries(list_id, 'ownerid')
  258. return self.playlist_result(entries, list_id, name)