| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  | # encoding: utf-8 | 
					
						
							|  |  |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | from .common import InfoExtractor | 
					
						
							|  |  |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |     clean_html, | 
					
						
							|  |  |  |  |     xpath_text, | 
					
						
							|  |  |  |  |     int_or_none, | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  | ) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-02 20:43:02 +01:00
										 |  |  |  | class NTVRuIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2015-02-02 21:48:54 +01:00
										 |  |  |  |     IE_NAME = 'ntv.ru' | 
					
						
							| 
									
										
										
										
											2016-03-21 21:36:32 +06:00
										 |  |  |  |     _VALID_URL = r'https?://(?:www\.)?ntv\.ru/(?P<id>.+)' | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     _TESTS = [ | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             'url': 'http://www.ntv.ru/novosti/863142/', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |             'md5': 'ba7ea172a91cb83eb734cad18c10e723', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |             'info_dict': { | 
					
						
							|  |  |  |  |                 'id': '746000', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |                 'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины', | 
					
						
							|  |  |  |  |                 'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'thumbnail': 're:^http://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |                 'duration': 136, | 
					
						
							|  |  |  |  |             }, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             'url': 'http://www.ntv.ru/video/novosti/750370/', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |             'md5': 'adecff79691b4d71e25220a191477124', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |             'info_dict': { | 
					
						
							|  |  |  |  |                 'id': '750370', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |                 'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход', | 
					
						
							|  |  |  |  |                 'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'thumbnail': 're:^http://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |                 'duration': 172, | 
					
						
							|  |  |  |  |             }, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |             'md5': '82dbd49b38e3af1d00df16acbeab260c', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |             'info_dict': { | 
					
						
							|  |  |  |  |                 'id': '747480', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'ext': 'mp4', | 
					
						
							|  |  |  |  |                 'title': '«Сегодня». 21 марта 2014 года. 16:00', | 
					
						
							|  |  |  |  |                 'description': '«Сегодня». 21 марта 2014 года. 16:00', | 
					
						
							|  |  |  |  |                 'thumbnail': 're:^http://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |                 'duration': 1496, | 
					
						
							|  |  |  |  |             }, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             'url': 'http://www.ntv.ru/kino/Koma_film', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |             'md5': 'f825770930937aa7e5aca0dc0d29319a', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |             'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'id': '1007609', | 
					
						
							|  |  |  |  |                 'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2014-04-08 19:11:40 +07:00
										 |  |  |  |                 'title': 'Остросюжетный фильм «Кома»', | 
					
						
							|  |  |  |  |                 'description': 'Остросюжетный фильм «Кома»', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'thumbnail': 're:^http://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2014-04-08 19:11:40 +07:00
										 |  |  |  |                 'duration': 5592, | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |             }, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |             'md5': '9320cd0e23f3ea59c330dc744e06ff3b', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |             'info_dict': { | 
					
						
							|  |  |  |  |                 'id': '751482', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'ext': 'mp4', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |                 'title': '«Дело врачей»: «Деревце жизни»', | 
					
						
							|  |  |  |  |                 'description': '«Дело врачей»: «Деревце жизни»', | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'thumbnail': 're:^http://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |                 'duration': 2590, | 
					
						
							|  |  |  |  |             }, | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |     ] | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     _VIDEO_ID_REGEXES = [ | 
					
						
							|  |  |  |  |         r'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)', | 
					
						
							|  |  |  |  |         r'<video embed=[^>]+><id>(\d+)</id>', | 
					
						
							| 
									
										
										
										
											2014-05-02 02:26:07 +07:00
										 |  |  |  |         r'<video restriction[^>]+><key>(\d+)</key>', | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |     ] | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2015-02-02 20:43:02 +01:00
										 |  |  |  |         video_id = self._match_id(url) | 
					
						
							| 
									
										
										
										
											2014-03-29 15:55:03 +07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |         video_id = self._html_search_regex(self._VIDEO_ID_REGEXES, webpage, 'video id') | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |         player = self._download_xml( | 
					
						
							|  |  |  |  |             'http://www.ntv.ru/vi%s/' % video_id, | 
					
						
							|  |  |  |  |             video_id, 'Downloading video XML') | 
					
						
							|  |  |  |  |         title = clean_html(xpath_text(player, './data/title', 'title', fatal=True)) | 
					
						
							|  |  |  |  |         description = clean_html(xpath_text(player, './data/description', 'description')) | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |         video = player.find('./data/video') | 
					
						
							|  |  |  |  |         video_id = xpath_text(video, './id', 'video id') | 
					
						
							|  |  |  |  |         thumbnail = xpath_text(video, './splash', 'thumbnail') | 
					
						
							|  |  |  |  |         duration = int_or_none(xpath_text(video, './totaltime', 'duration')) | 
					
						
							|  |  |  |  |         view_count = int_or_none(xpath_text(video, './views', 'view count')) | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |         token = self._download_webpage( | 
					
						
							|  |  |  |  |             'http://stat.ntv.ru/services/access/token', | 
					
						
							|  |  |  |  |             video_id, 'Downloading access token') | 
					
						
							| 
									
										
										
										
											2014-03-28 23:09:56 +07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |         formats = [] | 
					
						
							|  |  |  |  |         for format_id in ['', 'hi', 'webm']: | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |             file_ = video.find('./%sfile' % format_id) | 
					
						
							|  |  |  |  |             if file_ is None: | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |                 continue | 
					
						
							|  |  |  |  |             size = video.find('./%ssize' % format_id) | 
					
						
							|  |  |  |  |             formats.append({ | 
					
						
							| 
									
										
										
										
											2015-02-10 21:35:34 +06:00
										 |  |  |  |                 'url': 'http://media2.ntv.ru/vod/%s&tok=%s' % (file_.text, token), | 
					
						
							|  |  |  |  |                 'filesize': int_or_none(size.text if size is not None else None), | 
					
						
							| 
									
										
										
										
											2014-03-28 23:01:08 +07:00
										 |  |  |  |             }) | 
					
						
							|  |  |  |  |         self._sort_formats(formats) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         return { | 
					
						
							|  |  |  |  |             'id': video_id, | 
					
						
							|  |  |  |  |             'title': title, | 
					
						
							|  |  |  |  |             'description': description, | 
					
						
							|  |  |  |  |             'thumbnail': thumbnail, | 
					
						
							|  |  |  |  |             'duration': duration, | 
					
						
							|  |  |  |  |             'view_count': view_count, | 
					
						
							|  |  |  |  |             'formats': formats, | 
					
						
							| 
									
										
										
										
											2014-11-23 20:41:03 +01:00
										 |  |  |  |         } |