| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-26 18:38:48 -07:00
										 |  |  | import base64 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  | from ..compat import compat_urllib_parse | 
					
						
							| 
									
										
										
										
											2014-11-26 12:45:40 +01:00
										 |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |     ExtractorError, | 
					
						
							|  |  |  |     HEADRequest, | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  |     sanitized_Request, | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2013-06-26 18:38:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class HotNewHipHopIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2016-03-21 21:36:32 +06:00
										 |  |  |     _VALID_URL = r'https?://www\.hotnewhiphop\.com/.*\.(?P<id>.*)\.html' | 
					
						
							| 
									
										
										
										
											2013-06-27 20:46:46 +02:00
										 |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |         'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html', | 
					
						
							|  |  |  |         'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2014-11-26 12:45:40 +01:00
										 |  |  |             'id': '1435540', | 
					
						
							|  |  |  |             'ext': 'mp3', | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |             'title': 'Freddie Gibbs - Lay It Down' | 
					
						
							| 
									
										
										
										
											2013-06-27 20:46:46 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-26 18:38:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-11-26 12:45:40 +01:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							|  |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							| 
									
										
										
										
											2013-06-26 18:38:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |         video_url_base64 = self._search_regex( | 
					
						
							| 
									
										
										
										
											2014-11-26 12:45:40 +01:00
										 |  |  |             r'data-path="(.*?)"', webpage, 'video URL', default=None) | 
					
						
							| 
									
										
										
										
											2013-06-27 08:39:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |         if video_url_base64 is None: | 
					
						
							|  |  |  |             video_url = self._search_regex( | 
					
						
							| 
									
										
										
										
											2014-11-26 12:45:40 +01:00
										 |  |  |                 r'"contentUrl" content="(.*?)"', webpage, 'content URL') | 
					
						
							| 
									
										
										
										
											2013-06-27 08:39:32 -07:00
										 |  |  |             return self.url_result(video_url, ie='Youtube') | 
					
						
							| 
									
										
										
										
											2013-06-26 18:38:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |         reqdata = compat_urllib_parse.urlencode([ | 
					
						
							|  |  |  |             ('mediaType', 's'), | 
					
						
							|  |  |  |             ('mediaId', video_id), | 
					
						
							|  |  |  |         ]) | 
					
						
							| 
									
										
										
										
											2015-11-21 22:18:17 +06:00
										 |  |  |         r = sanitized_Request( | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |             'http://www.hotnewhiphop.com/ajax/media/getActions/', data=reqdata) | 
					
						
							|  |  |  |         r.add_header('Content-Type', 'application/x-www-form-urlencoded') | 
					
						
							|  |  |  |         mkd = self._download_json( | 
					
						
							|  |  |  |             r, video_id, note='Requesting media key', | 
					
						
							|  |  |  |             errnote='Could not download media key') | 
					
						
							|  |  |  |         if 'mediaKey' not in mkd: | 
					
						
							|  |  |  |             raise ExtractorError('Did not get a media key') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         redirect_url = base64.b64decode(video_url_base64).decode('utf-8') | 
					
						
							|  |  |  |         redirect_req = HEADRequest(redirect_url) | 
					
						
							|  |  |  |         req = self._request_webpage( | 
					
						
							|  |  |  |             redirect_req, video_id, | 
					
						
							|  |  |  |             note='Resolving final URL', errnote='Could not resolve final URL') | 
					
						
							|  |  |  |         video_url = req.geturl() | 
					
						
							|  |  |  |         if video_url.endswith('.html'): | 
					
						
							|  |  |  |             raise ExtractorError('Redirect failed') | 
					
						
							| 
									
										
										
										
											2013-06-26 18:38:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-26 12:45:40 +01:00
										 |  |  |         video_title = self._og_search_title(webpage).strip() | 
					
						
							| 
									
										
										
										
											2013-06-26 18:38:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'url': video_url, | 
					
						
							|  |  |  |             'title': video_title, | 
					
						
							| 
									
										
										
										
											2014-11-26 12:45:40 +01:00
										 |  |  |             'thumbnail': self._og_search_thumbnail(webpage), | 
					
						
							| 
									
										
										
										
											2014-01-22 01:55:50 +01:00
										 |  |  |         } |