]>
Commit | Line | Data |
---|---|---|
6800d337 | 1 | from __future__ import unicode_literals |
6800d337 | 2 | |
5219cb3e | 3 | from ..downloader import _get_real_downloader |
c43fe026 | 4 | from .fragment import FragmentFD |
5219cb3e | 5 | |
4c7853de | 6 | from ..utils import urljoin |
453a1617 | 7 | |
6800d337 | 8 | |
c43fe026 | 9 | class DashSegmentsFD(FragmentFD): |
6800d337 | 10 | """ |
0a473f2f | 11 | Download segments in a DASH manifest. External downloaders can take over |
52a8a1e1 | 12 | the fragment downloads by supporting the 'dash_frag_urls' protocol |
6800d337 | 13 | """ |
6800d337 | 14 | |
c43fe026 | 15 | FD_NAME = 'dashsegments' |
5bf3276e | 16 | |
c43fe026 | 17 | def real_download(self, filename, info_dict): |
1141e910 S |
18 | fragment_base_url = info_dict.get('fragment_base_url') |
19 | fragments = info_dict['fragments'][:1] if self.params.get( | |
86f4d14f | 20 | 'test', False) else info_dict['fragments'] |
5bf3276e | 21 | |
52a8a1e1 | 22 | real_downloader = _get_real_downloader(info_dict, 'dash_frag_urls', self.params, None) |
5219cb3e | 23 | |
c43fe026 | 24 | ctx = { |
25 | 'filename': filename, | |
1141e910 | 26 | 'total_frags': len(fragments), |
c43fe026 | 27 | } |
5bf3276e | 28 | |
5219cb3e | 29 | if real_downloader: |
30 | self._prepare_external_frag_download(ctx) | |
31 | else: | |
32 | self._prepare_and_start_frag_download(ctx) | |
6800d337 | 33 | |
0a473f2f | 34 | fragments_to_download = [] |
75a24854 | 35 | frag_index = 0 |
1141e910 | 36 | for i, fragment in enumerate(fragments): |
75a24854 | 37 | frag_index += 1 |
3e0304fe | 38 | if frag_index <= ctx['fragment_index']: |
75a24854 | 39 | continue |
5219cb3e | 40 | fragment_url = fragment.get('url') |
41 | if not fragment_url: | |
42 | assert fragment_base_url | |
43 | fragment_url = urljoin(fragment_base_url, fragment['path']) | |
44 | ||
4cf1e5d2 | 45 | fragments_to_download.append({ |
46 | 'frag_index': frag_index, | |
47 | 'index': i, | |
48 | 'url': fragment_url, | |
49 | }) | |
c43fe026 | 50 | |
5219cb3e | 51 | if real_downloader: |
beb4b92a | 52 | self.to_screen( |
53 | '[%s] Fragment downloads will be delegated to %s' % (self.FD_NAME, real_downloader.get_basename())) | |
5219cb3e | 54 | info_copy = info_dict.copy() |
0a473f2f | 55 | info_copy['fragments'] = fragments_to_download |
5219cb3e | 56 | fd = real_downloader(self.ydl, self.params) |
57 | # TODO: Make progress updates work without hooking twice | |
58 | # for ph in self._progress_hooks: | |
59 | # fd.add_progress_hook(ph) | |
60 | success = fd.real_download(filename, info_copy) | |
61 | if not success: | |
62 | return False | |
63 | else: | |
4c7853de | 64 | self.download_and_append_fragments(ctx, fragments_to_download, info_dict) |
6800d337 | 65 | return True |