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/(?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']
95 def _real_extract(self, url):
96 display_id = self._match_id(url)
98 webpage = self._download_webpage(url, display_id)
100 film_id = self._search_regex(r'filmId=([\da-f-]{36})"', webpage, 'film id')
102 snag = self._parse_json(
104 'Snag\.page\.data\s*=\s*(\[.+?\]);', webpage, 'snag'),
108 if item.get('data', {}).get('film', {}).get('id') == film_id:
109 data = item['data']['film']
110 title = data['title']
111 description = clean_html(data.get('synopsis'))
112 thumbnail = data.get('image')
113 duration = int_or_none(data.get('duration') or data.get('runtime'))
115 category['title'] for category in data.get('categories', [])
116 if category.get('title')]
119 title = self._search_regex(
120 r'itemprop="title">([^<]+)<', webpage, 'title')
121 description = self._html_search_regex(
122 r'(?s)<div itemprop="description" class="film-synopsis-inner ">(.+?)</div>',
123 webpage, 'description', default=None) or self._og_search_description(webpage)
124 thumbnail = self._og_search_thumbnail(webpage)
125 duration = parse_duration(self._search_regex(
126 r'<span itemprop="duration" class="film-duration strong">([^<]+)<',
127 webpage, 'duration', fatal=False))
128 categories = re.findall(r'<a href="/movies/[^"]+">([^<]+)</a>', webpage)
131 '_type': 'url_transparent',
132 'url': 'http://embed.snagfilms.com/embed/player?filmId=%s' % film_id,
134 'display_id': display_id,
136 'description': description,
137 'thumbnail': thumbnail,
138 'duration': duration,
139 'categories': categories,