yt-dlp/yt_dlp/extractor/dzsecurity.py

91 lines
2.6 KiB
Python
Raw Normal View History

2025-06-18 17:44:23 +00:00
2025-06-22 20:02:22 +00:00
from .common import InfoExtractor
from ..utils import (
smuggle_url,
unsmuggle_url,
)
from ..utils.traversal import traverse_obj
2025-06-18 17:44:23 +00:00
2025-06-18 17:54:20 +00:00
2025-06-18 17:44:23 +00:00
class DzsecurityLiveIE(InfoExtractor):
_VALID_URL = r'https?://live\.dzsecurity\.net/live/player/(?P<id>[\w-]+)'
2025-06-22 20:02:22 +00:00
_EMBED_REGEX = [rf'<iframe[^>]+\bsrc\s*=\s*["\'](?P<url>{_VALID_URL})']
2025-06-18 17:44:23 +00:00
2025-06-22 20:02:22 +00:00
_WEBPAGE_TESTS = [{
'url': 'https://www.echoroukonline.com/live',
'info_dict': {
'id': 'echorouktv',
2025-06-22 20:08:59 +00:00
'title': str,
2025-06-22 20:02:22 +00:00
'ext': 'mp4',
'live_status': 'is_live',
2025-06-18 18:15:00 +00:00
},
2025-06-22 20:21:02 +00:00
'params': {
'skip_download': 'Livestream',
},
2025-06-22 20:02:22 +00:00
}, {
'url': 'https://www.echoroukonline.com/live-news',
'info_dict': {
'id': 'echorouknews',
2025-06-22 20:08:59 +00:00
'title': str,
2025-06-22 20:02:22 +00:00
'ext': 'mp4',
'live_status': 'is_live',
2025-06-18 17:54:20 +00:00
},
2025-06-22 20:21:02 +00:00
'params': {
'skip_download': 'Livestream',
},
2025-06-22 20:02:22 +00:00
}, {
'url': 'https://elhayat.dz/%D8%A7%D9%84%D8%A8%D8%AB-%D8%A7%D9%84%D8%AD%D9%8A/',
'info_dict': {
'id': 'elhayattv',
2025-06-22 20:08:59 +00:00
'title': str,
2025-06-22 20:02:22 +00:00
'ext': 'mp4',
'live_status': 'is_live',
2025-06-18 17:54:20 +00:00
},
2025-06-22 20:21:02 +00:00
'params': {
'skip_download': 'Livestream',
},
2025-06-22 20:02:22 +00:00
}, {
'url': 'https://www.ennaharonline.com/live',
'info_dict': {
'id': 'ennahartv',
2025-06-22 20:08:59 +00:00
'title': str,
2025-06-22 20:02:22 +00:00
'ext': 'mp4',
'live_status': 'is_live',
2025-06-18 18:06:15 +00:00
},
2025-06-22 20:21:02 +00:00
'params': {
'skip_download': 'Livestream',
},
2025-06-22 20:02:22 +00:00
'skip': 'Geo-restricted to Algeria',
}]
2025-06-18 17:44:23 +00:00
@classmethod
def _extract_embed_urls(cls, url, webpage):
for embed_url in super()._extract_embed_urls(url, webpage):
yield smuggle_url(embed_url, {'referer': url})
2025-06-18 17:44:23 +00:00
def _real_extract(self, url):
url, smuggled_data = unsmuggle_url(url, {})
2025-06-18 17:49:26 +00:00
stream_id = self._match_id(url)
2025-06-18 17:44:23 +00:00
title = stream_id
referer = smuggled_data['referer']
if referer:
webpage = self._download_webpage(referer, referer)
title = self._html_extract_title(webpage, default=title)
2025-06-18 17:44:23 +00:00
player_page = self._download_webpage(url, stream_id, headers=traverse_obj(smuggled_data, {'Referer': 'referer'}))
2025-06-18 17:44:23 +00:00
m3u8_url = 'https:' + self._search_regex(
r'src:\s*location\.protocol\s*\+\s*"(//[^"]+\.m3u8\?[^"]+)"',
2025-06-18 17:54:20 +00:00
player_page,
'm3u8 URL',
2025-06-18 17:44:23 +00:00
)
return {
'id': stream_id,
'title': title,
'formats': self._extract_m3u8_formats(m3u8_url, stream_id),
2025-06-18 17:44:23 +00:00
'is_live': True,
}