5 from .common
import InfoExtractor
6 from .subtitles
import SubtitlesInfoExtractor
11 get_element_by_attribute
,
17 class DailymotionBaseInfoExtractor(InfoExtractor
):
19 def _build_request(url
):
20 """Build a request with the family filter disabled"""
21 request
= compat_urllib_request
.Request(url
)
22 request
.add_header('Cookie', 'family_filter=off')
25 class DailymotionIE(DailymotionBaseInfoExtractor
, SubtitlesInfoExtractor
):
26 """Information Extractor for Dailymotion"""
28 _VALID_URL
= r
'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/(?:embed/)?video/([^/]+)'
29 IE_NAME
= u
'dailymotion'
32 u
'url': u
'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech',
33 u
'file': u
'x33vw9.mp4',
34 u
'md5': u
'392c4b85a60a90dc4792da41ce3144eb',
36 u
"uploader": u
"Amphora Alex and Van .",
37 u
"title": u
"Tutoriel de Youtubeur\"DL DES VIDEO DE YOUTUBE\""
42 u
'url': u
'http://www.dailymotion.com/video/x149uew_katy-perry-roar-official_musi',
43 u
'file': u
'USUV71301934.mp4',
45 u
'title': u
'Roar (Official)',
46 u
'uploader': u
'Katy Perry',
47 u
'upload_date': u
'20130905',
50 u
'skip_download': True,
52 u
'skip': u
'VEVO is only available in some countries',
56 def _real_extract(self
, url
):
57 # Extract id and simplified title from URL
58 mobj
= re
.match(self
._VALID
_URL
, url
)
60 video_id
= mobj
.group(1).split('_')[0].split('?')[0]
62 video_extension
= 'mp4'
63 url
= 'http://www.dailymotion.com/video/%s' % video_id
65 # Retrieve video webpage to extract further information
66 request
= self
._build
_request
(url
)
67 webpage
= self
._download
_webpage
(request
, video_id
)
69 # Extract URL, uploader and title from webpage
70 self
.report_extraction(video_id
)
72 # It may just embed a vevo video:
74 r
'<link rel="video_src" href="[^"]*?vevo.com[^"]*?videoId=(?P<id>[\w]*)',
76 if m_vevo
is not None:
77 vevo_id
= m_vevo
.group('id')
78 self
.to_screen(u
'Vevo video detected: %s' % vevo_id
)
79 return self
.url_result(u
'vevo:%s' % vevo_id
, ie
='Vevo')
81 video_uploader
= self
._search
_regex
([r
'(?im)<span class="owner[^\"]+?">[^<]+?<a [^>]+?>([^<]+?)</a>',
82 # Looking for official user
83 r
'<(?:span|a) .*?rel="author".*?>([^<]+?)</'],
84 webpage
, 'video uploader')
86 video_upload_date
= None
87 mobj
= re
.search(r
'<div class="[^"]*uploaded_cont[^"]*" title="[^"]*">([0-9]{2})-([0-9]{2})-([0-9]{4})</div>', webpage
)
89 video_upload_date
= mobj
.group(3) + mobj
.group(2) + mobj
.group(1)
91 embed_url
= 'http://www.dailymotion.com/embed/video/%s' % video_id
92 embed_page
= self
._download
_webpage
(embed_url
, video_id
,
93 u
'Downloading embed page')
94 info
= self
._search
_regex
(r
'var info = ({.*?}),$', embed_page
,
95 'video info', flags
=re
.MULTILINE
)
96 info
= json
.loads(info
)
97 if info
.get('error') is not None:
98 msg
= 'Couldn\'t get video, Dailymotion says: %s' % info
['error']['title']
99 raise ExtractorError(msg
, expected
=True)
101 # TODO: support choosing qualities
103 for key
in ['stream_h264_hd1080_url','stream_h264_hd_url',
104 'stream_h264_hq_url','stream_h264_url',
105 'stream_h264_ld_url']:
106 if info
.get(key
):#key in info and info[key]:
108 self
.to_screen(u
'Using %s' % key
)
111 raise ExtractorError(u
'Unable to extract video URL')
112 video_url
= info
[max_quality
]
115 video_subtitles
= self
.extract_subtitles(video_id
)
116 if self
._downloader
.params
.get('listsubtitles', False):
117 self
._list
_available
_subtitles
(video_id
)
123 'uploader': video_uploader
,
124 'upload_date': video_upload_date
,
125 'title': self
._og
_search
_title
(webpage
),
126 'ext': video_extension
,
127 'subtitles': video_subtitles
,
128 'thumbnail': info
['thumbnail_url']
131 def _get_available_subtitles(self
, video_id
):
133 sub_list
= self
._download
_webpage
(
134 'https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id
,
135 video_id
, note
=False)
136 except ExtractorError
as err
:
137 self
._downloader
.report_warning(u
'unable to download video subtitles: %s' % compat_str(err
))
139 info
= json
.loads(sub_list
)
140 if (info
['total'] > 0):
141 sub_lang_list
= dict((l
['language'], l
['url']) for l
in info
['list'])
143 self
._downloader
.report_warning(u
'video doesn\'t have subtitles')
147 class DailymotionPlaylistIE(DailymotionBaseInfoExtractor
):
148 IE_NAME
= u
'dailymotion:playlist'
149 _VALID_URL
= r
'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/playlist/(?P<id>.+?)/'
150 _MORE_PAGES_INDICATOR
= r
'<div class="next">.*?<a.*?href="/playlist/.+?".*?>.*?</a>.*?</div>'
151 _PAGE_TEMPLATE
= 'https://www.dailymotion.com/playlist/%s/%s'
153 def _extract_entries(self
, id):
155 for pagenum
in itertools
.count(1):
156 request
= self
._build
_request
(self
._PAGE
_TEMPLATE
% (id, pagenum
))
157 webpage
= self
._download
_webpage
(request
,
158 id, u
'Downloading page %s' % pagenum
)
160 playlist_el
= get_element_by_attribute(u
'class', u
'video_list', webpage
)
161 video_ids
.extend(re
.findall(r
'data-id="(.+?)" data-ext-id', playlist_el
))
163 if re
.search(self
._MORE
_PAGES
_INDICATOR
, webpage
, re
.DOTALL
) is None:
165 return [self
.url_result('http://www.dailymotion.com/video/%s' % video_id
, 'Dailymotion')
166 for video_id
in video_ids
]
168 def _real_extract(self
, url
):
169 mobj
= re
.match(self
._VALID
_URL
, url
)
170 playlist_id
= mobj
.group('id')
171 webpage
= self
._download
_webpage
(url
, playlist_id
)
173 return {'_type': 'playlist',
175 'title': get_element_by_id(u
'playlist_name', webpage
),
176 'entries': self
._extract
_entries
(playlist_id
),
180 class DailymotionUserIE(DailymotionPlaylistIE
):
181 IE_NAME
= u
'dailymotion:user'
182 _VALID_URL
= r
'(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/user/(?P<user>[^/]+)'
183 _MORE_PAGES_INDICATOR
= r
'<div class="next">.*?<a.*?href="/user/.+?".*?>.*?</a>.*?</div>'
184 _PAGE_TEMPLATE
= 'http://www.dailymotion.com/user/%s/%s'
186 def _real_extract(self
, url
):
187 mobj
= re
.match(self
._VALID
_URL
, url
)
188 user
= mobj
.group('user')
189 webpage
= self
._download
_webpage
(url
, user
)
190 full_user
= self
._html
_search
_regex
(
191 r
'<a class="label" href="/%s".*?>(.*?)</' % re
.escape(user
),
192 webpage
, u
'user', flags
=re
.DOTALL
)
198 'entries': self
._extract
_entries
(user
),