| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  | # -*- coding: utf-8 -*- | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  | from ..utils import ( | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							|  |  |  |     qualities, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WrzutaIE(InfoExtractor): | 
					
						
							|  |  |  |     IE_NAME = 'wrzuta.pl' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?P<uploader>[0-9a-zA-Z]+)\.wrzuta\.pl/(?P<typ>film|audio)/(?P<id>[0-9a-zA-Z]+)' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'http://laboratoriumdextera.wrzuta.pl/film/aq4hIZWrkBu/nike_football_the_last_game', | 
					
						
							|  |  |  |         'md5': '9e67e05bed7c03b82488d87233a9efe7', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': 'aq4hIZWrkBu', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Nike Football: The Last Game', | 
					
						
							|  |  |  |             'duration': 307, | 
					
						
							|  |  |  |             'uploader_id': 'laboratoriumdextera', | 
					
						
							|  |  |  |             'description': 'md5:7fb5ef3c21c5893375fda51d9b15d9cd', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }, { | 
					
						
							| 
									
										
										
										
											2014-11-11 16:23:06 +02:00
										 |  |  |         'url': 'http://jolka85.wrzuta.pl/audio/063jOPX5ue2/liber_natalia_szroeder_-_teraz_ty', | 
					
						
							|  |  |  |         'md5': 'bc78077859bea7bcfe4295d7d7fc9025', | 
					
						
							| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2014-11-11 16:23:06 +02:00
										 |  |  |             'id': '063jOPX5ue2', | 
					
						
							| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  |             'ext': 'ogg', | 
					
						
							| 
									
										
										
										
											2014-11-11 16:23:06 +02:00
										 |  |  |             'title': 'Liber & Natalia Szroeder - Teraz Ty', | 
					
						
							|  |  |  |             'duration': 203, | 
					
						
							|  |  |  |             'uploader_id': 'jolka85', | 
					
						
							|  |  |  |             'description': 'md5:2d2b6340f9188c8c4cd891580e481096', | 
					
						
							| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         mobj = re.match(self._VALID_URL, url) | 
					
						
							|  |  |  |         video_id = mobj.group('id') | 
					
						
							|  |  |  |         typ = mobj.group('typ') | 
					
						
							|  |  |  |         uploader = mobj.group('uploader') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         quality = qualities(['SD', 'MQ', 'HQ', 'HD']) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 16:47:54 +02:00
										 |  |  |         audio_table = {'flv': 'mp3', 'webm': 'ogg', '???': 'mp3'} | 
					
						
							| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         embedpage = self._download_json('http://www.wrzuta.pl/npp/embed/%s/%s' % (uploader, video_id), video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  |         for media in embedpage['url']: | 
					
						
							| 
									
										
										
										
											2014-11-11 16:23:06 +02:00
										 |  |  |             fmt = media['type'].split('@')[0] | 
					
						
							| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  |             if typ == 'audio': | 
					
						
							| 
									
										
										
										
											2014-11-11 16:23:06 +02:00
										 |  |  |                 ext = audio_table.get(fmt, fmt) | 
					
						
							| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2014-11-11 16:23:06 +02:00
										 |  |  |                 ext = fmt | 
					
						
							| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             formats.append({ | 
					
						
							|  |  |  |                 'format_id': '%s_%s' % (ext, media['quality'].lower()), | 
					
						
							|  |  |  |                 'url': media['url'], | 
					
						
							|  |  |  |                 'ext': ext, | 
					
						
							|  |  |  |                 'quality': quality(media['quality']), | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': self._og_search_title(webpage), | 
					
						
							|  |  |  |             'thumbnail': self._og_search_thumbnail(webpage), | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							|  |  |  |             'duration': int_or_none(embedpage['duration']), | 
					
						
							|  |  |  |             'uploader_id': uploader, | 
					
						
							|  |  |  |             'description': self._og_search_description(webpage), | 
					
						
							| 
									
										
										
										
											2014-06-14 17:00:59 +07:00
										 |  |  |             'age_limit': embedpage.get('minimalAge', 0), | 
					
						
							| 
									
										
										
										
											2014-06-13 08:51:35 +02:00
										 |  |  |         } |