[regiotv] Improve extraction (Closes #7915)
[youtube-dl] / youtube_dl / extractor / animalplanet.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import (
7     parse_duration,
8     parse_iso8601,
9 )
10
11
12 class AnimalPlanetIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:www\.)?animalplanet\.com/([^/]+/)*(?P<id>[^/\?#]+)'
14     _TESTS = [{
15         'url': 'http://www.animalplanet.com/tv-shows/i-shouldnt-be-alive/videos/dog-saves-injured-owner/',
16         'info_dict': {
17             'id': '10608',
18             'ext': 'mp4',
19             'title': 'Dog Saves Injured Owner',
20             'description': 'A world class athlete is put to the test when she falls into a canyon and breaks her hip. Her only companion is her dog, Taz, who is on a mission to save her!',
21             'upload_date': '20100410',
22             'timestamp': 1270857727,
23             'duration': 220,
24         },
25         'params': {
26             # m3u8 download
27             'skip_download': True,
28         }
29     }, {
30         'url': 'http://www.animalplanet.com/longfin-eels-maneaters/',
31         'only_matching': True,
32     }]
33
34     def _real_extract(self, url):
35         display_id = self._match_id(url)
36         webpage = self._download_webpage(url, display_id)
37
38         video_data = self._parse_json(self._search_regex(
39             r'initialVideoData\s*=\s*({.+?});',
40             webpage, 'initialVideoData'), display_id)['playlist'][0]
41
42         return {
43             'id': compat_str(video_data['id']),
44             'display_id': display_id,
45             'title': video_data['title'],
46             'description': video_data.get('description'),
47             'thumbnail': video_data.get('thumbnailURL'),
48             'duration': parse_duration(video_data.get('video_length')),
49             'timestamp': parse_iso8601(video_data.get('publishedDate')),
50             'formats': self._extract_m3u8_formats(
51                 video_data['src'], display_id, 'mp4',
52                 'm3u8_native', m3u8_id='hls')
53         }