diff --git a/youtube_dl/extractor/earthcams.py b/youtube_dl/extractor/earthcams.py index 31a893de8..574e11516 100644 --- a/youtube_dl/extractor/earthcams.py +++ b/youtube_dl/extractor/earthcams.py @@ -4,6 +4,9 @@ from __future__ import unicode_literals from .common import InfoExtractor from ..utils import ( urljoin, + int_or_none, + url_or_none, + try_get, ) @@ -25,25 +28,23 @@ class EarthCamsIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) - - json_str = self._search_regex(r'var\sjson_base\s*=\s*(?P{.*});', webpage, 'jstr') + json_str = self._search_regex(r'var\s+json_base\s*=\s*(?P{\s*"cam"\s*:\s*{.*}.*});', webpage, 'jstr') json_base = self._parse_json(json_str, video_id) - - title = json_base["cam"][video_id]["long_title"] - description = json_base["cam"][video_id]["description"] - thumbnail = json_base["cam"][video_id]["thumbimage"] - view_count = int(json_base["cam"][video_id]["streamviews"]) - - domain = json_base["cam"][video_id]["html5_streamingdomain"] - path = json_base["cam"][video_id]["html5_streampath"] + video_info = try_get(json_base, lambda x: x['cam'][video_id], dict) or {} + title = video_info.get("long_title") + description = video_info.get("description") + thumbnail = video_info.get("thumbimage") + view_count = int_or_none(video_info.get("streamviews")) + domain = video_info.get("html5_streamingdomain") + path = video_info.get("html5_streampath") m3u8_url = urljoin(domain, path) return { 'id': video_id, 'formats': self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', 'm3u8_native'), - 'title': title, - 'description': description, + 'title': title or self._og_search_title(webpage), + 'description': description or self._og_search_description(webpage), 'view_count': view_count, 'is_live': True, - 'thumbnail': thumbnail, + 'thumbnail': url_or_none(thumbnail), }