| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  | # coding: utf-8 | 
					
						
							|  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2016-04-16 20:53:13 +01:00
										 |  |  | from ..utils import ( | 
					
						
							|  |  |  |     determine_ext, | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							| 
									
										
										
										
											2016-07-05 18:04:42 +01:00
										 |  |  |     float_or_none, | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |     mimetype2ext, | 
					
						
							| 
									
										
										
										
											2016-04-16 20:53:13 +01:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class OnionStudiosIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2017-10-12 16:05:25 +00:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?onionstudios\.com/(?:video(?:s/[^/]+-|/)|embed\?.*\bid=)(?P<id>\d+)(?!-)' | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     _TESTS = [{ | 
					
						
							|  |  |  |         'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937', | 
					
						
							| 
									
										
										
										
											2017-10-12 16:05:25 +00:00
										 |  |  |         'md5': '719d1f8c32094b8c33902c17bcae5e34', | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '2937', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Hannibal charges forward, stops for a cocktail', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg$', | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  |             'uploader': 'The A.V. Club', | 
					
						
							| 
									
										
										
										
											2016-07-05 18:04:42 +01:00
										 |  |  |             'uploader_id': 'the-av-club', | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  |         }, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2017-10-12 16:05:25 +00:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.onionstudios.com/video/6139.json', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  |     }] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 23:16:33 +06:00
										 |  |  |     @staticmethod | 
					
						
							|  |  |  |     def _extract_url(webpage): | 
					
						
							|  |  |  |         mobj = re.search( | 
					
						
							| 
									
										
										
										
											2017-10-12 16:05:25 +00:00
										 |  |  |             r'(?s)<(?:iframe|bulbs-video)[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?onionstudios\.com/(?:embed.+?|video/\d+\.json))\1', webpage) | 
					
						
							| 
									
										
										
										
											2015-06-24 23:16:33 +06:00
										 |  |  |         if mobj: | 
					
						
							|  |  |  |             return mobj.group('url') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  |     def _real_extract(self, url): | 
					
						
							|  |  |  |         video_id = self._match_id(url) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-05 18:04:42 +01:00
										 |  |  |         video_data = self._download_json( | 
					
						
							|  |  |  |             'http://www.onionstudios.com/video/%s.json' % video_id, video_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         title = video_data['title'] | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         formats = [] | 
					
						
							| 
									
										
										
										
											2016-07-05 18:04:42 +01:00
										 |  |  |         for source in video_data.get('sources', []): | 
					
						
							|  |  |  |             source_url = source.get('url') | 
					
						
							|  |  |  |             if not source_url: | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2016-07-06 09:11:46 +01:00
										 |  |  |             ext = mimetype2ext(source.get('content_type')) or determine_ext(source_url) | 
					
						
							|  |  |  |             if ext == 'm3u8': | 
					
						
							| 
									
										
										
										
											2016-04-16 20:53:13 +01:00
										 |  |  |                 formats.extend(self._extract_m3u8_formats( | 
					
						
							| 
									
										
										
										
											2016-07-05 18:04:42 +01:00
										 |  |  |                     source_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)) | 
					
						
							| 
									
										
										
										
											2016-04-16 20:53:13 +01:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2016-07-05 18:04:42 +01:00
										 |  |  |                 tbr = int_or_none(source.get('bitrate')) | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  |                 formats.append({ | 
					
						
							| 
									
										
										
										
											2016-07-05 18:04:42 +01:00
										 |  |  |                     'format_id': ext + ('-%d' % tbr if tbr else ''), | 
					
						
							|  |  |  |                     'url': source_url, | 
					
						
							|  |  |  |                     'width': int_or_none(source.get('width')), | 
					
						
							|  |  |  |                     'tbr': tbr, | 
					
						
							| 
									
										
										
										
											2016-04-16 20:53:13 +01:00
										 |  |  |                     'ext': ext, | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  |                 }) | 
					
						
							|  |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							| 
									
										
										
										
											2016-07-05 18:04:42 +01:00
										 |  |  |             'thumbnail': video_data.get('poster_url'), | 
					
						
							|  |  |  |             'uploader': video_data.get('channel_name'), | 
					
						
							|  |  |  |             'uploader_id': video_data.get('channel_slug'), | 
					
						
							|  |  |  |             'duration': float_or_none(video_data.get('duration', 1000)), | 
					
						
							|  |  |  |             'tags': video_data.get('tags'), | 
					
						
							| 
									
										
										
										
											2015-06-24 23:12:13 +06:00
										 |  |  |             'formats': formats, | 
					
						
							|  |  |  |         } |