From cf2b0fe00e25c40ea591524892b530a1b2697cf9 Mon Sep 17 00:00:00 2001 From: FA Date: Thu, 25 Apr 2019 13:07:14 -0700 Subject: [PATCH] [earthcams] Add new extractor per #19293 --- youtube_dl/extractor/earthcams.py | 49 ++++++++++++++++++++++++++++++ youtube_dl/extractor/extractors.py | 1 + 2 files changed, 50 insertions(+) create mode 100644 youtube_dl/extractor/earthcams.py diff --git a/youtube_dl/extractor/earthcams.py b/youtube_dl/extractor/earthcams.py new file mode 100644 index 000000000..31a893de8 --- /dev/null +++ b/youtube_dl/extractor/earthcams.py @@ -0,0 +1,49 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor +from ..utils import ( + urljoin, +) + + +class EarthCamsIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?earthcam\.com/.*?cam=(?P\w+)' + _TEST = { + 'url': 'https://www.earthcam.com/usa/newyork/timessquare/?cam=tsrobo1', + 'info_dict': { + 'id': 'tsrobo1', + 'ext': 'mp4', + 'title': 'Times Square, NYC', + 'description': 'EarthCam brings you an HD, panoramic view of Times Square looking up, down, and across 7th Avenue and Broadway. See why Times Square is called the "Crossroads of the World!"', + 'view_count': int, + 'is_live': True, + 'thumbnail': r're:^https?://.*\.jpg$', + }, + } + + 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_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"] + 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, + 'view_count': view_count, + 'is_live': True, + 'thumbnail': thumbnail, + } diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 0e3ccb82d..55bc96d79 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -313,6 +313,7 @@ from .dw import ( DWArticleIE, ) from .eagleplatform import EaglePlatformIE +from .earthcams import EarthCamsIE from .ebaumsworld import EbaumsWorldIE from .echomsk import EchoMskIE from .egghead import (