Check for None through truth value checks, added test for scenario for delegating the url
This commit is contained in:
parent
ccdbe1e8fa
commit
e13bd53a94
@ -28,6 +28,13 @@ class LcpIE(InfoExtractor):
|
|||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Politique Matin - Politique matin'
|
'title': 'Politique Matin - Politique matin'
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
'url': 'http://www.lcp.fr/le-direct',
|
||||||
|
'info_dict': {
|
||||||
|
'title': 'Le direct | LCP Assembl\xe9e nationale',
|
||||||
|
'id': 'le-direct',
|
||||||
|
},
|
||||||
|
'playlist_mincount': 1
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
@ -35,9 +42,9 @@ class LcpIE(InfoExtractor):
|
|||||||
webpage = self._download_webpage(url, display_id)
|
webpage = self._download_webpage(url, display_id)
|
||||||
|
|
||||||
# Extract the required info of the media files gathered in a dictionary
|
# Extract the required info of the media files gathered in a dictionary
|
||||||
media_files_info = self.__extract_from_webpage(display_id, webpage)
|
media_files_info = None #self.__extract_from_webpage(display_id, webpage)
|
||||||
# Some web pages embed videos from other platforms like dailymotion, therefore we pass on these URLs
|
# Some web pages embed videos from other platforms like dailymotion, therefore we pass on these URLs
|
||||||
if media_files_info is None:
|
if not media_files_info:
|
||||||
return self.url_result(url, 'Generic')
|
return self.url_result(url, 'Generic')
|
||||||
|
|
||||||
video_formats = self.__get_video_formats(media_files_info)
|
video_formats = self.__get_video_formats(media_files_info)
|
||||||
@ -55,12 +62,12 @@ class LcpIE(InfoExtractor):
|
|||||||
embed_url = self.__extract_embed_url(webpage)
|
embed_url = self.__extract_embed_url(webpage)
|
||||||
embed_regex = r'(?:[a-zA-Z0-9]+\.)?lcp\.fr/embed/(?P<clip_id>[A-za-z0-9]+)/(?P<player_id>[A-za-z0-9]+)/(?P<skin_name>[^\/]+)'
|
embed_regex = r'(?:[a-zA-Z0-9]+\.)?lcp\.fr/embed/(?P<clip_id>[A-za-z0-9]+)/(?P<player_id>[A-za-z0-9]+)/(?P<skin_name>[^\/]+)'
|
||||||
|
|
||||||
clip_id = self._search_regex(embed_regex, embed_url, 'clip id', group='clip_id', fatal=False)
|
clip_id = self._search_regex(embed_regex, embed_url, 'clip id', group='clip_id', default=None)
|
||||||
player_id = self._search_regex(embed_regex, embed_url, 'player id', group='player_id', fatal=False)
|
player_id = self._search_regex(embed_regex, embed_url, 'player id', group='player_id', default=None)
|
||||||
skin_name = self._search_regex(embed_regex, embed_url, 'skin name', group='skin_name', fatal=False)
|
skin_name = self._search_regex(embed_regex, embed_url, 'skin name', group='skin_name', default=None)
|
||||||
|
|
||||||
# Check whether the matches failed, which might be when dealing with other players (e.g., dailymotion stream)
|
# Check whether the matches failed, which might be when dealing with other players (e.g., dailymotion stream)
|
||||||
if (clip_id is None) or (player_id is None) or (skin_name is None):
|
if not clip_id or not player_id or not skin_name:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self.__extract_from_player(display_id, clip_id, player_id, skin_name)
|
return self.__extract_from_player(display_id, clip_id, player_id, skin_name)
|
||||||
@ -83,40 +90,42 @@ class LcpIE(InfoExtractor):
|
|||||||
|
|
||||||
# All videos are part of a playlist, a single video is also put in a playlist
|
# All videos are part of a playlist, a single video is also put in a playlist
|
||||||
media_files_info = info_json.get('Playlist')
|
media_files_info = info_json.get('Playlist')
|
||||||
if media_files_info is not None:
|
if not media_files_info:
|
||||||
media_files_info = media_files_info[0]
|
return None
|
||||||
return media_files_info
|
return media_files_info[0]
|
||||||
|
|
||||||
def __get_thumbnails(self, media_files_info):
|
def __get_thumbnails(self, media_files_info):
|
||||||
thumbnails = []
|
thumbnails = []
|
||||||
media_thumbnail_info = media_files_info.get('MediaInfo', {}).get('Poster')
|
media_thumbnail_info = media_files_info.get('MediaInfo', {}).get('Poster')
|
||||||
if media_thumbnail_info is not None:
|
if not media_thumbnail_info:
|
||||||
for thumbnail in media_thumbnail_info:
|
return None
|
||||||
thumbnails.append({
|
for thumbnail in media_thumbnail_info:
|
||||||
'url': thumbnail.get('Url'),
|
thumbnails.append({
|
||||||
'width': int_or_none(thumbnail.get('Size'))
|
'url': thumbnail.get('Url'),
|
||||||
})
|
'width': int_or_none(thumbnail.get('Size'))
|
||||||
|
})
|
||||||
return thumbnails
|
return thumbnails
|
||||||
|
|
||||||
def __get_video_formats(self, media_files_info):
|
def __get_video_formats(self, media_files_info):
|
||||||
formats = []
|
formats = []
|
||||||
media_files = media_files_info.get('MediaFiles')
|
media_files = media_files_info.get('MediaFiles')
|
||||||
|
if not media_files:
|
||||||
|
return None
|
||||||
|
|
||||||
if media_files is not None:
|
formats.extend(self.__get_mp4_video_formats(media_files))
|
||||||
formats.extend(self.__get_mp4_video_formats(media_files))
|
self._sort_formats(formats)
|
||||||
self._sort_formats(formats)
|
|
||||||
|
|
||||||
return formats
|
return formats
|
||||||
|
|
||||||
def __get_mp4_video_formats(self, media_files_json):
|
def __get_mp4_video_formats(self, media_files_json):
|
||||||
formats = []
|
formats = []
|
||||||
mp4_files_json = media_files_json.get('Mp4')
|
mp4_files_json = media_files_json.get('Mp4')
|
||||||
if mp4_files_json is not None:
|
if not mp4_files_json:
|
||||||
for video_info in mp4_files_json:
|
return None
|
||||||
bitrate = int_or_none(video_info.get('Bitrate'), scale=0.001) # Scale bitrate to KBit/s
|
for video_info in mp4_files_json:
|
||||||
formats.append({
|
bitrate = int_or_none(video_info.get('Bitrate'), scale=1000) # Scale bitrate to KBit/s
|
||||||
'url': video_info.get('Url'),
|
formats.append({
|
||||||
'ext': 'mp4',
|
'url': video_info.get('Url'),
|
||||||
'tbr': bitrate
|
'ext': 'mp4',
|
||||||
})
|
'tbr': bitrate
|
||||||
|
})
|
||||||
return formats
|
return formats
|
||||||
|
Loading…
x
Reference in New Issue
Block a user