| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  | import json | 
					
						
							|  |  |  | import time | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  | from ..compat import compat_urllib_parse | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  |     sanitized_Request, | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class HypemIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  |     _VALID_URL = r'http://(?:www\.)?hypem\.com/track/(?P<id>[^/]+)/' | 
					
						
							| 
									
										
										
										
											2013-06-27 20:46:46 +02:00
										 |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |         'url': 'http://hypem.com/track/1v6ga/BODYWORK+-+TAME', | 
					
						
							|  |  |  |         'md5': 'b9cc91b5af8995e9f0c1cee04c575828', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '1v6ga', | 
					
						
							|  |  |  |             'ext': 'mp3', | 
					
						
							|  |  |  |             'title': 'Tame', | 
					
						
							|  |  |  |             'uploader': 'BODYWORK', | 
					
						
							| 
									
										
										
										
											2013-06-27 20:46:46 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  |         track_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-03 14:03:17 +01:00
										 |  |  |         data = {'ax': 1, 'ts': time.time()} | 
					
						
							| 
									
										
										
										
											2015-12-05 20:46:57 +06:00
										 |  |  |         request = sanitized_Request(url + '?' + compat_urllib_parse.urlencode(data)) | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |         response, urlh = self._download_webpage_handle( | 
					
						
							|  |  |  |             request, track_id, 'Downloading webpage with the url') | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |         html_tracks = self._html_search_regex( | 
					
						
							| 
									
										
										
										
											2015-12-05 20:46:57 +06:00
										 |  |  |             r'(?ms)<script type="application/json" id="displayList-data">(.+?)</script>', | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |             response, 'tracks') | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  |         try: | 
					
						
							|  |  |  |             track_list = json.loads(html_tracks) | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |             track = track_list['tracks'][0] | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  |         except ValueError: | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |             raise ExtractorError('Hypemachine contained invalid JSON.') | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |         key = track['key'] | 
					
						
							|  |  |  |         track_id = track['id'] | 
					
						
							|  |  |  |         title = track['song'] | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  |         request = sanitized_Request( | 
					
						
							| 
									
										
										
										
											2015-12-05 20:46:57 +06:00
										 |  |  |             'http://hypem.com/serve/source/%s/%s' % (track_id, key), | 
					
						
							|  |  |  |             '', {'Content-Type': 'application/json'}) | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |         song_data = self._download_json(request, track_id, 'Downloading metadata') | 
					
						
							| 
									
										
										
										
											2015-12-05 20:46:57 +06:00
										 |  |  |         final_url = song_data['url'] | 
					
						
							|  |  |  |         artist = track.get('artist') | 
					
						
							| 
									
										
										
										
											2013-06-23 22:29:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-09 22:30:57 +02:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': track_id, | 
					
						
							|  |  |  |             'url': final_url, | 
					
						
							|  |  |  |             'ext': 'mp3', | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'uploader': artist, | 
					
						
							|  |  |  |         } |