| 
									
										
										
										
											2014-02-10 20:48:46 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-23 22:59:51 +02:00
										 |  |  | import re | 
					
						
							| 
									
										
										
										
											2013-07-23 11:41:05 +02:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2013-06-23 22:59:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2014-10-03 19:37:47 +07:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							|  |  |  |     parse_age_limit, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2013-06-23 22:59:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BreakIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2014-10-03 18:57:18 +07:00
										 |  |  |     _VALID_URL = r'http://(?:www\.)?break\.com/video/(?:[^/]+/)*.+-(?P<id>\d+)' | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2014-02-10 20:48:46 +01:00
										 |  |  |         'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '2468056', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'When Girls Act Like D-Bags', | 
					
						
							| 
									
										
										
										
											2015-08-08 21:58:24 +06:00
										 |  |  |             'age_limit': 13, | 
					
						
							| 
									
										
										
										
											2013-06-27 20:46:46 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-10-03 18:57:18 +07:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.break.com/video/ugc/baby-flex-2773063', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }] | 
					
						
							| 
									
										
										
										
											2013-06-23 22:59:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2014-10-03 18:57:18 +07:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							|  |  |  |         webpage = self._download_webpage( | 
					
						
							|  |  |  |             'http://www.break.com/embed/%s' % video_id, video_id) | 
					
						
							|  |  |  |         info = json.loads(self._search_regex( | 
					
						
							|  |  |  |             r'var embedVars = ({.*})\s*?</script>', | 
					
						
							|  |  |  |             webpage, 'info json', flags=re.DOTALL)) | 
					
						
							| 
									
										
										
										
											2014-10-03 19:37:47 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-04 19:01:18 +02:00
										 |  |  |         youtube_id = info.get('youtubeId') | 
					
						
							|  |  |  |         if youtube_id: | 
					
						
							|  |  |  |             return self.url_result(youtube_id, 'Youtube') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-03 19:37:47 +07:00
										 |  |  |         formats = [{ | 
					
						
							|  |  |  |             'url': media['uri'] + '?' + info['AuthToken'], | 
					
						
							|  |  |  |             'tbr': media['bitRate'], | 
					
						
							|  |  |  |             'width': media['width'], | 
					
						
							|  |  |  |             'height': media['height'], | 
					
						
							| 
									
										
										
										
											2015-03-09 04:55:35 +06:00
										 |  |  |         } for media in info['media'] if media.get('mediaPurpose') == 'play'] | 
					
						
							| 
									
										
										
										
											2014-10-03 19:37:47 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if not formats: | 
					
						
							|  |  |  |             formats.append({ | 
					
						
							|  |  |  |                 'url': info['videoUri'] | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         duration = int_or_none(info.get('videoLengthInSeconds')) | 
					
						
							|  |  |  |         age_limit = parse_age_limit(info.get('audienceRating')) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-10 20:48:46 +01:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': info['contentName'], | 
					
						
							| 
									
										
										
										
											2013-07-23 11:41:05 +02:00
										 |  |  |             'thumbnail': info['thumbUri'], | 
					
						
							| 
									
										
										
										
											2014-10-03 19:37:47 +07:00
										 |  |  |             'duration': duration, | 
					
						
							|  |  |  |             'age_limit': age_limit, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2014-02-10 20:48:46 +01:00
										 |  |  |         } |