2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from .subtitles
import SubtitlesInfoExtractor
12 compat_urllib_request
,
21 class DailymotionBaseInfoExtractor(InfoExtractor
):
23 def _build_request(url
):
24 """Build a request with the family filter disabled"""
25 request
= compat_urllib_request
.Request(url
)
26 request
.add_header('Cookie', 'family_filter=off')
27 request
.add_header('Cookie', 'ff=off')
30 class DailymotionIE(DailymotionBaseInfoExtractor
, SubtitlesInfoExtractor
):
31 """Information Extractor for Dailymotion"""
33 _VALID_URL
= r
'(?i)(?:https?://)?(?:(www|touch)\.)?dailymotion\.[a-z]{2,3}/(?:(embed|#)/)?video/(?P<id>[^/?_]+)'
34 IE_NAME
= 'dailymotion'
37 ('stream_h264_ld_url', 'ld'),
38 ('stream_h264_url', 'standard'),
39 ('stream_h264_hq_url', 'hq'),
40 ('stream_h264_hd_url', 'hd'),
41 ('stream_h264_hd1080_url', 'hd180'),
46 'url': 'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech',
47 'md5': '392c4b85a60a90dc4792da41ce3144eb',
51 'uploader': 'Amphora Alex and Van .',
52 'title': 'Tutoriel de Youtubeur"DL DES VIDEO DE YOUTUBE"',
57 'url': 'http://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musi',
59 'title': 'Roar (Official)',
62 'uploader': 'Katy Perry',
63 'upload_date': '20130905',
66 'skip_download': True,
68 'skip': 'VEVO is only available in some countries',
70 # age-restricted video
72 'url': 'http://www.dailymotion.com/video/xyh2zz_leanna-decker-cyber-girl-of-the-year-desires-nude-playboy-plus_redband',
73 'md5': '0d667a7b9cebecc3c89ee93099c4159d',
77 'title': 'Leanna Decker - Cyber Girl Of The Year Desires Nude [Playboy Plus]',
78 'uploader': 'HotWaves1012',
84 def _real_extract(self
, url
):
85 # Extract id and simplified title from URL
86 mobj
= re
.match(self
._VALID
_URL
, url
)
88 video_id
= mobj
.group('id')
90 url
= 'http://www.dailymotion.com/video/%s' % video_id
92 # Retrieve video webpage to extract further information
93 request
= self
._build
_request
(url
)
94 webpage
= self
._download
_webpage
(request
, video_id
)
96 # Extract URL, uploader and title from webpage
97 self
.report_extraction(video_id
)
99 # It may just embed a vevo video:
101 r
'<link rel="video_src" href="[^"]*?vevo.com[^"]*?videoId=(?P<id>[\w]*)',
103 if m_vevo
is not None:
104 vevo_id
= m_vevo
.group('id')
105 self
.to_screen('Vevo video detected: %s' % vevo_id
)
106 return self
.url_result('vevo:%s' % vevo_id
, ie
='Vevo')
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 '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
= map(int_or_none
, (m_size
.group(1), m_size
.group(2)))
133 width
, height
= None, None
137 'format_id': format_id
,
142 raise ExtractorError('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
= self
._search
_regex
(
151 r
'video_views_count[^>]+>\s+([\d\.,]+)', webpage
, 'view count', fatal
=False)
152 if view_count
is not None:
153 view_count
= str_to_int(view_count
)
158 'uploader': info
['owner.screenname'],
159 'upload_date': video_upload_date
,
160 'title': self
._og
_search
_title
(webpage
),
161 'subtitles': video_subtitles
,
162 'thumbnail': info
['thumbnail_url'],
163 'age_limit': age_limit
,
164 'view_count': view_count
,
167 def _get_available_subtitles(self
, video_id
, webpage
):
169 sub_list
= self
._download
_webpage
(
170 'https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id
,
171 video_id
, note
=False)
172 except ExtractorError
as err
:
173 self
._downloader
.report_warning('unable to download video subtitles: %s' % compat_str(err
))
175 info
= json
.loads(sub_list
)
176 if (info
['total'] > 0):
177 sub_lang_list
= dict((l
['language'], l
['url']) for l
in info
['list'])
179 self
._downloader
.report_warning('video doesn\'t have subtitles')
183 class DailymotionPlaylistIE(DailymotionBaseInfoExtractor
):
184 IE_NAME
= 'dailymotion:playlist'
185 _VALID_URL
= r
'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
186 _MORE_PAGES_INDICATOR
= r
'(?s)<div class="pages[^"]*">.*?<a\s+class="[^"]*?icon-arrow_right[^"]*?"'
187 _PAGE_TEMPLATE
= 'https://www.dailymotion.com/playlist/%s/%s'
189 'url': 'http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q',
193 'playlist_mincount': 20,
196 def _extract_entries(self
, id):
198 for pagenum
in itertools
.count(1):
199 request
= self
._build
_request
(self
._PAGE
_TEMPLATE
% (id, pagenum
))
200 webpage
= self
._download
_webpage
(request
,
201 id, 'Downloading page %s' % pagenum
)
203 video_ids
.extend(re
.findall(r
'data-xid="(.+?)"', webpage
))
205 if re
.search(self
._MORE
_PAGES
_INDICATOR
, webpage
) is None:
207 return [self
.url_result('http://www.dailymotion.com/video/%s' % video_id
, 'Dailymotion')
208 for video_id
in orderedSet(video_ids
)]
210 def _real_extract(self
, url
):
211 mobj
= re
.match(self
._VALID
_URL
, url
)
212 playlist_id
= mobj
.group('id')
213 webpage
= self
._download
_webpage
(url
, playlist_id
)
218 'title': self
._og
_search
_title
(webpage
),
219 'entries': self
._extract
_entries
(playlist_id
),
223 class DailymotionUserIE(DailymotionPlaylistIE
):
224 IE_NAME
= 'dailymotion:user'
225 _VALID_URL
= r
'https?://(?:www\.)?dailymotion\.[a-z]{2,3}/user/(?P<user>[^/]+)'
226 _PAGE_TEMPLATE
= 'http://www.dailymotion.com/user/%s/%s'
228 'url': 'https://www.dailymotion.com/user/nqtv',
231 'title': 'RĂ©mi Gaillard',
233 'playlist_mincount': 100,
236 def _real_extract(self
, url
):
237 mobj
= re
.match(self
._VALID
_URL
, url
)
238 user
= mobj
.group('user')
239 webpage
= self
._download
_webpage
(url
, user
)
240 full_user
= unescapeHTML(self
._html
_search
_regex
(
241 r
'<a class="nav-image" title="([^"]+)" href="/%s">' % re
.escape(user
),
248 'entries': self
._extract
_entries
(user
),