]>
Commit | Line | Data |
---|---|---|
654fd03c S |
1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
4 | ||
03339b7b | 5 | from .common import InfoExtractor |
654fd03c | 6 | from ..utils import ( |
9fbfc9bd | 7 | ExtractorError, |
654fd03c S |
8 | clean_html, |
9 | determine_ext, | |
10 | int_or_none, | |
11 | js_to_json, | |
12 | parse_duration, | |
13 | ) | |
03339b7b | 14 | |
654fd03c | 15 | |
67167920 | 16 | class ViewLiftBaseIE(InfoExtractor): |
17 | _DOMAINS_REGEX = '(?:snagfilms|snagxtreme|funnyforfree|kiddovid|winnersview|monumentalsportsnetwork|vayafilm)\.com|kesari\.tv' | |
18 | ||
19 | ||
20 | class ViewLiftEmbedIE(ViewLiftBaseIE): | |
21 | _VALID_URL = r'https?://(?:(?:www|embed)\.)?(?:%s)/embed/player\?.*\bfilmId=(?P<id>[\da-f-]{36})' % ViewLiftBaseIE._DOMAINS_REGEX | |
7d7d4690 | 22 | _TESTS = [{ |
654fd03c S |
23 | 'url': 'http://embed.snagfilms.com/embed/player?filmId=74849a00-85a9-11e1-9660-123139220831&w=500', |
24 | 'md5': '2924e9215c6eff7a55ed35b72276bd93', | |
25 | 'info_dict': { | |
7d7d4690 | 26 | 'id': '74849a00-85a9-11e1-9660-123139220831', |
7d7d4690 | 27 | 'ext': 'mp4', |
28 | 'title': '#whilewewatch', | |
7d7d4690 | 29 | } |
496ce6b3 S |
30 | }, { |
31 | # invalid labels, 360p is better that 480p | |
32 | 'url': 'http://www.snagfilms.com/embed/player?filmId=17ca0950-a74a-11e0-a92a-0026bb61d036', | |
33 | 'md5': '882fca19b9eb27ef865efeeaed376a48', | |
34 | 'info_dict': { | |
35 | 'id': '17ca0950-a74a-11e0-a92a-0026bb61d036', | |
36 | 'ext': 'mp4', | |
37 | 'title': 'Life in Limbo', | |
38 | } | |
654fd03c S |
39 | }, { |
40 | 'url': 'http://www.snagfilms.com/embed/player?filmId=0000014c-de2f-d5d6-abcf-ffef58af0017', | |
41 | 'only_matching': True, | |
7d7d4690 | 42 | }] |
03339b7b | 43 | |
7c197ad9 S |
44 | @staticmethod |
45 | def _extract_url(webpage): | |
46 | mobj = re.search( | |
67167920 | 47 | r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:embed\.)?(?:%s)/embed/player.+?)\1' % ViewLiftBaseIE._DOMAINS_REGEX, |
9fbfc9bd | 48 | webpage) |
7c197ad9 S |
49 | if mobj: |
50 | return mobj.group('url') | |
51 | ||
7e0480ae | 52 | def _real_extract(self, url): |
654fd03c S |
53 | video_id = self._match_id(url) |
54 | ||
55 | webpage = self._download_webpage(url, video_id) | |
03339b7b | 56 | |
9fbfc9bd S |
57 | if '>This film is not playable in your area.<' in webpage: |
58 | raise ExtractorError( | |
a42a1bb0 | 59 | 'Film %s is not playable in your area.' % video_id, expected=True) |
9fbfc9bd | 60 | |
7e0480ae | 61 | formats = [] |
67167920 | 62 | has_bitrate = False |
654fd03c S |
63 | for source in self._parse_json(js_to_json(self._search_regex( |
64 | r'(?s)sources:\s*(\[.+?\]),', webpage, 'json')), video_id): | |
65 | file_ = source.get('file') | |
66 | if not file_: | |
67 | continue | |
68 | type_ = source.get('type') | |
654fd03c | 69 | ext = determine_ext(file_) |
496ce6b3 | 70 | format_id = source.get('label') or ext |
67167920 | 71 | if all(v == 'm3u8' or v == 'hls' for v in (type_, ext)): |
654fd03c S |
72 | formats.extend(self._extract_m3u8_formats( |
73 | file_, video_id, 'mp4', m3u8_id='hls')) | |
7e0480ae | 74 | else: |
654fd03c | 75 | bitrate = int_or_none(self._search_regex( |
496ce6b3 S |
76 | [r'(\d+)kbps', r'_\d{1,2}x\d{1,2}_(\d{3,})\.%s' % ext], |
77 | file_, 'bitrate', default=None)) | |
67167920 | 78 | if not has_bitrate and bitrate: |
79 | has_bitrate = True | |
654fd03c S |
80 | height = int_or_none(self._search_regex( |
81 | r'^(\d+)[pP]$', format_id, 'height', default=None)) | |
82 | formats.append({ | |
83 | 'url': file_, | |
67167920 | 84 | 'format_id': 'http-%s%s' % (format_id, ('-%dk' % bitrate if bitrate else '')), |
654fd03c S |
85 | 'tbr': bitrate, |
86 | 'height': height, | |
87 | }) | |
67167920 | 88 | field_preference = None if has_bitrate else ('height', 'tbr', 'format_id') |
89 | self._sort_formats(formats, field_preference) | |
03339b7b | 90 | |
654fd03c S |
91 | title = self._search_regex( |
92 | [r"title\s*:\s*'([^']+)'", r'<title>([^<]+)</title>'], | |
93 | webpage, 'title') | |
94 | ||
7e0480ae | 95 | return { |
96 | 'id': video_id, | |
654fd03c S |
97 | 'title': title, |
98 | 'formats': formats, | |
99 | } | |
100 | ||
101 | ||
67167920 | 102 | class ViewLiftIE(ViewLiftBaseIE): |
103 | _VALID_URL = r'https?://(?:www\.)?(?P<domain>%s)/(?:films/title|show|(?:news/)?videos?)/(?P<id>[^?#]+)' % ViewLiftBaseIE._DOMAINS_REGEX | |
242a998b | 104 | _TESTS = [{ |
654fd03c S |
105 | 'url': 'http://www.snagfilms.com/films/title/lost_for_life', |
106 | 'md5': '19844f897b35af219773fd63bdec2942', | |
107 | 'info_dict': { | |
108 | 'id': '0000014c-de2f-d5d6-abcf-ffef58af0017', | |
109 | 'display_id': 'lost_for_life', | |
110 | 'ext': 'mp4', | |
111 | 'title': 'Lost for Life', | |
112 | 'description': 'md5:fbdacc8bb6b455e464aaf98bc02e1c82', | |
113 | 'thumbnail': 're:^https?://.*\.jpg', | |
114 | 'duration': 4489, | |
115 | 'categories': ['Documentary', 'Crime', 'Award Winning', 'Festivals'] | |
116 | } | |
242a998b S |
117 | }, { |
118 | 'url': 'http://www.snagfilms.com/show/the_world_cut_project/india', | |
119 | 'md5': 'e6292e5b837642bbda82d7f8bf3fbdfd', | |
120 | 'info_dict': { | |
121 | 'id': '00000145-d75c-d96e-a9c7-ff5c67b20000', | |
122 | 'display_id': 'the_world_cut_project/india', | |
123 | 'ext': 'mp4', | |
124 | 'title': 'India', | |
125 | 'description': 'md5:5c168c5a8f4719c146aad2e0dfac6f5f', | |
126 | 'thumbnail': 're:^https?://.*\.jpg', | |
127 | 'duration': 979, | |
128 | 'categories': ['Documentary', 'Sports', 'Politics'] | |
129 | } | |
a9de9517 S |
130 | }, { |
131 | # Film is not playable in your area. | |
132 | 'url': 'http://www.snagfilms.com/films/title/inside_mecca', | |
133 | 'only_matching': True, | |
134 | }, { | |
135 | # Film is not available. | |
136 | 'url': 'http://www.snagfilms.com/show/augie_alone/flirting', | |
137 | 'only_matching': True, | |
67167920 | 138 | }, { |
139 | 'url': 'http://www.winnersview.com/videos/the-good-son', | |
140 | 'only_matching': True, | |
141 | }, { | |
142 | 'url': 'http://www.kesari.tv/news/video/1461919076414', | |
143 | 'only_matching': True, | |
242a998b | 144 | }] |
654fd03c S |
145 | |
146 | def _real_extract(self, url): | |
67167920 | 147 | domain, display_id = re.match(self._VALID_URL, url).groups() |
654fd03c S |
148 | |
149 | webpage = self._download_webpage(url, display_id) | |
150 | ||
a42a1bb0 S |
151 | if ">Sorry, the Film you're looking for is not available.<" in webpage: |
152 | raise ExtractorError( | |
153 | 'Film %s is not available.' % display_id, expected=True) | |
154 | ||
654fd03c S |
155 | film_id = self._search_regex(r'filmId=([\da-f-]{36})"', webpage, 'film id') |
156 | ||
157 | snag = self._parse_json( | |
158 | self._search_regex( | |
159 | 'Snag\.page\.data\s*=\s*(\[.+?\]);', webpage, 'snag'), | |
160 | display_id) | |
161 | ||
162 | for item in snag: | |
163 | if item.get('data', {}).get('film', {}).get('id') == film_id: | |
164 | data = item['data']['film'] | |
165 | title = data['title'] | |
166 | description = clean_html(data.get('synopsis')) | |
167 | thumbnail = data.get('image') | |
168 | duration = int_or_none(data.get('duration') or data.get('runtime')) | |
169 | categories = [ | |
170 | category['title'] for category in data.get('categories', []) | |
171 | if category.get('title')] | |
172 | break | |
173 | else: | |
174 | title = self._search_regex( | |
175 | r'itemprop="title">([^<]+)<', webpage, 'title') | |
176 | description = self._html_search_regex( | |
177 | r'(?s)<div itemprop="description" class="film-synopsis-inner ">(.+?)</div>', | |
178 | webpage, 'description', default=None) or self._og_search_description(webpage) | |
179 | thumbnail = self._og_search_thumbnail(webpage) | |
180 | duration = parse_duration(self._search_regex( | |
181 | r'<span itemprop="duration" class="film-duration strong">([^<]+)<', | |
182 | webpage, 'duration', fatal=False)) | |
183 | categories = re.findall(r'<a href="/movies/[^"]+">([^<]+)</a>', webpage) | |
184 | ||
185 | return { | |
186 | '_type': 'url_transparent', | |
67167920 | 187 | 'url': 'http://%s/embed/player?filmId=%s' % (domain, film_id), |
654fd03c | 188 | 'id': film_id, |
7e0480ae | 189 | 'display_id': display_id, |
190 | 'title': title, | |
7e0480ae | 191 | 'description': description, |
7d7d4690 | 192 | 'thumbnail': thumbnail, |
654fd03c S |
193 | 'duration': duration, |
194 | 'categories': categories, | |
67167920 | 195 | 'ie_key': 'ViewLiftEmbed', |
7e0480ae | 196 | } |