2025-11-08 17:01:07 -08:00
|
|
|
|
import logging
|
2025-11-08 18:06:39 -08:00
|
|
|
|
import re
|
2025-11-08 18:48:09 -08:00
|
|
|
|
import urllib.parse
|
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,
|
2025-11-08 18:06:39 -08:00
|
|
|
|
get_element_by_class,
|
2025-11-08 17:26:20 -08:00
|
|
|
|
get_element_html_by_class,
|
2025-11-08 18:06:39 -08:00
|
|
|
|
get_element_html_by_id,
|
2025-11-08 17:26:20 -08:00
|
|
|
|
get_element_text_and_html_by_tag,
|
|
|
|
|
|
get_elements_html_by_class,
|
2025-11-08 18:06:39 -08:00
|
|
|
|
unified_strdate,
|
2025-11-08 17:26:20 -08:00
|
|
|
|
)
|
2025-11-08 17:01:07 -08:00
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
class HEINetworkTVIE(InfoExtractor):
|
|
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?heinetwork\.tv/(?:[\w\-/]+)'
|
2025-11-08 17:01:07 -08:00
|
|
|
|
_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',
|
2025-11-08 18:06:39 -08:00
|
|
|
|
'release_date': '20130207',
|
|
|
|
|
|
},
|
|
|
|
|
|
'params': {
|
|
|
|
|
|
'skip_download': True,
|
2025-11-08 17:01:07 -08:00
|
|
|
|
},
|
2025-11-08 18:48:09 -08:00
|
|
|
|
}, {
|
|
|
|
|
|
'url': 'https://www.heinetwork.tv/on-cinema-at-the-cinema/season-2/',
|
|
|
|
|
|
'playlist_mincount': 12,
|
|
|
|
|
|
'info_dict': {
|
|
|
|
|
|
'id': 'season-2',
|
|
|
|
|
|
'title': 'Season 2',
|
|
|
|
|
|
},
|
|
|
|
|
|
}, {
|
|
|
|
|
|
'url': 'https://www.heinetwork.tv/on-cinema-at-the-cinema/',
|
|
|
|
|
|
'playlist_mincount': 16,
|
|
|
|
|
|
'info_dict': {
|
|
|
|
|
|
'id': 'on-cinema-at-the-cinema',
|
|
|
|
|
|
'title': 'On Cinema at the Cinema',
|
|
|
|
|
|
},
|
2025-11-08 17:01:07 -08:00
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
|
|
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.')
|
|
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
item_id = urllib.parse.urlparse(url).path.split('/')[-1]
|
|
|
|
|
|
webpage = self._download_webpage(url, item_id)
|
|
|
|
|
|
if self._is_collection(webpage):
|
|
|
|
|
|
return self._extract_collection(webpage, url)
|
|
|
|
|
|
else:
|
|
|
|
|
|
return self._extract_single_video(webpage, url)
|
|
|
|
|
|
|
|
|
|
|
|
def _extract_collection(self, webpage, 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,
|
|
|
|
|
|
playlist_id=display_id,
|
|
|
|
|
|
ie=HEINetworkTVIE,
|
|
|
|
|
|
playlist_title=self._breadcrumbs(webpage)[-1],
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _extract_single_video(self, webpage, url):
|
|
|
|
|
|
path_components = [p for p in urllib.parse.urlparse(url).path.split('/') if p]
|
|
|
|
|
|
video_id = path_components[-1]
|
2025-11-08 17:01:07 -08:00
|
|
|
|
video_src = self._extract_video_src(webpage)
|
|
|
|
|
|
formats, _subs = self._extract_m3u8_formats_and_subtitles(video_src, video_id)
|
2025-11-08 18:06:39 -08:00
|
|
|
|
air_date = self._air_date(webpage)
|
2025-11-08 17:01:07 -08:00
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
'id': video_id,
|
|
|
|
|
|
'title': self._extract_video_title(webpage),
|
|
|
|
|
|
'formats': formats,
|
2025-11-08 18:06:39 -08:00
|
|
|
|
'release_date': air_date,
|
2025-11-08 17:01:07 -08:00
|
|
|
|
}
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
# General helpers
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
def _is_logged_in(self, webpage):
|
|
|
|
|
|
return get_element_by_attribute('href', '/my-account', webpage) is not None
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
def _is_collection(self, webpage):
|
|
|
|
|
|
return get_element_by_class('grid', webpage) is not None
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
def _breadcrumbs(self, webpage):
|
|
|
|
|
|
breadcrumb_container = get_element_html_by_class('breadcrumbs', webpage)
|
|
|
|
|
|
root = ElementTree.fromstring(breadcrumb_container)
|
|
|
|
|
|
return [''.join(e.itertext()).strip() for e in root.findall('.//li')]
|
2025-11-08 17:48:31 -08:00
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
# Single-video helpers
|
2025-11-08 17:48:31 -08:00
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
def _extract_video_src(self, webpage):
|
|
|
|
|
|
_, html = get_element_text_and_html_by_tag('castable-video', webpage)
|
|
|
|
|
|
attrs = extract_attributes(html)
|
|
|
|
|
|
return attrs['src']
|
2025-11-08 17:48:31 -08:00
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
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']
|
2025-11-08 17:26:20 -08:00
|
|
|
|
|
2025-11-08 18:48:09 -08:00
|
|
|
|
def _air_date(self, webpage):
|
|
|
|
|
|
episode_info_container = get_element_html_by_id('hei-episode-title', webpage)
|
|
|
|
|
|
release_date_str = get_element_by_class('text-sm', episode_info_container)
|
|
|
|
|
|
matches = re.match(r'\s+Air Date: (?P<date>[\w/]+)', release_date_str)
|
|
|
|
|
|
return unified_strdate(matches.group('date'), day_first=False)
|