]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/jove.py
[jove] Add new extractor. Closes #3177
[yt-dlp.git] / youtube_dl / extractor / jove.py
CommitLineData
a229909f
NJ
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5from datetime import datetime
6
7from .common import InfoExtractor
8from ..utils import determine_ext, ExtractorError
9
10
11class JoveIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?jove\.com/video/(?P<id>[0-9]+)'
13 _CHAPTERS_URL = 'http://www.jove.com/video-chapters?videoid={video_id:}'
14 _TEST = {
15 'url': 'http://www.jove.com/video/2744/electrode-positioning-montage-transcranial-direct-current',
16 'md5': '93723888d82dbd6ba8b3d7d0cd65dd2b',
17 'info_dict': {
18 'id': '2744',
19 'ext': 'mp4',
20 'title': 'Electrode Positioning and Montage in Transcranial Direct Current Stimulation',
21 'description': 'Transcranial direct current stimulation (tDCS) is an established technique to modulate cortical excitability1,2. It has been ...',
22 'thumbnail': 're:^https?://.*\.png$',
23 'upload_date': '20110523',
24 }
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30
31 webpage = self._download_webpage(url, video_id)
32 title = self._html_search_meta('citation_title', webpage, 'title')
33 thumbnail = self._og_search_thumbnail(webpage)
34 description = self._html_search_meta(
35 'description', webpage, 'description', fatal=False)
36 publish_date = self._html_search_meta(
37 'citation_publication_date', webpage, 'publish date', fatal=False)
38 if publish_date:
39 publish_date = datetime.strptime(publish_date,
40 '%Y/%m/%d').strftime('%Y%m%d')
41
42 # Not the same as video_id.
43 chapters_id = self._html_search_regex(
44 r'/video-chapters\?videoid=([0-9]+)', webpage, 'chapters id')
45 chapters_xml = self._download_xml(
46 self._CHAPTERS_URL.format(video_id=chapters_id),
47 video_id, note='Downloading chapter XML',
48 errnote='Failed to download chapter XML'
49 )
50 video_url = chapters_xml.attrib.get('video')
51 if not video_url:
52 raise ExtractorError('Failed to get the video URL')
53
54 ext = determine_ext(video_url)
55
56 return {
57 'id': video_id,
58 'title': title,
59 'url': video_url,
60 'ext': ext,
61 'thumbnail': thumbnail,
62 'description': description,
63 'upload_date': publish_date,
64 }