]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/yesjapan.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / yesjapan.py
1 from .common import InfoExtractor
2 from ..networking import HEADRequest
3 from ..utils import get_element_by_attribute, parse_iso8601
4
5
6 class YesJapanIE(InfoExtractor):
7 _VALID_URL = r'https?://(?:www\.)?yesjapan\.com/video/(?P<slug>[A-Za-z0-9\-]*)_(?P<id>[A-Za-z0-9]+)\.html'
8 _TEST = {
9 'url': 'http://www.yesjapan.com/video/japanese-in-5-20-wa-and-ga-particle-usages_726497834.html',
10 'md5': 'f0be416314e5be21a12b499b330c21cf',
11 'info_dict': {
12 'id': '726497834',
13 'title': 'Japanese in 5! #20 - WA And GA Particle Usages',
14 'description': 'This should clear up some issues most students of Japanese encounter with WA and GA....',
15 'ext': 'mp4',
16 'timestamp': 1416391590,
17 'upload_date': '20141119',
18 'thumbnail': r're:^https?://.*\.jpg$',
19 }
20 }
21
22 def _real_extract(self, url):
23 video_id = self._match_id(url)
24
25 webpage = self._download_webpage(url, video_id)
26 title = self._og_search_title(webpage)
27 video_url = self._og_search_video_url(webpage)
28 description = self._og_search_description(webpage)
29 thumbnail = self._og_search_thumbnail(webpage)
30
31 timestamp = None
32 submit_info = get_element_by_attribute('class', 'pm-submit-data', webpage)
33 if submit_info:
34 timestamp = parse_iso8601(self._search_regex(
35 r'datetime="([^"]+)"', submit_info, 'upload date', fatal=False, default=None))
36
37 # attempt to resolve the final URL in order to get a proper extension
38 redirect_req = HEADRequest(video_url)
39 req = self._request_webpage(
40 redirect_req, video_id, note='Resolving final URL', errnote='Could not resolve final URL', fatal=False)
41 if req:
42 video_url = req.url
43
44 formats = [{
45 'format_id': 'sd',
46 'url': video_url,
47 }]
48
49 return {
50 'id': video_id,
51 'title': title,
52 'formats': formats,
53 'description': description,
54 'timestamp': timestamp,
55 'thumbnail': thumbnail,
56 }