2025-11-08 17:01:07 -08:00
|
|
|
|
import logging
|
2025-11-08 17:48:31 -08:00
|
|
|
|
from abc import ABC, abstractmethod
|
2025-11-08 17:26:20 -08:00
|
|
|
|
from xml.etree import ElementTree
|
2025-11-08 17:01:07 -08:00
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2025-11-08 17:26:20 -08:00
|
|
|
|
from ..utils import (
|
|
|
|
|
|
extract_attributes,
|
|
|
|
|
|
get_element_by_attribute,
|
|
|
|
|
|
get_element_html_by_class,
|
|
|
|
|
|
get_element_text_and_html_by_tag,
|
|
|
|
|
|
get_elements_html_by_class,
|
|
|
|
|
|
)
|
2025-11-08 17:01:07 -08:00
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HEINetworkTVVideoIE(InfoExtractor):
|
|
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?heinetwork\.tv/(?P<series>[\w-]+)/(?P<season>[\w-]+)/(?P<id>[\w-]+)'
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
|
# requires cookies
|
|
|
|
|
|
'url': 'https://www.heinetwork.tv/on-cinema-at-the-cinema/season-2/side-effects-and-identity-thief/',
|
|
|
|
|
|
'md5': 'd10a28af64c3c34a69baa3f38a8c760b',
|
|
|
|
|
|
'info_dict': {
|
|
|
|
|
|
'id': 'side-effects-and-identity-thief',
|
|
|
|
|
|
'title': '201 ‘Side Effects’ and ‘Identity Thief’',
|
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
|
},
|
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
|
|
def _is_logged_in(self, webpage):
|
|
|
|
|
|
return get_element_by_attribute('href', '/my-account', webpage) is not None
|
|
|
|
|
|
|
|
|
|
|
|
def _extract_video_src(self, webpage):
|
|
|
|
|
|
_, html = get_element_text_and_html_by_tag('castable-video', webpage)
|
|
|
|
|
|
attrs = extract_attributes(html)
|
|
|
|
|
|
return attrs['src']
|
|
|
|
|
|
|
|
|
|
|
|
def _extract_video_title(self, webpage):
|
|
|
|
|
|
_, mux_video = get_element_text_and_html_by_tag('mux-video', webpage)
|
|
|
|
|
|
attrs = extract_attributes(mux_video)
|
|
|
|
|
|
if 'metadata-video-title' not in attrs:
|
|
|
|
|
|
return None
|
|
|
|
|
|
return attrs['metadata-video-title']
|
|
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
|
if not self._is_logged_in(self._download_webpage('https://www.heinetwork.tv/', None)):
|
|
|
|
|
|
logger.warning('You are not logged in. Some videos may be unavailable.')
|
|
|
|
|
|
|
|
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
|
webpage = self._download_webpage(url, video_id)
|
|
|
|
|
|
video_src = self._extract_video_src(webpage)
|
|
|
|
|
|
formats, _subs = self._extract_m3u8_formats_and_subtitles(video_src, video_id)
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
'id': video_id,
|
|
|
|
|
|
'title': self._extract_video_title(webpage),
|
|
|
|
|
|
'formats': formats,
|
|
|
|
|
|
}
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
|
|
|
|
|
|
2025-11-08 17:48:31 -08:00
|
|
|
|
def _breadcrumbs(webpage):
|
|
|
|
|
|
breadcrumb_container = get_element_html_by_class('breadcrumbs', webpage)
|
|
|
|
|
|
root = ElementTree.fromstring(breadcrumb_container)
|
|
|
|
|
|
return [e.text.strip() for e in root.findall('.//li')]
|
|
|
|
|
|
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
2025-11-08 17:48:31 -08:00
|
|
|
|
class HEINetworkTVCollectionIE(InfoExtractor, ABC):
|
|
|
|
|
|
"""Base class for HEINetworkTV collection extractors, which appear to have the same webpage structure"""
|
|
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2025-11-08 17:26:20 -08:00
|
|
|
|
def _playlist_item_extractor(self):
|
2025-11-08 17:48:31 -08:00
|
|
|
|
pass
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
|
|
|
|
|
def _title(self, webpage):
|
2025-11-08 17:48:31 -08:00
|
|
|
|
return _breadcrumbs(webpage)[-1]
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
|
display_id = self._match_id(url)
|
|
|
|
|
|
webpage = self._download_webpage(url, display_id)
|
|
|
|
|
|
grid = get_element_html_by_class('grid', webpage)
|
|
|
|
|
|
linksHtml = get_elements_html_by_class('group/thumb', grid)
|
|
|
|
|
|
urls = [extract_attributes(html)['href'] for html in linksHtml]
|
|
|
|
|
|
|
|
|
|
|
|
return self.playlist_from_matches(
|
|
|
|
|
|
urls,
|
|
|
|
|
|
ie=self._playlist_item_extractor(),
|
|
|
|
|
|
playlist_id=display_id,
|
|
|
|
|
|
playlist_title=self._title(webpage),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-08 17:48:31 -08:00
|
|
|
|
class HEINetworkTVSeasonIE(HEINetworkTVCollectionIE):
|
|
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?heinetwork\.tv/(?P<series>[\w-]+)/(?P<id>[\w-]+)'
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
|
# requires cookies
|
|
|
|
|
|
'url': 'https://www.heinetwork.tv/on-cinema-at-the-cinema/season-2/',
|
|
|
|
|
|
'playlist_mincount': 12,
|
|
|
|
|
|
'info_dict': {
|
|
|
|
|
|
'id': 'season-2',
|
|
|
|
|
|
'title': 'Season 2',
|
|
|
|
|
|
},
|
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
|
|
def _playlist_item_extractor(self):
|
|
|
|
|
|
return HEINetworkTVVideoIE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HEINetworkTVSeriesIE(HEINetworkTVCollectionIE):
|
2025-11-08 17:26:20 -08:00
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?heinetwork\.tv/(?P<id>[\w-]+)'
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
|
# requires cookies
|
|
|
|
|
|
'url': 'https://www.heinetwork.tv/on-cinema-at-the-cinema/',
|
|
|
|
|
|
'playlist_mincount': 16,
|
|
|
|
|
|
'info_dict': {
|
|
|
|
|
|
'id': 'on-cinema-at-the-cinema',
|
2025-11-08 17:48:31 -08:00
|
|
|
|
'title': 'On Cinema at the Cinema',
|
2025-11-08 17:26:20 -08:00
|
|
|
|
},
|
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
|
|
def _playlist_item_extractor(self):
|
|
|
|
|
|
return HEINetworkTVSeasonIE
|