| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  | from ..compat import compat_str | 
					
						
							| 
									
										
										
										
											2014-12-13 12:24:42 +01:00
										 |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |     ExtractorError, | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |     parse_iso8601, | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PlayFMIE(InfoExtractor): | 
					
						
							|  |  |  |     IE_NAME = 'play.fm' | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?play\.fm/(?P<slug>(?:[^/]+/)+(?P<id>[^/]+))/?(?:$|[?#])' | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |         'url': 'https://www.play.fm/dan-drastic/sven-tasnadi-leipzig-electronic-music-batofar-paris-fr-2014-07-12', | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |         'md5': 'c505f8307825a245d0c7ad1850001f22', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |             'id': '71276', | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |             'ext': 'mp3', | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |             'title': 'Sven Tasnadi - LEIPZIG ELECTRONIC MUSIC @ Batofar (Paris,FR) - 2014-07-12', | 
					
						
							|  |  |  |             'description': '', | 
					
						
							|  |  |  |             'duration': 5627, | 
					
						
							|  |  |  |             'timestamp': 1406033781, | 
					
						
							|  |  |  |             'upload_date': '20140722', | 
					
						
							|  |  |  |             'uploader': 'Dan Drastic', | 
					
						
							|  |  |  |             'uploader_id': '71170', | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |             'view_count': int, | 
					
						
							| 
									
										
										
										
											2014-09-22 18:58:22 +07:00
										 |  |  |             'comment_count': int, | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         mobj = re.match(self._VALID_URL, url) | 
					
						
							|  |  |  |         video_id = mobj.group('id') | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |         slug = mobj.group('slug') | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |         recordings = self._download_json( | 
					
						
							|  |  |  |             'http://v2api.play.fm/recordings/slug/%s' % slug, video_id) | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |         error = recordings.get('error') | 
					
						
							|  |  |  |         if isinstance(error, dict): | 
					
						
							|  |  |  |             raise ExtractorError( | 
					
						
							|  |  |  |                 '%s returned error: %s' % (self.IE_NAME, error.get('message')), | 
					
						
							|  |  |  |                 expected=True) | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |         audio_url = recordings['audio'] | 
					
						
							|  |  |  |         video_id = compat_str(recordings.get('id') or video_id) | 
					
						
							|  |  |  |         title = recordings['title'] | 
					
						
							|  |  |  |         description = recordings.get('description') | 
					
						
							|  |  |  |         duration = int_or_none(recordings.get('recordingDuration')) | 
					
						
							|  |  |  |         timestamp = parse_iso8601(recordings.get('created_at')) | 
					
						
							|  |  |  |         uploader = recordings.get('page', {}).get('title') | 
					
						
							|  |  |  |         uploader_id = compat_str(recordings.get('page', {}).get('id')) | 
					
						
							|  |  |  |         view_count = int_or_none(recordings.get('playCount')) | 
					
						
							|  |  |  |         comment_count = int_or_none(recordings.get('commentCount')) | 
					
						
							|  |  |  |         categories = [tag['name'] for tag in recordings.get('tags', []) if tag.get('name')] | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |             'url': audio_url, | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |             'description': description, | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |             'duration': duration, | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |             'timestamp': timestamp, | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |             'uploader': uploader, | 
					
						
							|  |  |  |             'uploader_id': uploader_id, | 
					
						
							| 
									
										
										
										
											2015-04-02 20:26:05 +06:00
										 |  |  |             'view_count': view_count, | 
					
						
							|  |  |  |             'comment_count': comment_count, | 
					
						
							|  |  |  |             'categories': categories, | 
					
						
							| 
									
										
										
										
											2014-08-22 17:34:50 +02:00
										 |  |  |         } |