[rcs] fixed coding conventions

This commit is contained in:
nixxo 2020-10-29 13:31:12 +01:00
parent a85e131b48
commit 508649e6f5

View File

@ -104,20 +104,20 @@ class RCSIE(InfoExtractor):
} }
def _get_video_src(self, video): def _get_video_src(self, video):
mediaFiles = video['mediaProfile']['mediaFile'] mediaFiles = video.get('mediaProfile').get('mediaFile')
src = {} src = {}
# audio # audio
if video['mediaType'] == 'AUDIO': if video.get('mediaType') == 'AUDIO':
for aud in mediaFiles: for aud in mediaFiles:
# todo: check # todo: check
src['mp3'] = aud['value'] src['mp3'] = aud.get('value')
# video # video
else: else:
for vid in mediaFiles: for vid in mediaFiles:
if vid['mimeType'] == 'application/vnd.apple.mpegurl': if vid.get('mimeType') == 'application/vnd.apple.mpegurl':
src['m3u8'] = vid['value'] src['m3u8'] = vid.get('value')
if vid['mimeType'] == 'video/mp4': if vid.get('mimeType') == 'video/mp4':
src['mp4'] = vid['value'] src['mp4'] = vid.get('value')
# replace host # replace host
for t in src: for t in src:
@ -128,9 +128,10 @@ def _get_video_src(self, video):
# switch cdn # switch cdn
if 'mp4' in src and 'm3u8' in src: if 'mp4' in src and 'm3u8' in src:
if '-lh.akamaihd' not in src['m3u8'] and 'akamai' in src['mp4']: if ('-lh.akamaihd' not in src.get('m3u8')
and 'akamai' in src.get('mp4')):
if 'm3u8' in src: if 'm3u8' in src:
matches = re.search(r'(?:https*:)?\/\/(?P<host>.*)\.net\/i(?P<path>.*)$', src['m3u8']) matches = re.search(r'(?:https*:)?\/\/(?P<host>.*)\.net\/i(?P<path>.*)$', src.get('m3u8'))
src['m3u8'] = 'https://vod.rcsobjects.it/hls/%s%s' % ( src['m3u8'] = 'https://vod.rcsobjects.it/hls/%s%s' % (
self._MIGRATION_MAP[matches.group('host')], self._MIGRATION_MAP[matches.group('host')],
matches.group('path').replace( matches.group('path').replace(
@ -140,11 +141,11 @@ def _get_video_src(self, video):
) )
) )
if 'mp4' in src: if 'mp4' in src:
matches = re.search(r'(?:https*:)?\/\/(?P<host>.*)\.net\/i(?P<path>.*)$', src['mp4']) matches = re.search(r'(?:https*:)?\/\/(?P<host>.*)\.net\/i(?P<path>.*)$', src.get('mp4'))
if matches: if matches:
if matches.group('host') in self._MIGRATION_MEDIA: if matches.group('host') in self._MIGRATION_MEDIA:
vh_stream = 'https://media2.corriereobjects.it' vh_stream = 'https://media2.corriereobjects.it'
if src['mp4'].find('fcs.quotidiani_!'): if src.get('mp4').find('fcs.quotidiani_!'):
vh_stream = 'https://media2-it.corriereobjects.it' vh_stream = 'https://media2-it.corriereobjects.it'
src['mp4'] = '%s%s' % ( src['mp4'] = '%s%s' % (
vh_stream, vh_stream,
@ -163,65 +164,68 @@ def _get_video_src(self, video):
) )
if 'mp3' in src: if 'mp3' in src:
src['mp3'] = src['mp3'].replace( src['mp3'] = src.get('mp3').replace(
'media2vam-corriere-it.akamaized.net', 'media2vam-corriere-it.akamaized.net',
'vod.rcsobjects.it/corriere') 'vod.rcsobjects.it/corriere')
if 'mp4' in src: if 'mp4' in src:
if src['mp4'].find('fcs.quotidiani_!'): if src.get('mp4').find('fcs.quotidiani_!'):
src['mp4'] = src['mp4'].replace('vod.rcsobjects', 'vod-it.rcsobjects') src['mp4'] = src.get('mp4').replace('vod.rcsobjects', 'vod-it.rcsobjects')
if 'm3u8' in src: if 'm3u8' in src:
if src['m3u8'].find('fcs.quotidiani_!'): if src.get('m3u8').find('fcs.quotidiani_!'):
src['m3u8'] = src['m3u8'].replace('vod.rcsobjects', 'vod-it.rcsobjects') src['m3u8'] = src.get('m3u8').replace('vod.rcsobjects', 'vod-it.rcsobjects')
if 'geoblocking' in video['mediaProfile']: if 'geoblocking' in video.get('mediaProfile'):
if 'm3u8' in src: if 'm3u8' in src:
src['m3u8'] = src['m3u8'].replace('vod.rcsobjects', 'vod-it.rcsobjects') src['m3u8'] = src.get('m3u8').replace('vod.rcsobjects', 'vod-it.rcsobjects')
if 'mp4' in src: if 'mp4' in src:
src['mp4'] = src['mp4'].replace('vod.rcsobjects', 'vod-it.rcsobjects') src['mp4'] = src.get('mp4').replace('vod.rcsobjects', 'vod-it.rcsobjects')
if 'm3u8' in src: if 'm3u8' in src:
if src['m3u8'].find('csmil') and src['m3u8'].find('vod'): if src.get('m3u8').find('csmil') and src.get('m3u8').find('vod'):
src['m3u8'] = src['m3u8'].replace('.csmil', '.urlset') src['m3u8'] = src.get('m3u8').replace('.csmil', '.urlset')
return src return src
def _create_formats(self, urls, video_id): def _create_formats(self, urls, video_id):
formats = [] formats = []
formats = self._extract_m3u8_formats( formats = self._extract_m3u8_formats(
urls['m3u8'], video_id, 'mp4', entry_protocol='m3u8_native', urls.get('m3u8'), video_id, 'mp4', entry_protocol='m3u8_native',
m3u8_id='hls', fatal=False) m3u8_id='hls', fatal=False)
if not formats: if not formats:
formats.append({ formats.append({
'format_id': 'http-mp4', 'format_id': 'http-mp4',
'url': urls['mp4'] 'url': urls.get('mp4')
}) })
self._sort_formats(formats) self._sort_formats(formats)
return formats return formats
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
mobj = re.search(self._VALID_URL, url).groupdict() mobj = re.search(self._VALID_URL, url)
if not mobj['cdn']: if 'cdn' not in mobj.groupdict():
raise ExtractorError('CDN not found in url: %s' % url) raise ExtractorError('CDN not found in url: %s' % url)
# for leitv/youreporter/viaggi don't use the embed page # for leitv/youreporter/viaggi don't use the embed page
if (mobj['cdn'] not in ['leitv.it', 'youreporter.it']) and (mobj['vid'] == 'video'): if ((mobj.group('cdn') not in ['leitv.it', 'youreporter.it'])
url = 'https://video.%s/video-embed/%s' % (mobj['cdn'], video_id) and (mobj.group('vid') == 'video')):
url = 'https://video.%s/video-embed/%s' % (mobj.group('cdn'), video_id)
page = self._download_webpage(url, video_id) page = self._download_webpage(url, video_id)
video_data = None video_data = None
# look for json video data url # look for json video data url
json = self._search_regex( json = self._search_regex(
r'''var url\s*=\s*["']((?:https?:)?//video\.rcs\.it/fragment-includes/video-includes/.+?\.json)["'];''', r'''(?x)var url\s*=\s*["']((?:https?:)?
//video\.rcs\.it
/fragment-includes/video-includes/.+?\.json)["'];''',
page, video_id, default=None) page, video_id, default=None)
if json: if json:
if json.startswith('//'): if json.startswith('//'):
json = 'https:%s' % json json = 'https:%s' % json
video_data = self._download_json(json, video_id) video_data = self._download_json(json, video_id)
# if url not found, look for json video data directly in the page # if json url not found, look for json video data directly in the page
else: else:
json = self._search_regex( json = self._search_regex(
r'[\s;]video\s*=\s*({[\s\S]+?})(?:;|,playlist=)', r'[\s;]video\s*=\s*({[\s\S]+?})(?:;|,playlist=)',
@ -241,11 +245,15 @@ def _real_extract(self, url):
formats = self._create_formats( formats = self._create_formats(
self._get_video_src(video_data), video_id) self._get_video_src(video_data), video_id)
description = (video_data.get('description')
or clean_html(video_data.get('htmlDescription')))
uploader = video_data.get('provider') or mobj.gruop('cdn')
return { return {
'id': video_id, 'id': video_id,
'title': video_data['title'], 'title': video_data.get('title'),
'description': video_data['description'] or clean_html(video_data['htmlDescription']), 'description': description,
'uploader': video_data['provider'] if video_data['provider'] else mobj['cdn'], 'uploader': uploader,
'formats': formats 'formats': formats
} }