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