| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2016-10-09 01:02:35 +07:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     qualities, | 
					
						
							|  |  |  |     str_or_none, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ReverbNationIE(InfoExtractor): | 
					
						
							|  |  |  |     _VALID_URL = r'^https?://(?:www\.)?reverbnation\.com/.*?/song/(?P<id>\d+).*?$' | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'http://www.reverbnation.com/alkilados/song/16965047-mona-lisa', | 
					
						
							| 
									
										
										
										
											2016-09-30 19:54:12 +02:00
										 |  |  |         'md5': 'c0aaf339bcee189495fdf5a8c8ba8645', | 
					
						
							| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2016-02-14 15:37:17 +06:00
										 |  |  |             'id': '16965047', | 
					
						
							|  |  |  |             'ext': 'mp3', | 
					
						
							|  |  |  |             'title': 'MONA LISA', | 
					
						
							|  |  |  |             'uploader': 'ALKILADOS', | 
					
						
							|  |  |  |             'uploader_id': '216429', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2016-09-30 19:54:12 +02:00
										 |  |  |         song_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         api_res = self._download_json( | 
					
						
							| 
									
										
										
										
											2014-08-10 10:58:22 +02:00
										 |  |  |             'https://api.reverbnation.com/song/%s' % song_id, | 
					
						
							| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  |             song_id, | 
					
						
							|  |  |  |             note='Downloading information of song %s' % song_id | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-09 01:02:35 +07:00
										 |  |  |         THUMBNAILS = ('thumbnail', 'image') | 
					
						
							|  |  |  |         quality = qualities(THUMBNAILS) | 
					
						
							| 
									
										
										
										
											2016-09-30 19:54:12 +02:00
										 |  |  |         thumbnails = [] | 
					
						
							| 
									
										
										
										
											2016-10-09 01:02:35 +07:00
										 |  |  |         for thumb_key in THUMBNAILS: | 
					
						
							|  |  |  |             if api_res.get(thumb_key): | 
					
						
							|  |  |  |                 thumbnails.append({ | 
					
						
							|  |  |  |                     'url': api_res[thumb_key], | 
					
						
							|  |  |  |                     'preference': quality(thumb_key) | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2016-09-30 19:54:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': song_id, | 
					
						
							| 
									
										
										
										
											2016-09-30 19:54:12 +02:00
										 |  |  |             'title': api_res['name'], | 
					
						
							|  |  |  |             'url': api_res['url'], | 
					
						
							| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  |             'uploader': api_res.get('artist', {}).get('name'), | 
					
						
							| 
									
										
										
										
											2014-08-10 11:00:14 +02:00
										 |  |  |             'uploader_id': str_or_none(api_res.get('artist', {}).get('id')), | 
					
						
							| 
									
										
										
										
											2016-09-30 19:54:12 +02:00
										 |  |  |             'thumbnails': thumbnails, | 
					
						
							| 
									
										
										
										
											2014-07-10 04:10:02 +02:00
										 |  |  |             'ext': 'mp3', | 
					
						
							|  |  |  |             'vcodec': 'none', | 
					
						
							|  |  |  |         } |