mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-06-28 01:18:30 +00:00
Update dzsecurity.py to use _EMBED_REGEX
This commit is contained in:
parent
5c56c1f0e3
commit
736f417e80
@ -1,13 +1,42 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
|
from yt_dlp import traverse_obj
|
||||||
from yt_dlp.extractor.common import InfoExtractor
|
from yt_dlp.extractor.common import InfoExtractor
|
||||||
from yt_dlp.utils import ExtractorError
|
from yt_dlp.utils import smuggle_url, unsmuggle_url
|
||||||
|
|
||||||
|
|
||||||
class DzsecurityLiveIE(InfoExtractor):
|
class DzsecurityLiveIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?(echoroukonline\.com/live(?:-news)?|ennaharonline\.com/live(?:-news)?|elhayat\.dz/%D8%A7%D9%84%D8%A8%D8%AB-%D8%A7%D9%84%D8%AD%D9%8A)'
|
_VALID_URL = r'https?://live\.dzsecurity\.net/live/player/(?P<id>[\w-]+)'
|
||||||
|
_EMBED_REGEX = [rf'<iframe [^>]*\bsrc\s*=\s*[\'"](?P<url>{_VALID_URL})']
|
||||||
|
|
||||||
_TESTS = [{
|
_WEBPAGE_TESTS = [
|
||||||
|
{
|
||||||
|
'url': 'https://www.echoroukonline.com/live',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'echorouktv',
|
||||||
|
'title': r're:البث الحي لقناة الشروق تي في',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'live_status': 'is_live',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url': 'https://www.echoroukonline.com/live-news',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'echorouknews',
|
||||||
|
'title': r're:البث الحي لقناة الشروق نيوز - آخر أخبار الجزائر',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'live_status': 'is_live',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url': 'https://elhayat.dz/%D8%A7%D9%84%D8%A8%D8%AB-%D8%A7%D9%84%D8%AD%D9%8A/',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'elhayattv',
|
||||||
|
'title': r're:البث الحي - الحياة',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'live_status': 'is_live',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
'url': 'https://www.ennaharonline.com/live',
|
'url': 'https://www.ennaharonline.com/live',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'ennahartv',
|
'id': 'ennahartv',
|
||||||
@ -16,55 +45,26 @@ class DzsecurityLiveIE(InfoExtractor):
|
|||||||
'live_status': 'is_live',
|
'live_status': 'is_live',
|
||||||
},
|
},
|
||||||
'skip': 'Geo-restricted to Algeria',
|
'skip': 'Geo-restricted to Algeria',
|
||||||
}, {
|
|
||||||
'url': 'https://www.echoroukonline.com/live',
|
|
||||||
'info_dict': {
|
|
||||||
'id': 'echorouktv',
|
|
||||||
'title': r're:البث الحي لقناة الشروق تي في',
|
|
||||||
'ext': 'mp4',
|
|
||||||
'live_status': 'is_live',
|
|
||||||
},
|
},
|
||||||
}, {
|
]
|
||||||
'url': 'https://www.echoroukonline.com/live-news',
|
|
||||||
'info_dict': {
|
@classmethod
|
||||||
'id': 'echorouknews',
|
def _extract_embed_urls(cls, url, webpage):
|
||||||
'title': r're:البث الحي لقناة الشروق نيوز - آخر أخبار الجزائر',
|
for embed_url in super()._extract_embed_urls(url, webpage):
|
||||||
'ext': 'mp4',
|
yield smuggle_url(embed_url, {'referer': url})
|
||||||
'live_status': 'is_live',
|
|
||||||
},
|
|
||||||
}, {
|
|
||||||
'url': 'https://elhayat.dz/%D8%A7%D9%84%D8%A8%D8%AB-%D8%A7%D9%84%D8%AD%D9%8A',
|
|
||||||
'info_dict': {
|
|
||||||
'id': 'elhayattv',
|
|
||||||
'title': r're:البث الحي - الحياة',
|
|
||||||
'ext': 'mp4',
|
|
||||||
'live_status': 'is_live',
|
|
||||||
},
|
|
||||||
}]
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
webpage = self._download_webpage(url, url, impersonate=True)
|
url, smuggled_data = unsmuggle_url(url, {})
|
||||||
|
|
||||||
title = self._html_extract_title(webpage, default='Live Stream')
|
stream_id = self._match_id(url)
|
||||||
|
|
||||||
player_url, stream_id = self._html_search_regex(
|
title = stream_id
|
||||||
r'https://live\.dzsecurity\.net/live/player/([a-zA-Z0-9_-]+)',
|
referer = smuggled_data['referer']
|
||||||
webpage,
|
if referer:
|
||||||
'player URL',
|
webpage = self._download_webpage(referer, referer)
|
||||||
group=(0, 1),
|
title = self._html_extract_title(webpage, default=title)
|
||||||
)
|
|
||||||
|
|
||||||
base_url_match = re.match(r'(https?://[^/]+)', url)
|
player_page = self._download_webpage(url, stream_id, headers=traverse_obj(smuggled_data, {'Referer': 'referer'}))
|
||||||
if not base_url_match:
|
|
||||||
raise ExtractorError('Failed to extract base URL from input URL')
|
|
||||||
|
|
||||||
base_url = base_url_match.group(1)
|
|
||||||
|
|
||||||
headers = {
|
|
||||||
'Referer': base_url,
|
|
||||||
}
|
|
||||||
|
|
||||||
player_page = self._download_webpage(player_url, player_url, headers=headers)
|
|
||||||
|
|
||||||
m3u8_url = 'https:' + self._search_regex(
|
m3u8_url = 'https:' + self._search_regex(
|
||||||
r'src:\s*location\.protocol\s*\+\s*"(//[^"]+\.m3u8\?[^"]+)"',
|
r'src:\s*location\.protocol\s*\+\s*"(//[^"]+\.m3u8\?[^"]+)"',
|
||||||
|
Loading…
Reference in New Issue
Block a user