2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
10 from ..compat
import (
12 compat_urllib_request
,
23 class DailymotionBaseInfoExtractor(InfoExtractor
):
25 def _build_request(url
):
26 """Build a request with the family filter disabled"""
27 request
= compat_urllib_request
.Request(url
)
28 request
.add_header('Cookie', 'family_filter=off; ff=off')
32 class DailymotionIE(DailymotionBaseInfoExtractor
):
33 """Information Extractor for Dailymotion"""
35 _VALID_URL
= r
'(?i)(?:https?://)?(?:(www|touch)\.)?dailymotion\.[a-z]{2,3}/(?:(embed|#)/)?video/(?P<id>[^/?_]+)'
36 IE_NAME
= 'dailymotion'
39 ('stream_h264_ld_url', 'ld'),
40 ('stream_h264_url', 'standard'),
41 ('stream_h264_hq_url', 'hq'),
42 ('stream_h264_hd_url', 'hd'),
43 ('stream_h264_hd1080_url', 'hd180'),
48 'url': 'https://www.dailymotion.com/video/x2iuewm_steam-machine-models-pricing-listed-on-steam-store-ign-news_videogames',
49 'md5': '2137c41a8e78554bb09225b8eb322406',
54 'title': 'Steam Machine Models, Pricing Listed on Steam Store - IGN News',
55 'upload_date': '20150306',
60 'url': 'http://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musi',
62 'title': 'Roar (Official)',
65 'uploader': 'Katy Perry',
66 'upload_date': '20130905',
69 'skip_download': True,
71 'skip': 'VEVO is only available in some countries',
73 # age-restricted video
75 'url': 'http://www.dailymotion.com/video/xyh2zz_leanna-decker-cyber-girl-of-the-year-desires-nude-playboy-plus_redband',
76 'md5': '0d667a7b9cebecc3c89ee93099c4159d',
80 'title': 'Leanna Decker - Cyber Girl Of The Year Desires Nude [Playboy Plus]',
81 'uploader': 'HotWaves1012',
87 def _real_extract(self
, url
):
88 video_id
= self
._match
_id
(url
)
89 url
= 'https://www.dailymotion.com/video/%s' % video_id
91 # Retrieve video webpage to extract further information
92 request
= self
._build
_request
(url
)
93 webpage
= self
._download
_webpage
(request
, video_id
)
95 # Extract URL, uploader and title from webpage
96 self
.report_extraction(video_id
)
98 # It may just embed a vevo video:
100 r
'<link rel="video_src" href="[^"]*?vevo.com[^"]*?video=(?P<id>[\w]*)',
102 if m_vevo
is not None:
103 vevo_id
= m_vevo
.group('id')
104 self
.to_screen('Vevo video detected: %s' % vevo_id
)
105 return self
.url_result('vevo:%s' % vevo_id
, ie
='Vevo')
107 age_limit
= self
._rta
_search
(webpage
)
109 video_upload_date
= None
110 mobj
= re
.search(r
'<meta property="video:release_date" content="([0-9]{4})-([0-9]{2})-([0-9]{2}).+?"/>', webpage
)
112 video_upload_date
= mobj
.group(1) + mobj
.group(2) + mobj
.group(3)
114 embed_url
= 'https://www.dailymotion.com/embed/video/%s' % video_id
115 embed_request
= self
._build
_request
(embed_url
)
116 embed_page
= self
._download
_webpage
(
117 embed_request
, video_id
, '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
)
147 view_count
= str_to_int(self
._search
_regex
(
148 r
'video_views_count[^>]+>\s+([\d\.,]+)',
149 webpage
, 'view count', fatal
=False))
151 title
= self
._og
_search
_title
(webpage
, default
=None)
153 title
= self
._html
_search
_regex
(
154 r
'(?s)<span\s+id="video_title"[^>]*>(.*?)</span>', webpage
,
160 'uploader': info
['owner.screenname'],
161 'upload_date': video_upload_date
,
163 'subtitles': video_subtitles
,
164 'thumbnail': info
['thumbnail_url'],
165 'age_limit': age_limit
,
166 'view_count': view_count
,
169 def _get_subtitles(self
, video_id
, webpage
):
171 sub_list
= self
._download
_webpage
(
172 'https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id
,
173 video_id
, note
=False)
174 except ExtractorError
as err
:
175 self
._downloader
.report_warning('unable to download video subtitles: %s' % compat_str(err
))
177 info
= json
.loads(sub_list
)
178 if (info
['total'] > 0):
179 sub_lang_list
= dict((l
['language'], [{'url': l
['url'], 'ext': 'srt'}]) for l
in info
['list'])
181 self
._downloader
.report_warning('video doesn\'t have subtitles')
185 class DailymotionPlaylistIE(DailymotionBaseInfoExtractor
):
186 IE_NAME
= 'dailymotion:playlist'
187 _VALID_URL
= r
'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
188 _MORE_PAGES_INDICATOR
= r
'(?s)<div class="pages[^"]*">.*?<a\s+class="[^"]*?icon-arrow_right[^"]*?"'
189 _PAGE_TEMPLATE
= 'https://www.dailymotion.com/playlist/%s/%s'
191 'url': 'http://www.dailymotion.com/playlist/xv4bw_nqtv_sport/1#video=xl8v3q',
194 'id': 'xv4bw_nqtv_sport',
196 'playlist_mincount': 20,
199 def _extract_entries(self
, id):
201 for pagenum
in itertools
.count(1):
202 request
= self
._build
_request
(self
._PAGE
_TEMPLATE
% (id, pagenum
))
203 webpage
= self
._download
_webpage
(request
,
204 id, 'Downloading page %s' % pagenum
)
206 video_ids
.extend(re
.findall(r
'data-xid="(.+?)"', webpage
))
208 if re
.search(self
._MORE
_PAGES
_INDICATOR
, webpage
) is None:
210 return [self
.url_result('http://www.dailymotion.com/video/%s' % video_id
, 'Dailymotion')
211 for video_id
in orderedSet(video_ids
)]
213 def _real_extract(self
, url
):
214 mobj
= re
.match(self
._VALID
_URL
, url
)
215 playlist_id
= mobj
.group('id')
216 webpage
= self
._download
_webpage
(url
, playlist_id
)
221 'title': self
._og
_search
_title
(webpage
),
222 'entries': self
._extract
_entries
(playlist_id
),
226 class DailymotionUserIE(DailymotionPlaylistIE
):
227 IE_NAME
= 'dailymotion:user'
228 _VALID_URL
= r
'https?://(?:www\.)?dailymotion\.[a-z]{2,3}/(?:old/)?user/(?P<user>[^/]+)'
229 _PAGE_TEMPLATE
= 'http://www.dailymotion.com/user/%s/%s'
231 'url': 'https://www.dailymotion.com/user/nqtv',
234 'title': 'Rémi Gaillard',
236 'playlist_mincount': 100,
239 def _real_extract(self
, url
):
240 mobj
= re
.match(self
._VALID
_URL
, url
)
241 user
= mobj
.group('user')
242 webpage
= self
._download
_webpage
(url
, user
)
243 full_user
= unescapeHTML(self
._html
_search
_regex
(
244 r
'<a class="nav-image" title="([^"]+)" href="/%s">' % re
.escape(user
),
251 'entries': self
._extract
_entries
(user
),