]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/downloader/dash.py
1 from __future__
import unicode_literals
6 from .fragment
import FragmentFD
13 class DashSegmentsFD(FragmentFD
):
15 Download segments in a DASH manifest
18 FD_NAME
= 'dashsegments'
20 def real_download(self
, filename
, info_dict
):
21 base_url
= info_dict
['url']
22 segment_urls
= [info_dict
['segment_urls'][0]] if self
.params
.get('test', False) else info_dict
['segment_urls']
23 initialization_url
= info_dict
.get('initialization_url')
27 'total_frags': len(segment_urls
) + (1 if initialization_url
else 0),
30 self
._prepare
_and
_start
_frag
_download
(ctx
)
32 def combine_url(base_url
, target_url
):
33 if re
.match(r
'^https?://', target_url
):
35 return '%s%s%s' % (base_url
, '' if base_url
.endswith('/') else '/', target_url
)
37 segments_filenames
= []
39 def append_url_to_file(target_url
, target_filename
):
40 success
= ctx
['dl'].download(target_filename
, {'url': combine_url(base_url
, target_url
)})
43 down
, target_sanitized
= sanitize_open(target_filename
, 'rb')
44 ctx
['dest_stream'].write(down
.read())
46 segments_filenames
.append(target_sanitized
)
48 if initialization_url
:
49 append_url_to_file(initialization_url
, ctx
['tmpfilename'] + '-Init')
50 for i
, segment_url
in enumerate(segment_urls
):
51 segment_filename
= '%s-Seg%d' % (ctx
['tmpfilename'], i
)
52 append_url_to_file(segment_url
, segment_filename
)
54 self
._finish
_frag
_download
(ctx
)
56 for segment_file
in segments_filenames
:
57 os
.remove(encodeFilename(segment_file
))