| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  | from __future__ import unicode_literals | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 18:25:43 +01:00
										 |  |  | from .common import InfoExtractor | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  | from ..utils import ( | 
					
						
							| 
									
										
										
										
											2015-06-27 18:50:26 +06:00
										 |  |  |     ExtractorError, | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |     clean_html, | 
					
						
							|  |  |  |     determine_ext, | 
					
						
							|  |  |  |     int_or_none, | 
					
						
							|  |  |  |     js_to_json, | 
					
						
							|  |  |  |     parse_duration, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2015-06-26 18:25:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  | class ViewLiftBaseIE(InfoExtractor): | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |     _DOMAINS_REGEX = r'(?:snagfilms|snagxtreme|funnyforfree|kiddovid|winnersview|monumentalsportsnetwork|vayafilm)\.com|kesari\.tv' | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ViewLiftEmbedIE(ViewLiftBaseIE): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:(?:www|embed)\.)?(?:%s)/embed/player\?.*\bfilmId=(?P<id>[\da-f-]{36})' % ViewLiftBaseIE._DOMAINS_REGEX | 
					
						
							| 
									
										
										
										
											2015-06-27 00:13:14 +01:00
										 |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |         'url': 'http://embed.snagfilms.com/embed/player?filmId=74849a00-85a9-11e1-9660-123139220831&w=500', | 
					
						
							|  |  |  |         'md5': '2924e9215c6eff7a55ed35b72276bd93', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							| 
									
										
										
										
											2015-06-27 00:13:14 +01:00
										 |  |  |             'id': '74849a00-85a9-11e1-9660-123139220831', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': '#whilewewatch', | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-21 23:54:31 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         # invalid labels, 360p is better that 480p | 
					
						
							|  |  |  |         'url': 'http://www.snagfilms.com/embed/player?filmId=17ca0950-a74a-11e0-a92a-0026bb61d036', | 
					
						
							|  |  |  |         'md5': '882fca19b9eb27ef865efeeaed376a48', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '17ca0950-a74a-11e0-a92a-0026bb61d036', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Life in Limbo', | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.snagfilms.com/embed/player?filmId=0000014c-de2f-d5d6-abcf-ffef58af0017', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2015-06-27 00:13:14 +01:00
										 |  |  |     }] | 
					
						
							| 
									
										
										
										
											2015-06-26 18:25:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 18:25:50 +06:00
										 |  |  |     @staticmethod | 
					
						
							|  |  |  |     def _extract_url(webpage): | 
					
						
							|  |  |  |         mobj = re.search( | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |             r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:embed\.)?(?:%s)/embed/player.+?)\1' % ViewLiftBaseIE._DOMAINS_REGEX, | 
					
						
							| 
									
										
										
										
											2015-06-27 18:50:26 +06:00
										 |  |  |             webpage) | 
					
						
							| 
									
										
										
										
											2015-06-27 18:25:50 +06:00
										 |  |  |         if mobj: | 
					
						
							|  |  |  |             return mobj.group('url') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 21:50:27 +01:00
										 |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |         video_id = self._match_id(url) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         webpage = self._download_webpage(url, video_id) | 
					
						
							| 
									
										
										
										
											2015-06-26 18:25:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 18:50:26 +06:00
										 |  |  |         if '>This film is not playable in your area.<' in webpage: | 
					
						
							|  |  |  |             raise ExtractorError( | 
					
						
							| 
									
										
										
										
											2015-06-27 18:54:08 +06:00
										 |  |  |                 'Film %s is not playable in your area.' % video_id, expected=True) | 
					
						
							| 
									
										
										
										
											2015-06-27 18:50:26 +06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 21:50:27 +01:00
										 |  |  |         formats = [] | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |         has_bitrate = False | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |         for source in self._parse_json(js_to_json(self._search_regex( | 
					
						
							|  |  |  |                 r'(?s)sources:\s*(\[.+?\]),', webpage, 'json')), video_id): | 
					
						
							|  |  |  |             file_ = source.get('file') | 
					
						
							|  |  |  |             if not file_: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             type_ = source.get('type') | 
					
						
							|  |  |  |             ext = determine_ext(file_) | 
					
						
							| 
									
										
										
										
											2015-07-21 23:54:31 +06:00
										 |  |  |             format_id = source.get('label') or ext | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |             if all(v == 'm3u8' or v == 'hls' for v in (type_, ext)): | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |                 formats.extend(self._extract_m3u8_formats( | 
					
						
							|  |  |  |                     file_, video_id, 'mp4', m3u8_id='hls')) | 
					
						
							| 
									
										
										
										
											2015-06-26 21:50:27 +01:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |                 bitrate = int_or_none(self._search_regex( | 
					
						
							| 
									
										
										
										
											2015-07-21 23:54:31 +06:00
										 |  |  |                     [r'(\d+)kbps', r'_\d{1,2}x\d{1,2}_(\d{3,})\.%s' % ext], | 
					
						
							|  |  |  |                     file_, 'bitrate', default=None)) | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |                 if not has_bitrate and bitrate: | 
					
						
							|  |  |  |                     has_bitrate = True | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |                 height = int_or_none(self._search_regex( | 
					
						
							|  |  |  |                     r'^(\d+)[pP]$', format_id, 'height', default=None)) | 
					
						
							|  |  |  |                 formats.append({ | 
					
						
							|  |  |  |                     'url': file_, | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |                     'format_id': 'http-%s%s' % (format_id, ('-%dk' % bitrate if bitrate else '')), | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |                     'tbr': bitrate, | 
					
						
							|  |  |  |                     'height': height, | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |         field_preference = None if has_bitrate else ('height', 'tbr', 'format_id') | 
					
						
							|  |  |  |         self._sort_formats(formats, field_preference) | 
					
						
							| 
									
										
										
										
											2015-06-26 18:25:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |         title = self._search_regex( | 
					
						
							|  |  |  |             [r"title\s*:\s*'([^']+)'", r'<title>([^<]+)</title>'], | 
					
						
							|  |  |  |             webpage, 'title') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-26 21:50:27 +01:00
										 |  |  |         return { | 
					
						
							|  |  |  |             'id': video_id, | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |             'title': title, | 
					
						
							|  |  |  |             'formats': formats, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  | class ViewLiftIE(ViewLiftBaseIE): | 
					
						
							|  |  |  |     _VALID_URL = r'https?://(?:www\.)?(?P<domain>%s)/(?:films/title|show|(?:news/)?videos?)/(?P<id>[^?#]+)' % ViewLiftBaseIE._DOMAINS_REGEX | 
					
						
							| 
									
										
										
										
											2015-06-27 18:40:01 +06:00
										 |  |  |     _TESTS = [{ | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |         'url': 'http://www.snagfilms.com/films/title/lost_for_life', | 
					
						
							|  |  |  |         'md5': '19844f897b35af219773fd63bdec2942', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '0000014c-de2f-d5d6-abcf-ffef58af0017', | 
					
						
							|  |  |  |             'display_id': 'lost_for_life', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'Lost for Life', | 
					
						
							|  |  |  |             'description': 'md5:fbdacc8bb6b455e464aaf98bc02e1c82', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |             'duration': 4489, | 
					
						
							|  |  |  |             'categories': ['Documentary', 'Crime', 'Award Winning', 'Festivals'] | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-27 18:40:01 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.snagfilms.com/show/the_world_cut_project/india', | 
					
						
							|  |  |  |         'md5': 'e6292e5b837642bbda82d7f8bf3fbdfd', | 
					
						
							|  |  |  |         'info_dict': { | 
					
						
							|  |  |  |             'id': '00000145-d75c-d96e-a9c7-ff5c67b20000', | 
					
						
							|  |  |  |             'display_id': 'the_world_cut_project/india', | 
					
						
							|  |  |  |             'ext': 'mp4', | 
					
						
							|  |  |  |             'title': 'India', | 
					
						
							|  |  |  |             'description': 'md5:5c168c5a8f4719c146aad2e0dfac6f5f', | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |             'thumbnail': r're:^https?://.*\.jpg', | 
					
						
							| 
									
										
										
										
											2015-06-27 18:40:01 +06:00
										 |  |  |             'duration': 979, | 
					
						
							|  |  |  |             'categories': ['Documentary', 'Sports', 'Politics'] | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-27 18:57:01 +06:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         # Film is not playable in your area. | 
					
						
							|  |  |  |         'url': 'http://www.snagfilms.com/films/title/inside_mecca', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         # Film is not available. | 
					
						
							|  |  |  |         'url': 'http://www.snagfilms.com/show/augie_alone/flirting', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.winnersview.com/videos/the-good-son', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							|  |  |  |     }, { | 
					
						
							|  |  |  |         'url': 'http://www.kesari.tv/news/video/1461919076414', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2016-06-01 19:18:01 +08:00
										 |  |  |     }, { | 
					
						
							|  |  |  |         # Was once Kaltura embed | 
					
						
							|  |  |  |         'url': 'https://www.monumentalsportsnetwork.com/videos/john-carlson-postgame-2-25-15', | 
					
						
							|  |  |  |         'only_matching': True, | 
					
						
							| 
									
										
										
										
											2015-06-27 18:40:01 +06:00
										 |  |  |     }] | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _real_extract(self, url): | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |         domain, display_id = re.match(self._VALID_URL, url).groups() | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         webpage = self._download_webpage(url, display_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 18:54:08 +06:00
										 |  |  |         if ">Sorry, the Film you're looking for is not available.<" in webpage: | 
					
						
							|  |  |  |             raise ExtractorError( | 
					
						
							|  |  |  |                 'Film %s is not available.' % display_id, expected=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |         film_id = self._search_regex(r'filmId=([\da-f-]{36})"', webpage, 'film id') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         snag = self._parse_json( | 
					
						
							|  |  |  |             self._search_regex( | 
					
						
							| 
									
										
										
										
											2017-01-02 20:08:07 +08:00
										 |  |  |                 r'Snag\.page\.data\s*=\s*(\[.+?\]);', webpage, 'snag'), | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |             display_id) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for item in snag: | 
					
						
							|  |  |  |             if item.get('data', {}).get('film', {}).get('id') == film_id: | 
					
						
							|  |  |  |                 data = item['data']['film'] | 
					
						
							|  |  |  |                 title = data['title'] | 
					
						
							|  |  |  |                 description = clean_html(data.get('synopsis')) | 
					
						
							|  |  |  |                 thumbnail = data.get('image') | 
					
						
							|  |  |  |                 duration = int_or_none(data.get('duration') or data.get('runtime')) | 
					
						
							|  |  |  |                 categories = [ | 
					
						
							|  |  |  |                     category['title'] for category in data.get('categories', []) | 
					
						
							|  |  |  |                     if category.get('title')] | 
					
						
							|  |  |  |                 break | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             title = self._search_regex( | 
					
						
							|  |  |  |                 r'itemprop="title">([^<]+)<', webpage, 'title') | 
					
						
							|  |  |  |             description = self._html_search_regex( | 
					
						
							|  |  |  |                 r'(?s)<div itemprop="description" class="film-synopsis-inner ">(.+?)</div>', | 
					
						
							|  |  |  |                 webpage, 'description', default=None) or self._og_search_description(webpage) | 
					
						
							|  |  |  |             thumbnail = self._og_search_thumbnail(webpage) | 
					
						
							|  |  |  |             duration = parse_duration(self._search_regex( | 
					
						
							|  |  |  |                 r'<span itemprop="duration" class="film-duration strong">([^<]+)<', | 
					
						
							|  |  |  |                 webpage, 'duration', fatal=False)) | 
					
						
							|  |  |  |             categories = re.findall(r'<a href="/movies/[^"]+">([^<]+)</a>', webpage) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |             '_type': 'url_transparent', | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |             'url': 'http://%s/embed/player?filmId=%s' % (domain, film_id), | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |             'id': film_id, | 
					
						
							| 
									
										
										
										
											2015-06-26 21:50:27 +01:00
										 |  |  |             'display_id': display_id, | 
					
						
							|  |  |  |             'title': title, | 
					
						
							|  |  |  |             'description': description, | 
					
						
							| 
									
										
										
										
											2015-06-27 00:13:14 +01:00
										 |  |  |             'thumbnail': thumbnail, | 
					
						
							| 
									
										
										
										
											2015-06-27 18:20:42 +06:00
										 |  |  |             'duration': duration, | 
					
						
							|  |  |  |             'categories': categories, | 
					
						
							| 
									
										
										
										
											2016-04-29 11:14:42 +01:00
										 |  |  |             'ie_key': 'ViewLiftEmbed', | 
					
						
							| 
									
										
										
										
											2015-06-26 21:50:27 +01:00
										 |  |  |         } |