1 from __future__ import unicode_literals
5 from .common import FileDownloader
6 from ..compat import compat_urllib_request
9 class DashSegmentsFD(FileDownloader):
11 Download segments in a DASH manifest
13 def real_download(self, filename, info_dict):
14 self.report_destination(filename)
15 tmpfilename = self.temp_name(filename)
16 base_url = info_dict['url']
17 segment_urls = info_dict['segment_urls']
21 def append_url_to_file(outf, target_url, target_name):
22 self.to_screen('[DashSegments] %s: Downloading %s' % (info_dict['id'], target_name))
23 req = compat_urllib_request.Request(target_url)
24 data = self.ydl.urlopen(req).read()
26 self.byte_counter += len(data)
28 def combine_url(base_url, target_url):
29 if re.match(r'^https?://', target_url):
31 return '%s/%s' % (base_url, target_url)
33 with open(tmpfilename, 'wb') as outf:
35 outf, combine_url(base_url, info_dict['initialization_url']),
36 'initialization segment')
37 for i, segment_url in enumerate(segment_urls):
39 outf, combine_url(base_url, segment_url),
40 'segment %d / %d' % (i + 1, len(segment_urls)))
42 self.try_rename(tmpfilename, filename)
45 'downloaded_bytes': self.byte_counter,
46 'total_bytes': self.byte_counter,