[tvn24] Improve extraction (closes #11679)

This commit is contained in:
Sergey M․ 2017-02-18 23:34:09 +07:00
parent 02d9b82a23
commit e84888b432
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -2,11 +2,15 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import (
int_or_none,
unescapeHTML,
)
class TVN24IE(InfoExtractor): class TVN24IE(InfoExtractor):
_VALID_URL = r'http://(?:tvn24bis|(?:www|fakty)\.tvn24)\.pl/.+/(?P<id>[^/]+)\.html' _VALID_URL = r'https?://(?:(?:[^/]+)\.)?tvn24(?:bis)?\.pl/(?:[^/]+/)*(?P<id>[^/]+)\.html'
_TEST = { _TESTS = [{
'url': 'http://www.tvn24.pl/wiadomosci-z-kraju,3/oredzie-artura-andrusa,702428.html', 'url': 'http://www.tvn24.pl/wiadomosci-z-kraju,3/oredzie-artura-andrusa,702428.html',
'md5': 'fbdec753d7bc29d96036808275f2130c', 'md5': 'fbdec753d7bc29d96036808275f2130c',
'info_dict': { 'info_dict': {
@ -16,28 +20,53 @@ class TVN24IE(InfoExtractor):
'description': 'Wyjątkowe orędzie Artura Andrusa, jednego z gości "Szkła kontaktowego".', 'description': 'Wyjątkowe orędzie Artura Andrusa, jednego z gości "Szkła kontaktowego".',
'thumbnail': 're:http://.*[.]jpeg', 'thumbnail': 're:http://.*[.]jpeg',
} }
} }, {
'url': 'http://fakty.tvn24.pl/ogladaj-online,60/53-konferencja-bezpieczenstwa-w-monachium,716431.html',
'only_matching': True,
}, {
'url': 'http://sport.tvn24.pl/pilka-nozna,105/ligue-1-kamil-glik-rozcial-glowe-monaco-tylko-remisuje-z-bastia,716522.html',
'only_matching': True,
}, {
'url': 'http://tvn24bis.pl/poranek,146,m/gen-koziej-w-tvn24-bis-wracamy-do-czasow-zimnej-wojny,715660.html',
'only_matching': True,
}]
def _real_extract(self, url): def _real_extract(self, url):
page_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(url, page_id)
webpage = self._download_webpage(url, video_id)
title = self._og_search_title(webpage) title = self._og_search_title(webpage)
description = self._og_search_description(webpage)
thumbnail = self._html_search_regex(r'\bdata-poster="(.+?)"', webpage, 'data-poster') def extract_json(attr, name, fatal=True):
share_params = self._html_search_regex(r'\bdata-share-params="(.+?)"', webpage, 'data-share-params') return self._parse_json(
share_params = self._parse_json(share_params, page_id) self._search_regex(
video_id = share_params['id'] r'\b%s=(["\'])(?P<json>(?!\1).+?)\1' % attr, webpage,
quality_data = self._html_search_regex(r'\bdata-quality="(.+?)"', webpage, 'data-quality') name, group='json', fatal=fatal) or '{}',
quality_data = self._parse_json(quality_data, page_id) video_id, transform_source=unescapeHTML, fatal=fatal)
quality_data = extract_json('data-quality', 'formats')
formats = [] formats = []
for format_id, url in quality_data.items(): for format_id, url in quality_data.items():
formats.append({ formats.append({
'format_id': format_id,
'height': int(format_id.rstrip('p')),
'url': url, 'url': url,
'ext': 'mp4', 'format_id': format_id,
'height': int_or_none(format_id.rstrip('p')),
}) })
self._sort_formats(formats) self._sort_formats(formats)
description = self._og_search_description(webpage)
thumbnail = self._og_search_thumbnail(
webpage, default=None) or self._html_search_regex(
r'\bdata-poster=(["\'])(?P<url>(?!\1).+?)\1', webpage,
'thumbnail', group='url')
share_params = extract_json(
'data-share-params', 'share params', fatal=False)
if isinstance(share_params, dict):
video_id = share_params.get('id') or video_id
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,