]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ellentv.py
Annotate changelog with bug being closed.
[youtubedl] / youtube_dl / extractor / ellentv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .kaltura import KalturaIE
6 from ..utils import NO_DEFAULT
7
8
9 class EllenTVIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?(?:ellentv|ellentube)\.com/videos/(?P<id>[a-z0-9_-]+)'
11 _TESTS = [{
12 'url': 'http://www.ellentv.com/videos/0-ipq1gsai/',
13 'md5': '4294cf98bc165f218aaa0b89e0fd8042',
14 'info_dict': {
15 'id': '0_ipq1gsai',
16 'ext': 'mov',
17 'title': 'Fast Fingers of Fate',
18 'description': 'md5:3539013ddcbfa64b2a6d1b38d910868a',
19 'timestamp': 1428035648,
20 'upload_date': '20150403',
21 'uploader_id': 'batchUser',
22 },
23 }, {
24 # not available via http://widgets.ellentube.com/
25 'url': 'http://www.ellentv.com/videos/1-szkgu2m2/',
26 'info_dict': {
27 'id': '1_szkgu2m2',
28 'ext': 'flv',
29 'title': "Ellen's Amazingly Talented Audience",
30 'description': 'md5:86ff1e376ff0d717d7171590e273f0a5',
31 'timestamp': 1255140900,
32 'upload_date': '20091010',
33 'uploader_id': 'ellenkaltura@gmail.com',
34 },
35 'params': {
36 'skip_download': True,
37 },
38 }]
39
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
42
43 URLS = ('http://widgets.ellentube.com/videos/%s' % video_id, url)
44
45 for num, url_ in enumerate(URLS, 1):
46 webpage = self._download_webpage(
47 url_, video_id, fatal=num == len(URLS))
48
49 default = NO_DEFAULT if num == len(URLS) else None
50
51 partner_id = self._search_regex(
52 r"var\s+partnerId\s*=\s*'([^']+)", webpage, 'partner id',
53 default=default)
54
55 kaltura_id = self._search_regex(
56 [r'id="kaltura_player_([^"]+)"',
57 r"_wb_entry_id\s*:\s*'([^']+)",
58 r'data-kaltura-entry-id="([^"]+)'],
59 webpage, 'kaltura id', default=default)
60
61 if partner_id and kaltura_id:
62 break
63
64 return self.url_result('kaltura:%s:%s' % (partner_id, kaltura_id), KalturaIE.ie_key())
65
66
67 class EllenTVClipsIE(InfoExtractor):
68 IE_NAME = 'EllenTV:clips'
69 _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
70 _TEST = {
71 'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
72 'info_dict': {
73 'id': 'meryl-streep-vanessa-hudgens',
74 'title': 'Meryl Streep, Vanessa Hudgens',
75 },
76 'playlist_mincount': 5,
77 }
78
79 def _real_extract(self, url):
80 playlist_id = self._match_id(url)
81
82 webpage = self._download_webpage(url, playlist_id)
83 playlist = self._extract_playlist(webpage, playlist_id)
84
85 return {
86 '_type': 'playlist',
87 'id': playlist_id,
88 'title': self._og_search_title(webpage),
89 'entries': self._extract_entries(playlist)
90 }
91
92 def _extract_playlist(self, webpage, playlist_id):
93 json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
94 return self._parse_json('[{' + json_string + '}]', playlist_id)
95
96 def _extract_entries(self, playlist):
97 return [
98 self.url_result(
99 'kaltura:%s:%s' % (item['kaltura_partner_id'], item['kaltura_entry_id']),
100 KalturaIE.ie_key(), video_id=item['kaltura_entry_id'])
101 for item in playlist]