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