]> jfr.im git - yt-dlp.git/blob - yt_dlp/downloader/dash.py
881ef3a1d3d6380c398689c1885d3f8c285dd8a9
[yt-dlp.git] / yt_dlp / downloader / dash.py
1 from __future__ import unicode_literals
2
3 from ..downloader import get_suitable_downloader
4 from .fragment import FragmentFD
5
6 from ..utils import urljoin
7
8
9 class DashSegmentsFD(FragmentFD):
10 """
11 Download segments in a DASH manifest. External downloaders can take over
12 the fragment downloads by supporting the 'dash_frag_urls' protocol
13 """
14
15 FD_NAME = 'dashsegments'
16
17 def real_download(self, filename, info_dict):
18 if info_dict.get('is_live'):
19 self.report_error('Live DASH videos are not supported')
20
21 fragment_base_url = info_dict.get('fragment_base_url')
22 fragments = info_dict['fragments'][:1] if self.params.get(
23 'test', False) else info_dict['fragments']
24
25 real_downloader = get_suitable_downloader(
26 info_dict, self.params, None, protocol='dash_frag_urls', to_stdout=(filename== '-'))
27
28 ctx = {
29 'filename': filename,
30 'total_frags': len(fragments),
31 }
32
33 if real_downloader:
34 self._prepare_external_frag_download(ctx)
35 else:
36 self._prepare_and_start_frag_download(ctx, info_dict)
37
38 fragments_to_download = []
39 frag_index = 0
40 for i, fragment in enumerate(fragments):
41 frag_index += 1
42 if frag_index <= ctx['fragment_index']:
43 continue
44 fragment_url = fragment.get('url')
45 if not fragment_url:
46 assert fragment_base_url
47 fragment_url = urljoin(fragment_base_url, fragment['path'])
48
49 fragments_to_download.append({
50 'frag_index': frag_index,
51 'index': i,
52 'url': fragment_url,
53 })
54
55 if real_downloader:
56 self.to_screen(
57 '[%s] Fragment downloads will be delegated to %s' % (self.FD_NAME, real_downloader.get_basename()))
58 info_copy = info_dict.copy()
59 info_copy['fragments'] = fragments_to_download
60 fd = real_downloader(self.ydl, self.params)
61 return fd.real_download(filename, info_copy)
62
63 return self.download_and_append_fragments(ctx, fragments_to_download, info_dict)