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