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