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,
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
33 webpage = self._download_webpage(url, video_id)
36 for source in self._parse_json(js_to_json(self._search_regex(
37 r'(?s)sources:\s*(\[.+?\]),', webpage, 'json')), video_id):
38 file_ = source.get('file')
41 type_ = source.get('type')
42 format_id = source.get('label')
43 ext = determine_ext(file_)
44 if any(_ == 'm3u8' for _ in (type_, ext)):
45 formats.extend(self._extract_m3u8_formats(
46 file_, video_id, 'mp4', m3u8_id='hls'))
48 bitrate = int_or_none(self._search_regex(
49 r'(\d+)kbps', file_, 'bitrate', default=None))
50 height = int_or_none(self._search_regex(
51 r'^(\d+)[pP]$', format_id, 'height', default=None))
54 'format_id': format_id,
58 self._sort_formats(formats)
60 title = self._search_regex(
61 [r"title\s*:\s*'([^']+)'", r'<title>([^<]+)</title>'],
71 class SnagFilmsIE(InfoExtractor):
72 _VALID_URL = r'https?://(?:www\.)?snagfilms\.com/films/title/(?P<id>[^/]+)'
74 'url': 'http://www.snagfilms.com/films/title/lost_for_life',
75 'md5': '19844f897b35af219773fd63bdec2942',
77 'id': '0000014c-de2f-d5d6-abcf-ffef58af0017',
78 'display_id': 'lost_for_life',
80 'title': 'Lost for Life',
81 'description': 'md5:fbdacc8bb6b455e464aaf98bc02e1c82',
82 'thumbnail': 're:^https?://.*\.jpg',
84 'categories': ['Documentary', 'Crime', 'Award Winning', 'Festivals']
88 def _real_extract(self, url):
89 display_id = self._match_id(url)
91 webpage = self._download_webpage(url, display_id)
93 film_id = self._search_regex(r'filmId=([\da-f-]{36})"', webpage, 'film id')
95 snag = self._parse_json(
97 'Snag\.page\.data\s*=\s*(\[.+?\]);', webpage, 'snag'),
101 if item.get('data', {}).get('film', {}).get('id') == film_id:
102 data = item['data']['film']
103 title = data['title']
104 description = clean_html(data.get('synopsis'))
105 thumbnail = data.get('image')
106 duration = int_or_none(data.get('duration') or data.get('runtime'))
108 category['title'] for category in data.get('categories', [])
109 if category.get('title')]
112 title = self._search_regex(
113 r'itemprop="title">([^<]+)<', webpage, 'title')
114 description = self._html_search_regex(
115 r'(?s)<div itemprop="description" class="film-synopsis-inner ">(.+?)</div>',
116 webpage, 'description', default=None) or self._og_search_description(webpage)
117 thumbnail = self._og_search_thumbnail(webpage)
118 duration = parse_duration(self._search_regex(
119 r'<span itemprop="duration" class="film-duration strong">([^<]+)<',
120 webpage, 'duration', fatal=False))
121 categories = re.findall(r'<a href="/movies/[^"]+">([^<]+)</a>', webpage)
124 '_type': 'url_transparent',
125 'url': 'http://embed.snagfilms.com/embed/player?filmId=%s' % film_id,
127 'display_id': display_id,
129 'description': description,
130 'thumbnail': thumbnail,
131 'duration': duration,
132 'categories': categories,