1 from __future__ import unicode_literals
2 from .common import FileDownloader
3 from ..compat import compat_urllib_request
8 class DashSegmentsFD(FileDownloader):
10 Download segments in a DASH manifest
12 def real_download(self, filename, info_dict):
13 self.report_destination(filename)
14 tmpfilename = self.temp_name(filename)
15 base_url = info_dict['url']
16 segment_urls = info_dict['segment_urls']
20 def append_url_to_file(outf, target_url, target_name):
21 self.to_screen('[DashSegments] %s: Downloading %s' % (info_dict['id'], target_name))
22 req = compat_urllib_request.Request(target_url)
23 data = self.ydl.urlopen(req).read()
25 self.byte_counter += len(data)
27 def combine_url(base_url, target_url):
28 if re.match(r'^https?://', target_url):
30 return '%s/%s' % (base_url, target_url)
32 with open(tmpfilename, 'wb') as outf:
34 outf, combine_url(base_url, info_dict['initialization_url']),
35 'initialization segment')
36 for i, segment_url in enumerate(segment_urls):
38 outf, combine_url(base_url, segment_url),
39 'segment %d / %d' % (i + 1, len(segment_urls)))
41 self.try_rename(tmpfilename, filename)
44 'downloaded_bytes': self.byte_counter,
45 'total_bytes': self.byte_counter,