1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-02-11 06:25:34 +08:00

[multipart] add simple implementation for a multipart downloader

This commit is contained in:
remitamine 2016-01-15 01:13:32 +01:00
parent 62b1a97496
commit f48137f157
3 changed files with 33 additions and 0 deletions

View File

@ -9,6 +9,7 @@ from .http import HttpFD
from .rtsp import RtspFD
from .rtmp import RtmpFD
from .dash import DashSegmentsFD
from .multipart import MultiPartFD
from ..utils import (
determine_protocol,
@ -22,6 +23,7 @@ PROTOCOL_MAP = {
'rtsp': RtspFD,
'f4m': F4mFD,
'http_dash_segments': DashSegmentsFD,
'multipart': MultiPartFD,
}

View File

@ -0,0 +1,29 @@
from __future__ import unicode_literals
from .common import FileDownloader
from ..utils import prepend_extension
class MultiPartFD(FileDownloader):
FD_NAME = 'multipart'
def real_download(self, filename, info_dict):
parts = info_dict['parts']
self.to_screen('[%s] Total parts: %d' % (self.FD_NAME, len(parts)))
for i in range(len(parts)):
fd = get_suitable_downloader(parts[i], self.params)(self.ydl, self.params)
frag_filename = prepend_extension(filename, 'part%d' % i)
success = fd.download(frag_filename, parts[i])
if not success:
return False
# We only download the first fragment during the test
if self.params.get('test', False):
break
return True
# workaround circular imports
from .__init__ import get_suitable_downloader

View File

@ -1891,6 +1891,8 @@ def determine_protocol(info_dict):
if protocol is not None:
return protocol
if 'parts' in info_dict:
return 'multipart'
url = info_dict['url']
if url.startswith('rtmp'):
return 'rtmp'