]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ellentv.py
debian/control: Add recommends on aria2 | wget | curl to use external downloaders.
[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 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-7jqrsr18/',
17 'md5': 'e4af06f3bf0d5f471921a18db5764642',
18 'info_dict': {
19 'id': '0-7jqrsr18',
20 'ext': 'mp4',
21 'title': 'What\'s Wrong with These Photos? A Whole Lot',
22 'description': 'md5:35f152dc66b587cf13e6d2cf4fa467f6',
23 'timestamp': 1406876400,
24 'upload_date': '20140801',
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 video_url = self._html_search_meta('VideoURL', webpage, 'url')
44 title = self._og_search_title(webpage, default=None) or self._search_regex(
45 r'pageName\s*=\s*"([^"]+)"', webpage, 'title')
46 description = self._html_search_meta(
47 'description', webpage, 'description') or self._og_search_description(webpage)
48 timestamp = parse_iso8601(self._search_regex(
49 r'<span class="publish-date"><time datetime="([^"]+)">',
50 webpage, 'timestamp'))
51
52 return {
53 'id': video_id,
54 'url': video_url,
55 'title': title,
56 'description': description,
57 'timestamp': timestamp,
58 }
59
60
61 class EllenTVClipsIE(InfoExtractor):
62 IE_NAME = 'EllenTV:clips'
63 _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
64 _TEST = {
65 'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
66 'info_dict': {
67 'id': 'meryl-streep-vanessa-hudgens',
68 'title': 'Meryl Streep, Vanessa Hudgens',
69 },
70 'playlist_mincount': 9,
71 }
72
73 def _real_extract(self, url):
74 playlist_id = self._match_id(url)
75
76 webpage = self._download_webpage(url, playlist_id)
77 playlist = self._extract_playlist(webpage)
78
79 return {
80 '_type': 'playlist',
81 'id': playlist_id,
82 'title': self._og_search_title(webpage),
83 'entries': self._extract_entries(playlist)
84 }
85
86 def _extract_playlist(self, webpage):
87 json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
88 try:
89 return json.loads("[{" + json_string + "}]")
90 except ValueError as ve:
91 raise ExtractorError('Failed to download JSON', cause=ve)
92
93 def _extract_entries(self, playlist):
94 return [self.url_result(item['url'], 'EllenTV') for item in playlist]