2015-06-03 18:10:18 +03:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2021-07-31 13:51:01 +03:00
|
|
|
from ..downloader import get_suitable_downloader
|
2016-02-09 18:25:02 +02:00
|
|
|
from .fragment import FragmentFD
|
2021-02-08 18:46:01 +02:00
|
|
|
|
2021-06-21 21:59:50 +03:00
|
|
|
from ..utils import urljoin
|
2015-06-04 17:12:05 +03:00
|
|
|
|
2015-06-03 18:10:18 +03:00
|
|
|
|
2016-02-09 18:25:02 +02:00
|
|
|
class DashSegmentsFD(FragmentFD):
|
2015-06-03 18:10:18 +03:00
|
|
|
"""
|
2021-03-10 17:26:24 +02:00
|
|
|
Download segments in a DASH manifest. External downloaders can take over
|
2021-04-10 18:08:33 +03:00
|
|
|
the fragment downloads by supporting the 'dash_frag_urls' protocol
|
2015-06-03 18:10:18 +03:00
|
|
|
"""
|
|
|
|
|
2016-02-09 18:25:02 +02:00
|
|
|
FD_NAME = 'dashsegments'
|
2015-06-10 09:45:54 +03:00
|
|
|
|
2016-02-09 18:25:02 +02:00
|
|
|
def real_download(self, filename, info_dict):
|
2021-07-31 13:51:01 +03:00
|
|
|
if info_dict.get('is_live'):
|
|
|
|
self.report_error('Live DASH videos are not supported')
|
|
|
|
|
2017-08-05 02:57:19 +03:00
|
|
|
fragment_base_url = info_dict.get('fragment_base_url')
|
|
|
|
fragments = info_dict['fragments'][:1] if self.params.get(
|
2016-09-17 16:35:22 +03:00
|
|
|
'test', False) else info_dict['fragments']
|
2015-06-10 09:45:54 +03:00
|
|
|
|
2021-07-31 13:53:54 +03:00
|
|
|
real_downloader = get_suitable_downloader(
|
2021-08-01 10:22:09 +03:00
|
|
|
info_dict, self.params, None, protocol='dash_frag_urls', to_stdout=(filename == '-'))
|
2021-02-08 18:46:01 +02:00
|
|
|
|
2016-02-09 18:25:02 +02:00
|
|
|
ctx = {
|
|
|
|
'filename': filename,
|
2017-08-05 02:57:19 +03:00
|
|
|
'total_frags': len(fragments),
|
2016-02-09 18:25:02 +02:00
|
|
|
}
|
2015-06-10 09:45:54 +03:00
|
|
|
|
2021-02-08 18:46:01 +02:00
|
|
|
if real_downloader:
|
|
|
|
self._prepare_external_frag_download(ctx)
|
|
|
|
else:
|
2021-07-21 20:28:43 +03:00
|
|
|
self._prepare_and_start_frag_download(ctx, info_dict)
|
2015-06-03 18:10:18 +03:00
|
|
|
|
2021-03-10 17:26:24 +02:00
|
|
|
fragments_to_download = []
|
2016-06-28 20:07:50 +03:00
|
|
|
frag_index = 0
|
2017-08-05 02:57:19 +03:00
|
|
|
for i, fragment in enumerate(fragments):
|
2016-06-28 20:07:50 +03:00
|
|
|
frag_index += 1
|
2017-04-22 18:42:24 +03:00
|
|
|
if frag_index <= ctx['fragment_index']:
|
2016-06-28 20:07:50 +03:00
|
|
|
continue
|
2021-02-08 18:46:01 +02:00
|
|
|
fragment_url = fragment.get('url')
|
|
|
|
if not fragment_url:
|
|
|
|
assert fragment_base_url
|
|
|
|
fragment_url = urljoin(fragment_base_url, fragment['path'])
|
|
|
|
|
2021-03-13 06:46:58 +02:00
|
|
|
fragments_to_download.append({
|
|
|
|
'frag_index': frag_index,
|
|
|
|
'index': i,
|
|
|
|
'url': fragment_url,
|
|
|
|
})
|
2016-02-09 18:25:02 +02:00
|
|
|
|
2021-02-08 18:46:01 +02:00
|
|
|
if real_downloader:
|
2021-03-20 05:20:08 +02:00
|
|
|
self.to_screen(
|
|
|
|
'[%s] Fragment downloads will be delegated to %s' % (self.FD_NAME, real_downloader.get_basename()))
|
2021-02-08 18:46:01 +02:00
|
|
|
info_copy = info_dict.copy()
|
2021-03-10 17:26:24 +02:00
|
|
|
info_copy['fragments'] = fragments_to_download
|
2021-02-08 18:46:01 +02:00
|
|
|
fd = real_downloader(self.ydl, self.params)
|
2021-06-24 15:24:05 +03:00
|
|
|
return fd.real_download(filename, info_copy)
|
2021-06-24 19:53:33 +03:00
|
|
|
|
|
|
|
return self.download_and_append_fragments(ctx, fragments_to_download, info_dict)
|