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