]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/thechive.py
[escapist] Extract duration
[youtube-dl.git] / youtube_dl / extractor / thechive.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import unified_strdate
7
8
9
10 class TheChiveIE(InfoExtractor):
11     _VALID_URL = r'http://(www\.)?thechive\.com/[^/]+/[^/]+/[^/]+/(?P<video_id>[A-Za-z\-]+)'
12     _TEST = {
13         'url': "http://thechive.com/2015/02/20/so-thats-what-a-set-of-redneck-bagpipes-sound-like-video/",
14         'md5': "366710dda77cfa727bdef3523ba8466f",
15         'info_dict': {
16             'id': "so-thats-what-a-set-of-redneck-bagpipes-sound-like-video",
17             'title': "So that's what a set of redneck bagpipes sound like... (Video)",
18             'description': "Okay that was pretty good. Now play Freebird!...",
19             'thumbnail': "https://thechive.files.wordpress.com/2015/02/0_07dghz0w-thumbnail2.jpg",
20             'author': "Ben",
21             'upload_date': "20150220",
22             'ext': "mp4"
23         }
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         video_id = mobj.group('video_id')
29         webpage = self._download_webpage(url, video_id)
30
31         title = self._og_search_title(webpage)
32         description = self._html_search_regex(r'(?s)<meta name="description" content="(.*?)" />', webpage, 'description')
33         thumbnail = self._og_search_thumbnail(webpage)
34         author = self._html_search_regex(
35             r'(?s)itemprop="author">(.+?)</span>', webpage, 'author', fatal=False).capitalize() 
36         upload_date = unified_strdate(self._html_search_regex(
37             r'(?s)itemprop="datePublished" datetime="(.+?)">', webpage, 'upload_date', fatal=False))
38
39         # Adapted from extractor/musicvault.py
40         VIDEO_URL_TEMPLATE = 'http://cdnapi.kaltura.com/p/%(uid)s/sp/%(wid)s/playManifest/entryId/%(entry_id)s/format/url/protocol/http'
41
42         kaltura_id = self._search_regex(
43             r'entry_id=([^"]+)',
44             webpage, 'kaltura ID')
45         video_url = VIDEO_URL_TEMPLATE % {
46             'entry_id': kaltura_id,
47             'wid': self._search_regex(r'partner_id/([0-9]+)\?', webpage, 'wid'),
48             'uid': self._search_regex(r'uiconf_id/([0-9]+)/', webpage, 'uid'),
49         }
50
51         return {
52             'url': video_url,
53             'id': video_id,
54             'title': title,
55             'description': description,
56             'thumbnail': thumbnail,
57             'author': author,
58             'upload_date': upload_date,
59             'ext': 'mp4'
60         }