5 from .common import InfoExtractor
6 from .subtitles import SubtitlesInfoExtractor
11 get_element_by_attribute,
19 class DailymotionBaseInfoExtractor(InfoExtractor):
21 def _build_request(url):
22 """Build a request with the family filter disabled"""
23 request = compat_urllib_request.Request(url)
24 request.add_header('Cookie', 'family_filter=off')
25 request.add_header('Cookie', 'ff=off')
28 class DailymotionIE(DailymotionBaseInfoExtractor, SubtitlesInfoExtractor):
29 """Information Extractor for Dailymotion"""
31 _VALID_URL = r'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/(?:embed/)?video/([^/]+)'
32 IE_NAME = u'dailymotion'
35 (u'stream_h264_ld_url', u'ld'),
36 (u'stream_h264_url', u'standard'),
37 (u'stream_h264_hq_url', u'hq'),
38 (u'stream_h264_hd_url', u'hd'),
39 (u'stream_h264_hd1080_url', u'hd180'),
44 u'url': u'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech',
45 u'file': u'x33vw9.mp4',
46 u'md5': u'392c4b85a60a90dc4792da41ce3144eb',
48 u"uploader": u"Amphora Alex and Van .",
49 u"title": u"Tutoriel de Youtubeur\"DL DES VIDEO DE YOUTUBE\""
54 u'url': u'http://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musi',
55 u'file': u'USUV71301934.mp4',
57 u'title': u'Roar (Official)',
58 u'uploader': u'Katy Perry',
59 u'upload_date': u'20130905',
62 u'skip_download': True,
64 u'skip': u'VEVO is only available in some countries',
66 # age-restricted video
68 u'url': u'http://www.dailymotion.com/video/xyh2zz_leanna-decker-cyber-girl-of-the-year-desires-nude-playboy-plus_redband',
69 u'file': u'xyh2zz.mp4',
70 u'md5': u'0d667a7b9cebecc3c89ee93099c4159d',
72 u'title': 'Leanna Decker - Cyber Girl Of The Year Desires Nude [Playboy Plus]',
73 u'uploader': 'HotWaves1012',
80 def _real_extract(self, url):
81 # Extract id and simplified title from URL
82 mobj = re.match(self._VALID_URL, url)
84 video_id = mobj.group(1).split('_')[0].split('?')[0]
86 url = 'http://www.dailymotion.com/video/%s' % video_id
88 # Retrieve video webpage to extract further information
89 request = self._build_request(url)
90 webpage = self._download_webpage(request, video_id)
92 # Extract URL, uploader and title from webpage
93 self.report_extraction(video_id)
95 # It may just embed a vevo video:
97 r'<link rel="video_src" href="[^"]*?vevo.com[^"]*?videoId=(?P<id>[\w]*)',
99 if m_vevo is not None:
100 vevo_id = m_vevo.group('id')
101 self.to_screen(u'Vevo video detected: %s' % vevo_id)
102 return self.url_result(u'vevo:%s' % vevo_id, ie='Vevo')
104 video_uploader = self._search_regex([r'(?im)<span class="owner[^\"]+?">[^<]+?<a [^>]+?>([^<]+?)</a>',
105 # Looking for official user
106 r'<(?:span|a) .*?rel="author".*?>([^<]+?)</'],
107 webpage, 'video uploader', fatal=False)
108 age_limit = self._rta_search(webpage)
110 video_upload_date = None
111 mobj = re.search(r'<div class="[^"]*uploaded_cont[^"]*" title="[^"]*">([0-9]{2})-([0-9]{2})-([0-9]{4})</div>', webpage)
113 video_upload_date = mobj.group(3) + mobj.group(2) + mobj.group(1)
115 embed_url = 'http://www.dailymotion.com/embed/video/%s' % video_id
116 embed_page = self._download_webpage(embed_url, video_id,
117 u'Downloading embed page')
118 info = self._search_regex(r'var info = ({.*?}),$', embed_page,
119 'video info', flags=re.MULTILINE)
120 info = json.loads(info)
121 if info.get('error') is not None:
122 msg = 'Couldn\'t get video, Dailymotion says: %s' % info['error']['title']
123 raise ExtractorError(msg, expected=True)
126 for (key, format_id) in self._FORMATS:
127 video_url = info.get(key)
128 if video_url is not None:
129 m_size = re.search(r'H264-(\d+)x(\d+)', video_url)
130 if m_size is not None:
131 width, height = m_size.group(1), m_size.group(2)
133 width, height = None, None
137 'format_id': format_id,
142 raise ExtractorError(u'Unable to extract video URL')
145 video_subtitles = self.extract_subtitles(video_id, webpage)
146 if self._downloader.params.get('listsubtitles', False):
147 self._list_available_subtitles(video_id, webpage)
150 view_count = str_to_int(self._search_regex(
151 r'video_views_value[^>]+>([\d\.,]+)<', webpage, u'view count'))
156 'uploader': video_uploader,
157 'upload_date': video_upload_date,
158 'title': self._og_search_title(webpage),
159 'subtitles': video_subtitles,
160 'thumbnail': info['thumbnail_url'],
161 'age_limit': age_limit,
162 'view_count': view_count,
165 def _get_available_subtitles(self, video_id, webpage):
167 sub_list = self._download_webpage(
168 'https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id,
169 video_id, note=False)
170 except ExtractorError as err:
171 self._downloader.report_warning(u'unable to download video subtitles: %s' % compat_str(err))
173 info = json.loads(sub_list)
174 if (info['total'] > 0):
175 sub_lang_list = dict((l['language'], l['url']) for l in info['list'])
177 self._downloader.report_warning(u'video doesn\'t have subtitles')
181 class DailymotionPlaylistIE(DailymotionBaseInfoExtractor):
182 IE_NAME = u'dailymotion:playlist'
183 _VALID_URL = r'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
184 _MORE_PAGES_INDICATOR = r'<div class="next">.*?<a.*?href="/playlist/.+?".*?>.*?</a>.*?</div>'
185 _PAGE_TEMPLATE = 'https://www.dailymotion.com/playlist/%s/%s'
187 def _extract_entries(self, id):
189 for pagenum in itertools.count(1):
190 request = self._build_request(self._PAGE_TEMPLATE % (id, pagenum))
191 webpage = self._download_webpage(request,
192 id, u'Downloading page %s' % pagenum)
194 playlist_el = get_element_by_attribute(u'class', u'row video_list', webpage)
195 video_ids.extend(re.findall(r'data-id="(.+?)"', playlist_el))
197 if re.search(self._MORE_PAGES_INDICATOR, webpage, re.DOTALL) is None:
199 return [self.url_result('http://www.dailymotion.com/video/%s' % video_id, 'Dailymotion')
200 for video_id in orderedSet(video_ids)]
202 def _real_extract(self, url):
203 mobj = re.match(self._VALID_URL, url)
204 playlist_id = mobj.group('id')
205 webpage = self._download_webpage(url, playlist_id)
207 return {'_type': 'playlist',
209 'title': get_element_by_id(u'playlist_name', webpage),
210 'entries': self._extract_entries(playlist_id),
214 class DailymotionUserIE(DailymotionPlaylistIE):
215 IE_NAME = u'dailymotion:user'
216 _VALID_URL = r'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/user/(?P<user>[^/]+)'
217 _MORE_PAGES_INDICATOR = r'<div class="next">.*?<a.*?href="/user/.+?".*?>.*?</a>.*?</div>'
218 _PAGE_TEMPLATE = 'http://www.dailymotion.com/user/%s/%s'
220 def _real_extract(self, url):
221 mobj = re.match(self._VALID_URL, url)
222 user = mobj.group('user')
223 webpage = self._download_webpage(url, user)
224 full_user = self._html_search_regex(
225 r'<a class="label" href="/%s".*?>(.*?)</' % re.escape(user),
226 webpage, u'user', flags=re.DOTALL)
232 'entries': self._extract_entries(user),