[earthcams] Add new extractor per #19293

This commit is contained in:
FA 2019-04-25 13:19:22 -07:00
parent cf2b0fe00e
commit 7b392e10fb

View File

@ -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<jstr>{.*});', webpage, 'jstr')
json_str = self._search_regex(r'var\s+json_base\s*=\s*(?P<jstr>{\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),
}