1 from __future__ import unicode_literals
5 from .common import InfoExtractor
15 class SnagFilmsEmbedIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:(?:www|embed)\.)?snagfilms\.com/embed/player\?.*\bfilmId=(?P<id>[\da-f-]{36})'
18 'url': 'http://embed.snagfilms.com/embed/player?filmId=74849a00-85a9-11e1-9660-123139220831&w=500',
19 'md5': '2924e9215c6eff7a55ed35b72276bd93',
21 'id': '74849a00-85a9-11e1-9660-123139220831',
23 'title': '#whilewewatch',
26 'url': 'http://www.snagfilms.com/embed/player?filmId=0000014c-de2f-d5d6-abcf-ffef58af0017',
27 'only_matching': True,
31 def _extract_url(webpage):
33 r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:embed\.)?snagfilms\.com/embed/player.+?)\1', webpage)
35 return mobj.group('url')
37 def _real_extract(self, url):
38 video_id = self._match_id(url)
40 webpage = self._download_webpage(url, video_id)
43 for source in self._parse_json(js_to_json(self._search_regex(
44 r'(?s)sources:\s*(\[.+?\]),', webpage, 'json')), video_id):
45 file_ = source.get('file')
48 type_ = source.get('type')
49 format_id = source.get('label')
50 ext = determine_ext(file_)
51 if any(_ == 'm3u8' for _ in (type_, ext)):
52 formats.extend(self._extract_m3u8_formats(
53 file_, video_id, 'mp4', m3u8_id='hls'))
55 bitrate = int_or_none(self._search_regex(
56 r'(\d+)kbps', file_, 'bitrate', default=None))
57 height = int_or_none(self._search_regex(
58 r'^(\d+)[pP]$', format_id, 'height', default=None))
61 'format_id': format_id,
65 self._sort_formats(formats)
67 title = self._search_regex(
68 [r"title\s*:\s*'([^']+)'", r'<title>([^<]+)</title>'],
78 class SnagFilmsIE(InfoExtractor):
79 _VALID_URL = r'https?://(?:www\.)?snagfilms\.com/(?:films/title|show)/(?P<id>[^?#]+)'
81 'url': 'http://www.snagfilms.com/films/title/lost_for_life',
82 'md5': '19844f897b35af219773fd63bdec2942',
84 'id': '0000014c-de2f-d5d6-abcf-ffef58af0017',
85 'display_id': 'lost_for_life',
87 'title': 'Lost for Life',
88 'description': 'md5:fbdacc8bb6b455e464aaf98bc02e1c82',
89 'thumbnail': 're:^https?://.*\.jpg',
91 'categories': ['Documentary', 'Crime', 'Award Winning', 'Festivals']
94 'url': 'http://www.snagfilms.com/show/the_world_cut_project/india',
95 'md5': 'e6292e5b837642bbda82d7f8bf3fbdfd',
97 'id': '00000145-d75c-d96e-a9c7-ff5c67b20000',
98 'display_id': 'the_world_cut_project/india',
101 'description': 'md5:5c168c5a8f4719c146aad2e0dfac6f5f',
102 'thumbnail': 're:^https?://.*\.jpg',
104 'categories': ['Documentary', 'Sports', 'Politics']
108 def _real_extract(self, url):
109 display_id = self._match_id(url)
111 webpage = self._download_webpage(url, display_id)
113 film_id = self._search_regex(r'filmId=([\da-f-]{36})"', webpage, 'film id')
115 snag = self._parse_json(
117 'Snag\.page\.data\s*=\s*(\[.+?\]);', webpage, 'snag'),
121 if item.get('data', {}).get('film', {}).get('id') == film_id:
122 data = item['data']['film']
123 title = data['title']
124 description = clean_html(data.get('synopsis'))
125 thumbnail = data.get('image')
126 duration = int_or_none(data.get('duration') or data.get('runtime'))
128 category['title'] for category in data.get('categories', [])
129 if category.get('title')]
132 title = self._search_regex(
133 r'itemprop="title">([^<]+)<', webpage, 'title')
134 description = self._html_search_regex(
135 r'(?s)<div itemprop="description" class="film-synopsis-inner ">(.+?)</div>',
136 webpage, 'description', default=None) or self._og_search_description(webpage)
137 thumbnail = self._og_search_thumbnail(webpage)
138 duration = parse_duration(self._search_regex(
139 r'<span itemprop="duration" class="film-duration strong">([^<]+)<',
140 webpage, 'duration', fatal=False))
141 categories = re.findall(r'<a href="/movies/[^"]+">([^<]+)</a>', webpage)
144 '_type': 'url_transparent',
145 'url': 'http://embed.snagfilms.com/embed/player?filmId=%s' % film_id,
147 'display_id': display_id,
149 'description': description,
150 'thumbnail': thumbnail,
151 'duration': duration,
152 'categories': categories,