]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/ellentv.py
[SpankBang] Use python2.6 compatible string formatting spec
[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     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     _TESTS = [{
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:686114ced0a032926935e9015ee794ac',
23             'timestamp': 1428033600,
24             'upload_date': '20150403',
25         }
26     }, {
27         'url': 'http://ellentube.com/videos/0-dvzmabd5/',
28         'md5': '98238118eaa2bbdf6ad7f708e3e4f4eb',
29         'info_dict': {
30             'id': '0-dvzmabd5',
31             'ext': 'mp4',
32             'title': '1 year old twin sister makes her brother laugh',
33             'description': '1 year old twin sister makes her brother laugh',
34             'timestamp': 1419542075,
35             'upload_date': '20141225',
36         }
37     }]
38
39     def _real_extract(self, url):
40         video_id = self._match_id(url)
41
42         webpage = self._download_webpage(url, video_id)
43
44         video_url = self._html_search_meta('VideoURL', webpage, 'url', fatal=True)
45         title = self._og_search_title(webpage, default=None) or self._search_regex(
46             r'pageName\s*=\s*"([^"]+)"', webpage, 'title')
47         description = self._html_search_meta(
48             'description', webpage, 'description') or self._og_search_description(webpage)
49         timestamp = parse_iso8601(self._search_regex(
50             r'<span class="publish-date"><time datetime="([^"]+)">',
51             webpage, 'timestamp', fatal=False))
52
53         return {
54             'id': video_id,
55             'url': video_url,
56             'title': title,
57             'description': description,
58             'timestamp': timestamp,
59         }
60
61
62 class EllenTVClipsIE(InfoExtractor):
63     IE_NAME = 'EllenTV:clips'
64     _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
65     _TEST = {
66         'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
67         'info_dict': {
68             'id': 'meryl-streep-vanessa-hudgens',
69             'title': 'Meryl Streep, Vanessa Hudgens',
70         },
71         'playlist_mincount': 9,
72     }
73
74     def _real_extract(self, url):
75         playlist_id = self._match_id(url)
76
77         webpage = self._download_webpage(url, playlist_id)
78         playlist = self._extract_playlist(webpage)
79
80         return {
81             '_type': 'playlist',
82             'id': playlist_id,
83             'title': self._og_search_title(webpage),
84             'entries': self._extract_entries(playlist)
85         }
86
87     def _extract_playlist(self, webpage):
88         json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
89         try:
90             return json.loads("[{" + json_string + "}]")
91         except ValueError as ve:
92             raise ExtractorError('Failed to download JSON', cause=ve)
93
94     def _extract_entries(self, playlist):
95         return [self.url_result(item['url'], 'EllenTV') for item in playlist]