[TV2Hu] Fix TV2HuIE and add TV2HuSeriesIE (#804)

Closes #799 
Authored by: Ashish0804
This commit is contained in:
Ashish 2021-08-29 06:44:22 +05:30 committed by GitHub
parent abafce59a1
commit 58f68fe703
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 41 deletions

View file

@ -1440,7 +1440,10 @@ from .tv2dk import (
TV2DKIE, TV2DKIE,
TV2DKBornholmPlayIE, TV2DKBornholmPlayIE,
) )
from .tv2hu import TV2HuIE from .tv2hu import (
TV2HuIE,
TV2HuSeriesIE,
)
from .tv4 import TV4IE from .tv4 import TV4IE
from .tv5mondeplus import TV5MondePlusIE from .tv5mondeplus import TV5MondePlusIE
from .tv5unis import ( from .tv5unis import (

View file

@ -2,61 +2,109 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import int_or_none from ..utils import (
traverse_obj,
UnsupportedError,
)
class TV2HuIE(InfoExtractor): class TV2HuIE(InfoExtractor):
IE_NAME = 'tv2.hu' IE_NAME = 'tv2play.hu'
_VALID_URL = r'https?://(?:www\.)?tv2\.hu/(?:[^/]+/)+(?P<id>\d+)_[^/?#]+?\.html' _VALID_URL = r'https?://(?:www\.)?tv2play\.hu/(?!szalag/)(?P<id>[^#&?]+)'
_TESTS = [{ _TESTS = [{
'url': 'http://tv2.hu/ezek_megorultek/217679_ezek-megorultek---1.-adas-1.-resz.html', 'url': 'https://tv2play.hu/mintaapak/mintaapak_213_epizod_resz',
'info_dict': {
'id': '249240',
'ext': 'mp4',
'title': 'Mintaapák - 213. epizód',
'series': 'Mintaapák',
'duration': 2164,
'description': 'md5:7350147e75485a59598e806c47967b07',
'thumbnail': r're:^https?://.*\.jpg$',
'release_date': '20210825',
'season_number': None,
'episode_number': 213,
},
'params': {
'skip_download': True,
},
}, {
'url': 'https://tv2play.hu/taxi_2',
'md5': '585e58e2e090f34603804bb2c48e98d8', 'md5': '585e58e2e090f34603804bb2c48e98d8',
'info_dict': { 'info_dict': {
'id': '217679', 'id': '199363',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Ezek megőrültek! - 1. adás 1. rész', 'title': 'Taxi 2',
'upload_date': '20160826', 'series': 'Taxi 2',
'thumbnail': r're:^https?://.*\.jpg$' 'duration': 5087,
} 'description': 'md5:47762155dc9a50241797ded101b1b08c',
}, { 'thumbnail': r're:^https?://.*\.jpg$',
'url': 'http://tv2.hu/ezek_megorultek/teljes_adasok/217677_ezek-megorultek---1.-adas-2.-resz.html', 'release_date': '20210118',
'only_matching': True 'season_number': None,
}, { 'episode_number': None,
'url': 'http://tv2.hu/musoraink/aktiv/aktiv_teljes_adas/217963_aktiv-teljes-adas---2016.08.30..html', },
'only_matching': True 'params': {
'skip_download': True,
},
}] }]
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) id = self._match_id(url)
webpage = self._download_webpage(url, video_id) json_data = self._download_json(f'https://tv2play.hu/api/search/{id}', id)
json_url = self._search_regex(
r'jsonUrl\s*=\s*"([^"]+)"', webpage, 'json url')
json_data = self._download_json(json_url, video_id)
formats = [] if json_data['contentType'] == 'showpage':
for b in ('bitrates', 'backupBitrates'): ribbon_ids = traverse_obj(json_data, ('pages', ..., 'tabs', ..., 'ribbonIds'), get_all=False, expected_type=list)
bitrates = json_data.get(b, {}) entries = [self.url_result(f'https://tv2play.hu/szalag/{ribbon_id}',
m3u8_url = bitrates.get('hls') ie=TV2HuSeriesIE.ie_key(), video_id=ribbon_id) for ribbon_id in ribbon_ids]
if m3u8_url: return self.playlist_result(entries, playlist_id=id)
formats.extend(self._extract_wowza_formats( elif json_data['contentType'] != 'video':
m3u8_url, video_id, skip_protocols=['rtmp', 'rtsp'])) raise UnsupportedError(url)
for mp4_url in bitrates.get('mp4', []): video_id = str(json_data['id'])
height = int_or_none(self._search_regex( player_id = json_data.get('playerId')
r'\.(\d+)p\.mp4', mp4_url, 'height', default=None)) series_json = json_data.get('seriesInfo', {})
formats.append({
'format_id': 'http' + ('-%d' % height if height else ''), video_json_url = self._download_json(f'https://tv2play.hu/api/streaming-url?playerId={player_id}', video_id)['url']
'url': mp4_url, video_json = self._download_json(video_json_url, video_id)
'height': height, m3u8_url = self._proto_relative_url(traverse_obj(video_json, ('bitrates', 'hls')))
'width': int_or_none(height / 9.0 * 16.0 if height else None), formats, subtitles = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)
})
self._sort_formats(formats) self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,
'title': self._og_search_title(webpage).strip(), 'title': json_data['title'],
'thumbnail': self._og_search_thumbnail(webpage), 'series': json_data.get('seriesTitle'),
'upload_date': self._search_regex( 'duration': json_data.get('length'),
r'/vod/(\d{8})/', json_url, 'upload_date', default=None), 'description': json_data.get('description'),
'thumbnail': 'https://tv2play.hu' + json_data.get('thumbnailUrl'),
'release_date': json_data.get('uploadedAt').replace('.', ''),
'season_number': series_json.get('seasonNr'),
'episode_number': series_json.get('episodeNr'),
'formats': formats, 'formats': formats,
'subtitles': subtitles,
} }
class TV2HuSeriesIE(InfoExtractor):
IE_NAME = 'tv2playseries.hu'
_VALID_URL = r'https?://(?:www\.)?tv2play\.hu/szalag/(?P<id>[^#&?]+)'
_TESTS = [{
'url': 'https://tv2play.hu/szalag/59?rendezes=nepszeruseg',
'playlist_mincount': 284,
'info_dict': {
'id': '59',
}
}]
def _real_extract(self, url):
id = self._match_id(url)
json_data = self._download_json(f'https://tv2play.hu/api/ribbons/{id}/0?size=100000', id)
entries = []
for card in json_data.get('cards', []):
video_id = card.get('slug')
if video_id:
entries.append(self.url_result(f'https://tv2play.hu/{video_id}',
ie=TV2HuIE.ie_key(), video_id=video_id))
return self.playlist_result(entries, playlist_id=id)