]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/ellentv.py
[ellentv] Fix tests
[youtube-dl.git] / 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     parse_iso8601,
10 )
11
12
13 class EllenTVIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?(?:ellentv|ellentube)\.com/videos/(?P<id>[a-z0-9_-]+)'
15     _TEST = {
16         'url': 'http://www.ellentv.com/videos/0-ipq1gsai/',
17         'md5': '8e3c576bf2e9bfff4d76565f56f94c9c',
18         'info_dict': {
19             'id': '0_ipq1gsai',
20             'ext': 'mp4',
21             'title': 'Fast Fingers of Fate',
22             'description': 'md5:587e79fbbd0d73b148bc596d99ce48e6',
23             'timestamp': 1428035648,
24             'upload_date': '20150403',
25             'uploader_id': 'batchUser',
26         }
27     }
28
29     def _real_extract(self, url):
30         video_id = self._match_id(url)
31
32         webpage = self._download_webpage(
33             'http://widgets.ellentube.com/videos/%s' % video_id,
34             video_id)
35
36         partner_id = self._search_regex(
37             r"var\s+partnerId\s*=\s*'([^']+)", webpage, 'partner id')
38
39         kaltura_id = self._search_regex(
40             [r'id="kaltura_player_([^"]+)"',
41              r"_wb_entry_id\s*:\s*'([^']+)",
42              r'data-kaltura-entry-id="([^"]+)'],
43             webpage, 'kaltura id')
44
45         return self.url_result('kaltura:%s:%s' % (partner_id, kaltura_id), 'Kaltura')
46
47
48 class EllenTVClipsIE(InfoExtractor):
49     IE_NAME = 'EllenTV:clips'
50     _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
51     _TEST = {
52         'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
53         'info_dict': {
54             'id': 'meryl-streep-vanessa-hudgens',
55             'title': 'Meryl Streep, Vanessa Hudgens',
56         },
57         'playlist_mincount': 9,
58     }
59
60     def _real_extract(self, url):
61         playlist_id = self._match_id(url)
62
63         webpage = self._download_webpage(url, playlist_id)
64         playlist = self._extract_playlist(webpage)
65
66         return {
67             '_type': 'playlist',
68             'id': playlist_id,
69             'title': self._og_search_title(webpage),
70             'entries': self._extract_entries(playlist)
71         }
72
73     def _extract_playlist(self, webpage):
74         json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
75         try:
76             return json.loads("[{" + json_string + "}]")
77         except ValueError as ve:
78             raise ExtractorError('Failed to download JSON', cause=ve)
79
80     def _extract_entries(self, playlist):
81         return [self.url_result(item['url'], 'EllenTV') for item in playlist]