added md5 calculation param for dash and http
This commit is contained in:
parent
076f3a7c9f
commit
25b73545c6
@ -341,7 +341,7 @@ class FileDownloader(object):
|
|||||||
|
|
||||||
return self.real_download(filename, info_dict, md5)
|
return self.real_download(filename, info_dict, md5)
|
||||||
|
|
||||||
def real_download(self, filename, info_dict, *args):
|
def real_download(self, filename, info_dict):
|
||||||
"""Real download process. Redefine in subclasses."""
|
"""Real download process. Redefine in subclasses."""
|
||||||
raise NotImplementedError('This method must be implemented by subclasses')
|
raise NotImplementedError('This method must be implemented by subclasses')
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
import hashlib
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ class DashSegmentsFD(FileDownloader):
|
|||||||
"""
|
"""
|
||||||
Download segments in a DASH manifest
|
Download segments in a DASH manifest
|
||||||
"""
|
"""
|
||||||
def real_download(self, filename, info_dict):
|
def real_download(self, filename, info_dict, md5=False):
|
||||||
self.report_destination(filename)
|
self.report_destination(filename)
|
||||||
tmpfilename = self.temp_name(filename)
|
tmpfilename = self.temp_name(filename)
|
||||||
base_url = info_dict['url']
|
base_url = info_dict['url']
|
||||||
@ -19,18 +20,20 @@ class DashSegmentsFD(FileDownloader):
|
|||||||
is_test = self.params.get('test', False)
|
is_test = self.params.get('test', False)
|
||||||
remaining_bytes = self._TEST_FILE_SIZE if is_test else None
|
remaining_bytes = self._TEST_FILE_SIZE if is_test else None
|
||||||
byte_counter = 0
|
byte_counter = 0
|
||||||
|
if md5:
|
||||||
|
m = hashlib.md5()
|
||||||
|
else:
|
||||||
|
m = None
|
||||||
def append_url_to_file(outf, target_url, target_name, remaining_bytes=None):
|
def append_url_to_file(outf, target_url, target_name, remaining_bytes=None):
|
||||||
self.to_screen('[DashSegments] %s: Downloading %s' % (info_dict['id'], target_name))
|
self.to_screen('[DashSegments] %s: Downloading %s' % (info_dict['id'], target_name))
|
||||||
req = compat_urllib_request.Request(target_url)
|
req = compat_urllib_request.Request(target_url)
|
||||||
if remaining_bytes is not None:
|
if remaining_bytes is not None:
|
||||||
req.add_header('Range', 'bytes=0-%d' % (remaining_bytes - 1))
|
req.add_header('Range', 'bytes=0-%d' % (remaining_bytes - 1))
|
||||||
|
|
||||||
data = self.ydl.urlopen(req).read()
|
data = self.ydl.urlopen(req).read()
|
||||||
|
|
||||||
if remaining_bytes is not None:
|
if remaining_bytes is not None:
|
||||||
data = data[:remaining_bytes]
|
data = data[:remaining_bytes]
|
||||||
|
if m is not None:
|
||||||
|
m.update(data)
|
||||||
outf.write(data)
|
outf.write(data)
|
||||||
return len(data)
|
return len(data)
|
||||||
|
|
||||||
@ -53,7 +56,8 @@ class DashSegmentsFD(FileDownloader):
|
|||||||
remaining_bytes -= segment_len
|
remaining_bytes -= segment_len
|
||||||
if remaining_bytes <= 0:
|
if remaining_bytes <= 0:
|
||||||
break
|
break
|
||||||
|
if m is not None:
|
||||||
|
open(filename, 'w').write(m.hexdigest())
|
||||||
self.try_rename(tmpfilename, filename)
|
self.try_rename(tmpfilename, filename)
|
||||||
|
|
||||||
self._hook_progress({
|
self._hook_progress({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user