mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-04-29 03:55:53 +00:00
Cleanup extractor
This commit is contained in:
parent
f60713f781
commit
057c5cbbd0
@ -1,12 +1,11 @@
|
|||||||
import datetime as dt
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import ExtractorError
|
from ..utils import ExtractorError
|
||||||
|
from ..utils.traversal import traverse_obj
|
||||||
|
|
||||||
|
|
||||||
class NestIE(InfoExtractor):
|
class NestIE(InfoExtractor):
|
||||||
_VALID_URL = r'^https?://video\.nest\.com/embedded/live/(?P<id>[A-Za-z0-9]+)'
|
_VALID_URL = r'https?://video\.nest\.com/(?:embedded/)?live/(?P<id>\w+)'
|
||||||
_EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//video\.nest\.com/embedded/live/.+)\1']
|
_EMBED_REGEX = [rf'<iframe[^>]+\bsrc=[\'"](?P<url>{_VALID_URL})']
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://video.nest.com/embedded/live/4fvYdSo8AX?autoplay=0',
|
'url': 'https://video.nest.com/embedded/live/4fvYdSo8AX?autoplay=0',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
@ -24,6 +23,9 @@ class NestIE(InfoExtractor):
|
|||||||
# m3u8 download
|
# m3u8 download
|
||||||
'skip_download': True,
|
'skip_download': True,
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
'url': 'https://video.nest.com/live/4fvYdSo8AX',
|
||||||
|
'only_matching': True,
|
||||||
}]
|
}]
|
||||||
_WEBPAGE_TESTS = [{
|
_WEBPAGE_TESTS = [{
|
||||||
'url': 'https://www.pacificblue.biz/noyo-harbor-webcam/',
|
'url': 'https://www.pacificblue.biz/noyo-harbor-webcam/',
|
||||||
@ -46,34 +48,25 @@ class NestIE(InfoExtractor):
|
|||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
now = dt.datetime.now().strftime('%s')
|
data = self._download_json(
|
||||||
api = f'https://video.nest.com/api/dropcam/cameras.get_by_public_token?token={video_id}&_={now}'
|
f'https://video.nest.com/api/dropcam/cameras.get_by_public_token?token={video_id}', video_id)
|
||||||
data = self._download_json(api, video_id)
|
item = traverse_obj(data, ('items', 0, {dict}))
|
||||||
items = data.get('items')
|
|
||||||
item = items[0] if items else {}
|
|
||||||
titles = [item.get('title'), item.get('name'), item.get('where')]
|
|
||||||
titles = [title for title in titles if title]
|
|
||||||
title = titles.pop(0) if titles else None
|
|
||||||
alt_title = titles.pop(0) if titles else None
|
|
||||||
timezone = item.get('timezone', '')
|
|
||||||
timezone = timezone.split('/')
|
|
||||||
timezone = timezone[1] if len(timezone) > 1 else None
|
|
||||||
timezone = timezone.replace('_', ' ')
|
|
||||||
location = timezone or item.get('where')
|
|
||||||
uuid = item.get('uuid')
|
uuid = item.get('uuid')
|
||||||
domain = item.get('live_stream_host')
|
domain = item.get('live_stream_host')
|
||||||
if not domain or not uuid:
|
if not domain or not uuid:
|
||||||
raise ExtractorError('Unable to construct playlist URL')
|
raise ExtractorError('Unable to construct playlist URL')
|
||||||
m3u8 = f'https://{domain}/nexus_aac/{uuid}/playlist.m3u8?public={video_id}'
|
m3u8 = f'https://{domain}/nexus_aac/{uuid}/playlist.m3u8?public={video_id}'
|
||||||
domain = item.get('nexus_api_nest_domain_host')
|
|
||||||
thumb = f'https://{domain}/get_image?uuid={uuid}&width=540&public={video_id}' if domain else None
|
thumb_domain = item.get('nexus_api_nest_domain_host')
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': title,
|
**traverse_obj(item, {
|
||||||
'alt_title': alt_title,
|
'description': ('description', {str}),
|
||||||
'description': item.get('description'),
|
'title': (('title', 'name', 'where'), {str}, filter, any),
|
||||||
'location': location,
|
'alt_title': ('name', {str}),
|
||||||
'thumbnail': thumb,
|
'location': ((('timezone', {lambda x: x.split('/')[1].replace('_', ' ')}), 'where'), {str}, filter, any),
|
||||||
|
}),
|
||||||
|
'thumbnail': f'https://{thumb_domain}/get_image?uuid={uuid}&public={video_id}' if thumb_domain else None,
|
||||||
'availability': 'public' if item.get('is_public') else None,
|
'availability': 'public' if item.get('is_public') else None,
|
||||||
'formats': self._extract_m3u8_formats(m3u8, video_id, 'mp4', live=True),
|
'formats': self._extract_m3u8_formats(m3u8, video_id, 'mp4', live=True),
|
||||||
'is_live': True,
|
'is_live': True,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user