1 from __future__ import unicode_literals
6 from .fragment import FragmentFD
8 from ..compat import compat_urlparse
15 class HlsFD(FragmentFD):
16 """ A limited implementation that does not require ffmpeg """
20 def real_download(self, filename, info_dict):
21 man_url = info_dict['url']
22 self.to_screen('[%s] Downloading m3u8 manifest' % self.FD_NAME)
23 manifest = self.ydl.urlopen(man_url).read()
25 s = manifest.decode('utf-8', 'ignore')
27 for line in s.splitlines():
29 if line and not line.startswith('#'):
32 if re.match(r'^https?://', line)
33 else compat_urlparse.urljoin(man_url, line))
34 fragment_urls.append(segment_url)
35 # We only download the first fragment during the test
36 if self.params.get('test', False):
41 'total_frags': len(fragment_urls),
44 self._prepare_and_start_frag_download(ctx)
47 for i, frag_url in enumerate(fragment_urls):
48 frag_filename = '%s-Frag%d' % (ctx['tmpfilename'], i)
49 success = ctx['dl'].download(frag_filename, {'url': frag_url})
52 down, frag_sanitized = sanitize_open(frag_filename, 'rb')
53 ctx['dest_stream'].write(down.read())
55 frags_filenames.append(frag_sanitized)
57 self._finish_frag_download(ctx)
59 for frag_file in frags_filenames:
60 os.remove(encodeFilename(frag_file))