| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  | # coding: utf-8 | 
					
						
							| 
									
										
										
										
											2014-11-26 12:56:28 +01:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  | import re | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  | from ..utils import ExtractorError | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TriluliluIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |     _VALID_URL = r'https?://(?:www\.)?trilulilu\.ro/(?:video-[^/]+/)?(?P<id>[^/#\?]+)' | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |     _TEST = { | 
					
						
							| 
									
										
										
										
											2014-11-26 12:56:28 +01:00
										 |  |  |         'url': 'http://www.trilulilu.ro/video-animatie/big-buck-bunny-1', | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |         'md5': 'c1450a00da251e2769b74b9005601cac', | 
					
						
							| 
									
										
										
										
											2014-11-26 12:56:28 +01:00
										 |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |             'id': 'ae2899e124140b', | 
					
						
							| 
									
										
										
										
											2014-11-26 12:56:28 +01:00
										 |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Big Buck Bunny', | 
					
						
							|  |  |  |             'description': ':) pentru copilul din noi', | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |         display_id = self._match_id(url) | 
					
						
							|  |  |  |         webpage = self._download_webpage(url, display_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if re.search(r'Fişierul nu este disponibil pentru vizionare în ţara dumneavoastră', webpage): | 
					
						
							|  |  |  |             raise ExtractorError( | 
					
						
							|  |  |  |                 'This video is not available in your country.', expected=True) | 
					
						
							|  |  |  |         elif re.search('Fişierul poate fi accesat doar de către prietenii lui', webpage): | 
					
						
							|  |  |  |             raise ExtractorError('This video is private.', expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         flashvars_str = self._search_regex( | 
					
						
							|  |  |  |             r'block_flash_vars\s*=\s*(\{[^\}]+\})', webpage, 'flashvars', fatal=False, default=None) | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |         if flashvars_str: | 
					
						
							|  |  |  |             flashvars = self._parse_json(flashvars_str, display_id) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             raise ExtractorError( | 
					
						
							|  |  |  |                 'This page does not contain videos', expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if flashvars['isMP3'] == 'true': | 
					
						
							|  |  |  |             raise ExtractorError( | 
					
						
							|  |  |  |                 'Audio downloads are currently not supported', expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         video_id = flashvars['hash'] | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |         title = self._og_search_title(webpage) | 
					
						
							|  |  |  |         thumbnail = self._og_search_thumbnail(webpage) | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |         description = self._og_search_description(webpage, default=None) | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-26 12:56:28 +01:00
										 |  |  |         format_url = ('http://fs%(server)s.trilulilu.ro/%(hash)s/' | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |                       'video-formats2' % flashvars) | 
					
						
							| 
									
										
										
										
											2013-11-26 18:48:52 +01:00
										 |  |  |         format_doc = self._download_xml( | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |             format_url, video_id, | 
					
						
							| 
									
										
										
										
											2014-11-26 12:56:28 +01:00
										 |  |  |             note='Downloading formats', | 
					
						
							|  |  |  |             errnote='Error while downloading formats') | 
					
						
							| 
									
										
										
										
											2014-11-23 20:41:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |         video_url_template = ( | 
					
						
							| 
									
										
										
										
											2014-11-26 12:56:28 +01:00
										 |  |  |             'http://fs%(server)s.trilulilu.ro/stream.php?type=video' | 
					
						
							|  |  |  |             '&source=site&hash=%(hash)s&username=%(userid)s&' | 
					
						
							|  |  |  |             'key=ministhebest&format=%%s&sig=&exp=' % | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |             flashvars) | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |         formats = [ | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |                 'format_id': fnode.text.partition('-')[2], | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |                 'url': video_url_template % fnode.text, | 
					
						
							| 
									
										
										
										
											2013-09-14 14:45:04 +02:00
										 |  |  |                 'ext': fnode.text.partition('-')[0] | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for fnode in format_doc.findall('./formats/format') | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 14:21:06 +01:00
										 |  |  |         return { | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2015-02-09 16:55:31 +02:00
										 |  |  |             'display_id': display_id, | 
					
						
							| 
									
										
										
										
											2013-08-27 01:59:00 +02:00
										 |  |  |             'formats': formats, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'description': description, | 
					
						
							|  |  |  |             'thumbnail': thumbnail, | 
					
						
							|  |  |  |         } |