]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/abcotvs.py
Annotate changelog with bug being closed.
[youtubedl] / youtube_dl / extractor / abcotvs.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 int_or_none,
9 parse_iso8601,
10 )
11
12
13 class ABCOTVSIE(InfoExtractor):
14 IE_NAME = 'abcotvs'
15 IE_DESC = 'ABC Owned Television Stations'
16 _VALID_URL = r'https?://(?:abc(?:7(?:news|ny|chicago)?|11|13|30)|6abc)\.com(?:/[^/]+/(?P<display_id>[^/]+))?/(?P<id>\d+)'
17 _TESTS = [
18 {
19 'url': 'http://abc7news.com/entertainment/east-bay-museum-celebrates-vintage-synthesizers/472581/',
20 'info_dict': {
21 'id': '472581',
22 'display_id': 'east-bay-museum-celebrates-vintage-synthesizers',
23 'ext': 'mp4',
24 'title': 'East Bay museum celebrates vintage synthesizers',
25 'description': 'md5:24ed2bd527096ec2a5c67b9d5a9005f3',
26 'thumbnail': r're:^https?://.*\.jpg$',
27 'timestamp': 1421123075,
28 'upload_date': '20150113',
29 'uploader': 'Jonathan Bloom',
30 },
31 'params': {
32 # m3u8 download
33 'skip_download': True,
34 },
35 },
36 {
37 'url': 'http://abc7news.com/472581',
38 'only_matching': True,
39 },
40 ]
41
42 def _real_extract(self, url):
43 mobj = re.match(self._VALID_URL, url)
44 video_id = mobj.group('id')
45 display_id = mobj.group('display_id') or video_id
46
47 webpage = self._download_webpage(url, display_id)
48
49 m3u8 = self._html_search_meta(
50 'contentURL', webpage, 'm3u8 url', fatal=True).split('?')[0]
51
52 formats = self._extract_m3u8_formats(m3u8, display_id, 'mp4')
53 self._sort_formats(formats)
54
55 title = self._og_search_title(webpage).strip()
56 description = self._og_search_description(webpage).strip()
57 thumbnail = self._og_search_thumbnail(webpage)
58 timestamp = parse_iso8601(self._search_regex(
59 r'<div class="meta">\s*<time class="timeago" datetime="([^"]+)">',
60 webpage, 'upload date', fatal=False))
61 uploader = self._search_regex(
62 r'rel="author">([^<]+)</a>',
63 webpage, 'uploader', default=None)
64
65 return {
66 'id': video_id,
67 'display_id': display_id,
68 'title': title,
69 'description': description,
70 'thumbnail': thumbnail,
71 'timestamp': timestamp,
72 'uploader': uploader,
73 'formats': formats,
74 }
75
76
77 class ABCOTVSClipsIE(InfoExtractor):
78 IE_NAME = 'abcotvs:clips'
79 _VALID_URL = r'https?://clips\.abcotvs\.com/(?:[^/]+/)*video/(?P<id>\d+)'
80 _TEST = {
81 'url': 'https://clips.abcotvs.com/kabc/video/214814',
82 'info_dict': {
83 'id': '214814',
84 'ext': 'mp4',
85 'title': 'SpaceX launch pad explosion destroys rocket, satellite',
86 'description': 'md5:9f186e5ad8f490f65409965ee9c7be1b',
87 'upload_date': '20160901',
88 'timestamp': 1472756695,
89 },
90 'params': {
91 # m3u8 download
92 'skip_download': True,
93 },
94 }
95
96 def _real_extract(self, url):
97 video_id = self._match_id(url)
98 video_data = self._download_json('https://clips.abcotvs.com/vogo/video/getByIds?ids=' + video_id, video_id)['results'][0]
99 title = video_data['title']
100 formats = self._extract_m3u8_formats(
101 video_data['videoURL'].split('?')[0], video_id, 'mp4')
102 self._sort_formats(formats)
103
104 return {
105 'id': video_id,
106 'title': title,
107 'description': video_data.get('description'),
108 'thumbnail': video_data.get('thumbnailURL'),
109 'duration': int_or_none(video_data.get('duration')),
110 'timestamp': int_or_none(video_data.get('pubDate')),
111 'formats': formats,
112 }