| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 22:01:15 +06:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-03-13 22:11:56 +06:00
										 |  |  | from ..compat import compat_str | 
					
						
							| 
									
										
										
										
											2015-03-13 22:01:15 +06:00
										 |  |  | from ..utils import int_or_none | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | class BeatportProIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2015-03-13 22:03:58 +06:00
										 |  |  |     _VALID_URL = r'https?://pro\.beatport\.com/track/(?P<display_id>[^/]+)/(?P<id>[0-9]+)' | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'https://pro.beatport.com/track/synesthesia-original-mix/5379371', | 
					
						
							|  |  |  |         'md5': 'b3c34d8639a2f6a7f734382358478887', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-03-13 22:13:50 +06:00
										 |  |  |             'id': '5379371', | 
					
						
							|  |  |  |             'display_id': 'synesthesia-original-mix', | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Froxic - Synesthesia (Original Mix)', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'https://pro.beatport.com/track/love-and-war-original-mix/3756896', | 
					
						
							|  |  |  |         'md5': 'e44c3025dfa38c6577fbaeb43da43514', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-03-13 22:13:50 +06:00
										 |  |  |             'id': '3756896', | 
					
						
							|  |  |  |             'display_id': 'love-and-war-original-mix', | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |             'ext': 'mp3', | 
					
						
							|  |  |  |             'title': 'Wolfgang Gartner - Love & War (Original Mix)', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'https://pro.beatport.com/track/birds-original-mix/4991738', | 
					
						
							|  |  |  |         'md5': 'a1fd8e8046de3950fd039304c186c05f', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-03-13 22:13:50 +06:00
										 |  |  |             'id': '4991738', | 
					
						
							|  |  |  |             'display_id': 'birds-original-mix', | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': "Tos, Middle Milk, Mumblin' Johnsson - Birds (Original Mix)", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2015-03-13 22:03:58 +06:00
										 |  |  |         mobj = re.match(self._VALID_URL, url) | 
					
						
							|  |  |  |         track_id = mobj.group('id') | 
					
						
							|  |  |  |         display_id = mobj.group('display_id') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         webpage = self._download_webpage(url, display_id) | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 22:11:56 +06:00
										 |  |  |         playables = self._parse_json( | 
					
						
							|  |  |  |             self._search_regex( | 
					
						
							|  |  |  |                 r'window\.Playables\s*=\s*({.+?});', webpage, | 
					
						
							|  |  |  |                 'playables info', flags=re.DOTALL), | 
					
						
							|  |  |  |             track_id) | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-12 16:42:55 -04:00
										 |  |  |         track = next(t for t in playables['tracks'] if t['id'] == int(track_id)) | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         title = ', '.join((a['name'] for a in track['artists'])) + ' - ' + track['name'] | 
					
						
							|  |  |  |         if track['mix']: | 
					
						
							|  |  |  |             title += ' (' + track['mix'] + ')' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							|  |  |  |         for ext, info in track['preview'].items(): | 
					
						
							| 
									
										
										
										
											2015-03-13 22:11:56 +06:00
										 |  |  |             if not info['url']: | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |                 continue | 
					
						
							|  |  |  |             fmt = { | 
					
						
							|  |  |  |                 'url': info['url'], | 
					
						
							|  |  |  |                 'ext': ext, | 
					
						
							|  |  |  |                 'format_id': ext, | 
					
						
							|  |  |  |                 'vcodec': 'none', | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ext == 'mp3': | 
					
						
							|  |  |  |                 fmt['preference'] = 0 | 
					
						
							|  |  |  |                 fmt['acodec'] = 'mp3' | 
					
						
							|  |  |  |                 fmt['abr'] = 96 | 
					
						
							|  |  |  |                 fmt['asr'] = 44100 | 
					
						
							|  |  |  |             elif ext == 'mp4': | 
					
						
							|  |  |  |                 fmt['preference'] = 1 | 
					
						
							|  |  |  |                 fmt['acodec'] = 'aac' | 
					
						
							|  |  |  |                 fmt['abr'] = 96 | 
					
						
							|  |  |  |                 fmt['asr'] = 44100 | 
					
						
							| 
									
										
										
										
											2015-03-13 22:01:15 +06:00
										 |  |  |             formats.append(fmt) | 
					
						
							| 
									
										
										
										
											2015-03-13 21:51:49 +06:00
										 |  |  |         self._sort_formats(formats) | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 22:01:15 +06:00
										 |  |  |         images = [] | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |         for name, info in track['images'].items(): | 
					
						
							| 
									
										
										
										
											2015-03-13 22:01:15 +06:00
										 |  |  |             image_url = info.get('url') | 
					
						
							|  |  |  |             if name == 'dynamic' or not image_url: | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2015-03-13 22:11:56 +06:00
										 |  |  |             image = { | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |                 'id': name, | 
					
						
							| 
									
										
										
										
											2015-03-13 22:01:15 +06:00
										 |  |  |                 'url': image_url, | 
					
						
							|  |  |  |                 'height': int_or_none(info.get('height')), | 
					
						
							|  |  |  |                 'width': int_or_none(info.get('width')), | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-03-13 22:11:56 +06:00
										 |  |  |             images.append(image) | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							| 
									
										
										
										
											2015-03-13 22:11:56 +06:00
										 |  |  |             'id': compat_str(track.get('id')) or track_id, | 
					
						
							| 
									
										
										
										
											2015-03-13 22:03:58 +06:00
										 |  |  |             'display_id': track.get('slug') or display_id, | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |             'title': title, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2015-03-13 22:01:15 +06:00
										 |  |  |             'thumbnails': images, | 
					
						
							| 
									
										
										
										
											2015-03-12 15:43:13 -04:00
										 |  |  |         } |