]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/dailymotion.py
6 from .common
import InfoExtractor
7 from .subtitles
import SubtitlesIE
12 compat_urllib_request
,
14 get_element_by_attribute
,
21 class DailyMotionSubtitlesIE(SubtitlesIE
):
23 def _get_available_subtitles(self
, video_id
):
24 request
= compat_urllib_request
.Request('https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id
)
26 sub_list
= compat_urllib_request
.urlopen(request
).read().decode('utf-8')
27 except (compat_urllib_error
.URLError
, compat_http_client
.HTTPException
, socket
.error
) as err
:
28 self
._downloader
.report_warning(u
'unable to download video subtitles: %s' % compat_str(err
))
30 info
= json
.loads(sub_list
)
31 if (info
['total'] > 0):
32 sub_lang_list
= dict((l
['language'], l
['url']) for l
in info
['list'])
34 self
._downloader
.report_warning(u
'video doesn\'t have subtitles')
37 def _get_subtitle_url(self
, sub_lang
, sub_name
, video_id
, format
):
38 sub_lang_list
= self
._get
_available
_subtitles
(video_id
)
39 return sub_lang_list
[sub_lang
]
41 def _request_automatic_caption(self
, video_id
, webpage
):
42 self
._downloader
.report_warning(u
'Automatic Captions not supported by dailymotion')
46 class DailymotionIE(DailyMotionSubtitlesIE
): #,InfoExtractor):
47 """Information Extractor for Dailymotion"""
49 _VALID_URL
= r
'(?i)(?:https?://)?(?:www\.)?dailymotion\.[a-z]{2,3}/video/([^/]+)'
50 IE_NAME
= u
'dailymotion'
52 u
'url': u
'http://www.dailymotion.com/video/x33vw9_tutoriel-de-youtubeur-dl-des-video_tech',
53 u
'file': u
'x33vw9.mp4',
54 u
'md5': u
'392c4b85a60a90dc4792da41ce3144eb',
56 u
"uploader": u
"Alex and Van .",
57 u
"title": u
"Tutoriel de Youtubeur\"DL DES VIDEO DE YOUTUBE\""
61 def _real_extract(self
, url
):
62 # Extract id and simplified title from URL
63 mobj
= re
.match(self
._VALID
_URL
, url
)
65 video_id
= mobj
.group(1).split('_')[0].split('?')[0]
67 video_extension
= 'mp4'
69 # Retrieve video webpage to extract further information
70 request
= compat_urllib_request
.Request(url
)
71 request
.add_header('Cookie', 'family_filter=off')
72 webpage
= self
._download
_webpage
(request
, video_id
)
74 # Extract URL, uploader and title from webpage
75 self
.report_extraction(video_id
)
77 video_uploader
= self
._search
_regex
([r
'(?im)<span class="owner[^\"]+?">[^<]+?<a [^>]+?>([^<]+?)</a>',
78 # Looking for official user
79 r
'<(?:span|a) .*?rel="author".*?>([^<]+?)</'],
80 webpage
, 'video uploader')
82 video_upload_date
= None
83 mobj
= re
.search(r
'<div class="[^"]*uploaded_cont[^"]*" title="[^"]*">([0-9]{2})-([0-9]{2})-([0-9]{4})</div>', webpage
)
85 video_upload_date
= mobj
.group(3) + mobj
.group(2) + mobj
.group(1)
87 embed_url
= 'http://www.dailymotion.com/embed/video/%s' % video_id
88 embed_page
= self
._download
_webpage
(embed_url
, video_id
,
89 u
'Downloading embed page')
90 info
= self
._search
_regex
(r
'var info = ({.*?}),', embed_page
, 'video info')
91 info
= json
.loads(info
)
93 # TODO: support choosing qualities
95 for key
in ['stream_h264_hd1080_url', 'stream_h264_hd_url',
96 'stream_h264_hq_url', 'stream_h264_url',
97 'stream_h264_ld_url']:
98 if info
.get(key
): # key in info and info[key]:
100 self
.to_screen(u
'%s: Using %s' % (video_id
, key
))
103 raise ExtractorError(u
'Unable to extract video URL')
104 video_url
= info
[max_quality
]
107 video_subtitles
= None
110 if self
._downloader
.params
.get('writesubtitles', False) or self
._downloader
.params
.get('allsubtitles', False):
111 video_subtitles
= self
._extract
_subtitles
(video_id
)
112 elif self
._downloader
.params
.get('writeautomaticsub', False):
113 video_subtitles
= self
._request
_automatic
_caption
(video_id
, video_webpage
)
115 if self
._downloader
.params
.get('listsubtitles', False):
116 self
._list
_available
_subtitles
(video_id
)
119 if 'length_seconds' not in info
:
120 self
._downloader
.report_warning(u
'unable to extract video duration')
123 video_duration
= compat_urllib_parse
.unquote_plus(video_info
['length_seconds'][0])
128 'uploader': video_uploader
,
129 'upload_date': video_upload_date
,
130 'title': self
._og
_search
_title
(webpage
),
131 'ext': video_extension
,
132 'subtitles': video_subtitles
,
133 'thumbnail': info
['thumbnail_url']