| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |     determine_ext, | 
					
						
							| 
									
										
										
										
											2017-04-20 05:16:41 +01:00
										 |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2018-07-21 19:08:28 +07:00
										 |  |  |     int_or_none, | 
					
						
							|  |  |  |     mimetype2ext, | 
					
						
							|  |  |  |     parse_iso8601, | 
					
						
							|  |  |  |     url_or_none, | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AMPIE(InfoExtractor): | 
					
						
							|  |  |  |     # parse Akamai Adaptive Media Player feed | 
					
						
							|  |  |  |     def _extract_feed_info(self, url): | 
					
						
							| 
									
										
										
										
											2017-04-20 05:16:41 +01:00
										 |  |  |         feed = self._download_json( | 
					
						
							| 
									
										
										
										
											2015-12-21 11:12:58 +01:00
										 |  |  |             url, None, 'Downloading Akamai AMP feed', | 
					
						
							| 
									
										
										
										
											2017-04-20 05:16:41 +01:00
										 |  |  |             'Unable to download Akamai AMP feed') | 
					
						
							|  |  |  |         item = feed.get('channel', {}).get('item') | 
					
						
							|  |  |  |         if not item: | 
					
						
							|  |  |  |             raise ExtractorError('%s said: %s' % (self.IE_NAME, feed['error'])) | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         video_id = item['guid'] | 
					
						
							| 
									
										
										
										
											2015-12-21 11:12:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         def get_media_node(name, default=None): | 
					
						
							|  |  |  |             media_name = 'media-%s' % name | 
					
						
							|  |  |  |             media_group = item.get('media-group') or item | 
					
						
							|  |  |  |             return media_group.get(media_name) or item.get(media_name) or item.get(name, default) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |         thumbnails = [] | 
					
						
							| 
									
										
										
										
											2015-12-21 11:12:58 +01:00
										 |  |  |         media_thumbnail = get_media_node('thumbnail') | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |         if media_thumbnail: | 
					
						
							|  |  |  |             if isinstance(media_thumbnail, dict): | 
					
						
							|  |  |  |                 media_thumbnail = [media_thumbnail] | 
					
						
							|  |  |  |             for thumbnail_data in media_thumbnail: | 
					
						
							| 
									
										
										
										
											2017-05-02 00:06:19 +01:00
										 |  |  |                 thumbnail = thumbnail_data.get('@attributes', {}) | 
					
						
							| 
									
										
										
										
											2018-07-21 19:08:28 +07:00
										 |  |  |                 thumbnail_url = url_or_none(thumbnail.get('url')) | 
					
						
							| 
									
										
										
										
											2017-05-02 00:06:19 +01:00
										 |  |  |                 if not thumbnail_url: | 
					
						
							|  |  |  |                     continue | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |                 thumbnails.append({ | 
					
						
							| 
									
										
										
										
											2017-05-02 00:06:19 +01:00
										 |  |  |                     'url': self._proto_relative_url(thumbnail_url, 'http:'), | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |                     'width': int_or_none(thumbnail.get('width')), | 
					
						
							|  |  |  |                     'height': int_or_none(thumbnail.get('height')), | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         subtitles = {} | 
					
						
							| 
									
										
										
										
											2015-12-21 11:12:58 +01:00
										 |  |  |         media_subtitle = get_media_node('subTitle') | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |         if media_subtitle: | 
					
						
							|  |  |  |             if isinstance(media_subtitle, dict): | 
					
						
							|  |  |  |                 media_subtitle = [media_subtitle] | 
					
						
							|  |  |  |             for subtitle_data in media_subtitle: | 
					
						
							| 
									
										
										
										
											2017-05-02 00:06:19 +01:00
										 |  |  |                 subtitle = subtitle_data.get('@attributes', {}) | 
					
						
							| 
									
										
										
										
											2018-07-21 19:08:28 +07:00
										 |  |  |                 subtitle_href = url_or_none(subtitle.get('href')) | 
					
						
							| 
									
										
										
										
											2017-05-02 00:06:19 +01:00
										 |  |  |                 if not subtitle_href: | 
					
						
							|  |  |  |                     continue | 
					
						
							|  |  |  |                 subtitles.setdefault(subtitle.get('lang') or 'en', []).append({ | 
					
						
							|  |  |  |                     'url': subtitle_href, | 
					
						
							|  |  |  |                     'ext': mimetype2ext(subtitle.get('type')) or determine_ext(subtitle_href), | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							| 
									
										
										
										
											2015-12-21 11:12:58 +01:00
										 |  |  |         media_content = get_media_node('content') | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |         if isinstance(media_content, dict): | 
					
						
							|  |  |  |             media_content = [media_content] | 
					
						
							|  |  |  |         for media_data in media_content: | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |             media = media_data.get('@attributes', {}) | 
					
						
							| 
									
										
										
										
											2018-07-21 19:08:28 +07:00
										 |  |  |             media_url = url_or_none(media.get('url')) | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |             if not media_url: | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2016-07-06 20:10:47 +08:00
										 |  |  |             ext = mimetype2ext(media.get('type')) or determine_ext(media_url) | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |             if ext == 'f4m': | 
					
						
							| 
									
										
										
										
											2015-12-29 00:58:24 +06:00
										 |  |  |                 formats.extend(self._extract_f4m_formats( | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |                     media_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124', | 
					
						
							| 
									
										
										
										
											2015-12-29 00:58:24 +06:00
										 |  |  |                     video_id, f4m_id='hds', fatal=False)) | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |             elif ext == 'm3u8': | 
					
						
							| 
									
										
										
										
											2015-12-29 00:58:24 +06:00
										 |  |  |                 formats.extend(self._extract_m3u8_formats( | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |                     media_url, video_id, 'mp4', m3u8_id='hls', fatal=False)) | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 formats.append({ | 
					
						
							| 
									
										
										
										
											2016-05-17 15:38:57 +08:00
										 |  |  |                     'format_id': media_data.get('media-category', {}).get('@attributes', {}).get('label'), | 
					
						
							| 
									
										
										
										
											2018-07-21 19:08:28 +07:00
										 |  |  |                     'url': media_url, | 
					
						
							| 
									
										
										
										
											2015-12-21 11:12:58 +01:00
										 |  |  |                     'tbr': int_or_none(media.get('bitrate')), | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |                     'filesize': int_or_none(media.get('fileSize')), | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |                     'ext': ext, | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |                 }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 01:13:47 +06:00
										 |  |  |         timestamp = parse_iso8601(item.get('pubDate'), ' ') or parse_iso8601(item.get('dc-date')) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2015-12-21 11:12:58 +01:00
										 |  |  |             'title': get_media_node('title'), | 
					
						
							|  |  |  |             'description': get_media_node('description'), | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |             'thumbnails': thumbnails, | 
					
						
							| 
									
										
										
										
											2016-03-28 01:13:47 +06:00
										 |  |  |             'timestamp': timestamp, | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |             'duration': int_or_none(media_content[0].get('@attributes', {}).get('duration')), | 
					
						
							| 
									
										
										
										
											2016-01-05 01:05:37 +06:00
										 |  |  |             'subtitles': subtitles, | 
					
						
							| 
									
										
										
										
											2015-11-07 16:54:35 +01:00
										 |  |  |             'formats': formats, | 
					
						
							|  |  |  |         } |