[daum] Add 'thumbnail' to all _TESTS
[youtube-dl] / youtube_dl / extractor / daum.py
1 # encoding: utf-8
2
3 from __future__ import unicode_literals
4
5 import re
6
7 from .common import InfoExtractor
8 from ..compat import (
9     compat_urllib_parse,
10     compat_urllib_parse_unquote,
11 )
12 from ..utils import (
13     int_or_none,
14     str_to_int,
15     xpath_text,
16 )
17
18
19 class DaumIE(InfoExtractor):
20     _VALID_URL = r'https?://(?:(?:m\.)?tvpot\.daum\.net/v/|videofarm\.daum\.net/controller/player/VodPlayer\.swf\?vid=)(?P<id>[^?#&]+)'
21     IE_NAME = 'daum.net'
22
23     _TESTS = [{
24         'url': 'http://tvpot.daum.net/v/vab4dyeDBysyBssyukBUjBz',
25         'info_dict': {
26             'id': 'vab4dyeDBysyBssyukBUjBz',
27             'ext': 'mp4',
28             'title': '마크 헌트 vs 안토니오 실바',
29             'description': 'Mark Hunt vs Antonio Silva',
30             'upload_date': '20131217',
31             'thumbnail': 're:^https?://.*\.(?:jpg|png)',
32             'duration': 2117,
33             'view_count': int,
34             'comment_count': int,
35         },
36     }, {
37         'url': 'http://m.tvpot.daum.net/v/65139429',
38         'info_dict': {
39             'id': '65139429',
40             'ext': 'mp4',
41             'title': 'md5:a100d65d09cec246d8aa9bde7de45aed',
42             'description': 'md5:79794514261164ff27e36a21ad229fc5',
43             'upload_date': '20150604',
44             'thumbnail': 're:^https?://.*\.(?:jpg|png)',
45             'duration': 154,
46             'view_count': int,
47             'comment_count': int,
48         },
49     }, {
50         'url': 'http://tvpot.daum.net/v/07dXWRka62Y%24',
51         'only_matching': True,
52     }, {
53         'url': 'http://videofarm.daum.net/controller/player/VodPlayer.swf?vid=vwIpVpCQsT8%24&ref=',
54         'info_dict': {
55             'id': 'vwIpVpCQsT8$',
56             'ext': 'flv',
57             'title': '01-Korean War ( Trouble on the horizon )',
58             'description': '\nKorean War 01\nTrouble on the horizon\n전쟁의 먹구름',
59             'upload_date': '20080223',
60             'thumbnail': 're:^https?://.*\.(?:jpg|png)',
61             'duration': 249,
62             'view_count': int,
63             'comment_count': int,
64         },
65     }]
66
67     def _real_extract(self, url):
68         video_id = compat_urllib_parse_unquote(self._match_id(url))
69         query = compat_urllib_parse.urlencode({'vid': video_id})
70         movie_data = self._download_json(
71             'http://videofarm.daum.net/controller/api/closed/v1_2/IntegratedMovieData.json?' + query,
72             video_id, 'Downloading video formats info')
73
74         # For urls like http://m.tvpot.daum.net/v/65139429, where the video_id is really a clipid
75         if not movie_data.get('output_list', {}).get('output_list') and re.match(r'^\d+$', video_id):
76             return self.url_result('http://tvpot.daum.net/clip/ClipView.do?clipid=%s' % video_id)
77
78         info = self._download_xml(
79             'http://tvpot.daum.net/clip/ClipInfoXml.do?' + query, video_id,
80             'Downloading video info')
81
82         formats = []
83         for format_el in movie_data['output_list']['output_list']:
84             profile = format_el['profile']
85             format_query = compat_urllib_parse.urlencode({
86                 'vid': video_id,
87                 'profile': profile,
88             })
89             url_doc = self._download_xml(
90                 'http://videofarm.daum.net/controller/api/open/v1_2/MovieLocation.apixml?' + format_query,
91                 video_id, note='Downloading video data for %s format' % profile)
92             format_url = url_doc.find('result/url').text
93             formats.append({
94                 'url': format_url,
95                 'format_id': profile,
96                 'width': int_or_none(format_el.get('width')),
97                 'height': int_or_none(format_el.get('height')),
98                 'filesize': int_or_none(format_el.get('filesize')),
99             })
100         self._sort_formats(formats)
101
102         return {
103             'id': video_id,
104             'title': info.find('TITLE').text,
105             'formats': formats,
106             'thumbnail': xpath_text(info, 'THUMB_URL'),
107             'description': xpath_text(info, 'CONTENTS'),
108             'duration': int_or_none(xpath_text(info, 'DURATION')),
109             'upload_date': info.find('REGDTTM').text[:8],
110             'view_count': str_to_int(xpath_text(info, 'PLAY_CNT')),
111             'comment_count': str_to_int(xpath_text(info, 'COMMENT_CNT')),
112         }
113
114
115 class DaumClipIE(InfoExtractor):
116     _VALID_URL = r'https?://(?:m\.)?tvpot\.daum\.net/(?:clip/ClipView.(?:do|tv)|mypot/View.do)\?.*?clipid=(?P<id>\d+)'
117     IE_NAME = 'daum.net:clip'
118
119     _TESTS = [{
120         'url': 'http://tvpot.daum.net/clip/ClipView.do?clipid=52554690',
121         'info_dict': {
122             'id': '52554690',
123             'ext': 'mp4',
124             'title': 'DOTA 2GETHER 시즌2 6회 - 2부',
125             'description': 'DOTA 2GETHER 시즌2 6회 - 2부',
126             'upload_date': '20130831',
127             'thumbnail': 're:^https?://.*\.(?:jpg|png)',
128             'duration': 3868,
129             'view_count': int,
130         },
131     }, {
132         'url': 'http://m.tvpot.daum.net/clip/ClipView.tv?clipid=54999425',
133         'only_matching': True,
134     }]
135
136     def _real_extract(self, url):
137         video_id = self._match_id(url)
138         clip_info = self._download_json(
139             'http://tvpot.daum.net/mypot/json/GetClipInfo.do?clipid=%s' % video_id,
140             video_id, 'Downloading clip info')['clip_bean']
141
142         return {
143             '_type': 'url_transparent',
144             'id': video_id,
145             'url': 'http://tvpot.daum.net/v/%s' % clip_info['vid'],
146             'title': clip_info['title'],
147             'thumbnail': clip_info.get('thumb_url'),
148             'description': clip_info.get('contents'),
149             'duration': int_or_none(clip_info.get('duration')),
150             'upload_date': clip_info.get('up_date')[:8],
151             'view_count': int_or_none(clip_info.get('play_count')),
152             'ie_key': 'Daum',
153         }