| 
									
										
										
										
											2014-01-27 05:47:30 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-23 17:59:27 +02:00
										 |  |  | from .common import FileDownloader | 
					
						
							| 
									
										
										
										
											2015-01-24 01:38:48 +01:00
										 |  |  | from .external import get_external_downloader | 
					
						
							|  |  |  | from .f4m import F4mFD | 
					
						
							| 
									
										
										
										
											2013-09-23 17:59:27 +02:00
										 |  |  | from .hls import HlsFD | 
					
						
							| 
									
										
										
										
											2014-09-24 14:16:56 +02:00
										 |  |  | from .hls import NativeHlsFD | 
					
						
							| 
									
										
										
										
											2013-09-23 17:59:27 +02:00
										 |  |  | from .http import HttpFD | 
					
						
							| 
									
										
										
										
											2015-04-26 00:25:51 +06:00
										 |  |  | from .rtsp import RtspFD | 
					
						
							| 
									
										
										
										
											2013-09-23 17:59:27 +02:00
										 |  |  | from .rtmp import RtmpFD | 
					
						
							| 
									
										
										
										
											2015-06-04 22:05:33 +08:00
										 |  |  | from .dash import DashSegmentsFD | 
					
						
							| 
									
										
										
										
											2013-09-23 17:59:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2015-01-23 23:50:31 +01:00
										 |  |  |     determine_protocol, | 
					
						
							| 
									
										
										
										
											2013-09-23 17:59:27 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 23:50:31 +01:00
										 |  |  | PROTOCOL_MAP = { | 
					
						
							|  |  |  |     'rtmp': RtmpFD, | 
					
						
							|  |  |  |     'm3u8_native': NativeHlsFD, | 
					
						
							|  |  |  |     'm3u8': HlsFD, | 
					
						
							| 
									
										
										
										
											2015-04-26 00:25:51 +06:00
										 |  |  |     'mms': RtspFD, | 
					
						
							|  |  |  |     'rtsp': RtspFD, | 
					
						
							| 
									
										
										
										
											2015-01-23 23:50:31 +01:00
										 |  |  |     'f4m': F4mFD, | 
					
						
							| 
									
										
										
										
											2015-06-04 22:27:29 +08:00
										 |  |  |     'http_dash_segments': DashSegmentsFD, | 
					
						
							| 
									
										
										
										
											2015-01-23 23:50:31 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-25 12:02:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 23:50:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | def get_suitable_downloader(info_dict, params={}): | 
					
						
							| 
									
										
										
										
											2013-09-23 17:59:27 +02:00
										 |  |  |     """Get the downloader class that can handle the info dict.""" | 
					
						
							| 
									
										
										
										
											2015-01-23 23:50:31 +01:00
										 |  |  |     protocol = determine_protocol(info_dict) | 
					
						
							|  |  |  |     info_dict['protocol'] = protocol | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-24 01:38:48 +01:00
										 |  |  |     external_downloader = params.get('external_downloader') | 
					
						
							|  |  |  |     if external_downloader is not None: | 
					
						
							|  |  |  |         ed = get_external_downloader(external_downloader) | 
					
						
							|  |  |  |         if ed.supports(info_dict): | 
					
						
							|  |  |  |             return ed | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-17 12:09:12 +01:00
										 |  |  |     if protocol == 'm3u8' and params.get('hls_prefer_native'): | 
					
						
							|  |  |  |         return NativeHlsFD | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 23:50:31 +01:00
										 |  |  |     return PROTOCOL_MAP.get(protocol, HttpFD) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-23 22:25:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | __all__ = [ | 
					
						
							|  |  |  |     'get_suitable_downloader', | 
					
						
							|  |  |  |     'FileDownloader', | 
					
						
							|  |  |  | ] |