0
0
Fork 0

[rtp] fix extraction(closes #15099)

main
Remita Amine 2019-05-28 04:58:12 +01:00
parent 0d29751890
commit ead467a9c1
1 changed files with 30 additions and 53 deletions

View File

@ -1,9 +1,11 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import (
determine_ext,
js_to_json,
)
class RTPIE(InfoExtractor): class RTPIE(InfoExtractor):
@ -18,10 +20,6 @@ class RTPIE(InfoExtractor):
'description': 'As paixões musicais de António Cartaxo e António Macedo', 'description': 'As paixões musicais de António Cartaxo e António Macedo',
'thumbnail': r're:^https?://.*\.jpg', 'thumbnail': r're:^https?://.*\.jpg',
}, },
'params': {
# rtmp download
'skip_download': True,
},
}, { }, {
'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas', 'url': 'http://www.rtp.pt/play/p831/a-quimica-das-coisas',
'only_matching': True, 'only_matching': True,
@ -33,57 +31,36 @@ class RTPIE(InfoExtractor):
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
title = self._html_search_meta( title = self._html_search_meta(
'twitter:title', webpage, display_name='title', fatal=True) 'twitter:title', webpage, display_name='title', fatal=True)
description = self._html_search_meta('description', webpage)
thumbnail = self._og_search_thumbnail(webpage)
player_config = self._search_regex( config = self._parse_json(self._search_regex(
r'(?s)RTPPLAY\.player\.newPlayer\(\s*(\{.*?\})\s*\)', webpage, 'player config') r'(?s)RTPPlayer\(({.+?})\);', webpage,
config = self._parse_json(player_config, video_id) 'player config'), video_id, js_to_json)
file_url = config['file']
path, ext = config.get('file').rsplit('.', 1) ext = determine_ext(file_url)
formats = [{ if ext == 'm3u8':
'format_id': 'rtmp', file_key = config.get('fileKey')
'ext': ext, formats = self._extract_m3u8_formats(
'vcodec': config.get('type') == 'audio' and 'none' or None, file_url, video_id, 'mp4', 'm3u8_native',
'preference': -2, m3u8_id='hls', fatal=file_key)
'url': 'rtmp://{streamer:s}/{application:s}'.format(**config), if file_key:
'app': config.get('application'), formats.append({
'play_path': '{ext:s}:{path:s}'.format(ext=ext, path=path), 'url': 'https://cdn-ondemand.rtp.pt' + file_key,
'page_url': url, 'preference': 1,
'rtmp_live': config.get('live', False), })
'player_url': 'http://programas.rtp.pt/play/player.swf?v3', self._sort_formats(formats)
'rtmp_real_time': True, else:
}] formats = [{
'url': file_url,
# Construct regular HTTP download URLs 'ext': ext,
replacements = { }]
'audio': { if config.get('mediaType') == 'audio':
'format_id': 'mp3', for f in formats:
'pattern': r'^nas2\.share/wavrss/', f['vcodec'] = 'none'
'repl': 'http://rsspod.rtp.pt/podcasts/',
'vcodec': 'none',
},
'video': {
'format_id': 'mp4_h264',
'pattern': r'^nas2\.share/h264/',
'repl': 'http://rsspod.rtp.pt/videocasts/',
'vcodec': 'h264',
},
}
r = replacements[config['type']]
if re.match(r['pattern'], config['file']) is not None:
formats.append({
'format_id': r['format_id'],
'url': re.sub(r['pattern'], r['repl'], config['file']),
'vcodec': r['vcodec'],
})
self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'formats': formats, 'formats': formats,
'description': description, 'description': self._html_search_meta(['description', 'twitter:description'], webpage),
'thumbnail': thumbnail, 'thumbnail': config.get('poster') or self._og_search_thumbnail(webpage),
} }