]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ellentv.py
Prepare for upload.
[youtubedl] / youtube_dl / extractor / ellentv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import json
6
7 from .common import InfoExtractor
8 from ..utils import (
9 ExtractorError,
10 parse_iso8601,
11 )
12
13
14 class EllenTVIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?ellentv\.com/videos/(?P<id>[a-z0-9_-]+)'
16 _TEST = {
17 'url': 'http://www.ellentv.com/videos/0-7jqrsr18/',
18 'md5': 'e4af06f3bf0d5f471921a18db5764642',
19 'info_dict': {
20 'id': '0-7jqrsr18',
21 'ext': 'mp4',
22 'title': 'What\'s Wrong with These Photos? A Whole Lot',
23 'timestamp': 1406876400,
24 'upload_date': '20140801',
25 }
26 }
27
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('id')
31
32 webpage = self._download_webpage(url, video_id)
33 timestamp = parse_iso8601(self._search_regex(
34 r'<span class="publish-date"><time datetime="([^"]+)">',
35 webpage, 'timestamp'))
36
37 return {
38 'id': video_id,
39 'title': self._og_search_title(webpage),
40 'url': self._html_search_meta('VideoURL', webpage, 'url'),
41 'timestamp': timestamp,
42 }
43
44
45 class EllenTVClipsIE(InfoExtractor):
46 IE_NAME = 'EllenTV:clips'
47 _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
48 _TEST = {
49 'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
50 'info_dict': {
51 'id': 'meryl-streep-vanessa-hudgens',
52 'title': 'Meryl Streep, Vanessa Hudgens',
53 },
54 'playlist_mincount': 9,
55 }
56
57 def _real_extract(self, url):
58 mobj = re.match(self._VALID_URL, url)
59 playlist_id = mobj.group('id')
60
61 webpage = self._download_webpage(url, playlist_id)
62 playlist = self._extract_playlist(webpage)
63
64 return {
65 '_type': 'playlist',
66 'id': playlist_id,
67 'title': self._og_search_title(webpage),
68 'entries': self._extract_entries(playlist)
69 }
70
71 def _extract_playlist(self, webpage):
72 json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
73 try:
74 return json.loads("[{" + json_string + "}]")
75 except ValueError as ve:
76 raise ExtractorError('Failed to download JSON', cause=ve)
77
78 def _extract_entries(self, playlist):
79 return [self.url_result(item['url'], 'EllenTV') for item in playlist]