Wrapper over youtube-dl for searching and batch downloading bilibili videos.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.5 KiB

--- http.py 2020-09-06 12:40:29.065733507 -0400
+++ http.py.modified 2020-09-06 12:41:50.335728741 -0400
@@ -39,11 +39,15 @@
ctx.stream = None
# Do not include the Accept-Encoding header
- headers = {'Youtubedl-no-compression': 'True'}
+ headers = {}
add_headers = info_dict.get('http_headers')
+ print("add_headers: ", add_headers)
+
if add_headers:
headers.update(add_headers)
+ print("headers: ", headers)
+ print("url: ", url)
is_test = self.params.get('test', False)
chunk_size = self._TEST_FILE_SIZE if is_test else (
info_dict.get('downloader_options', {}).get('http_chunk_size')
@@ -188,6 +192,7 @@
def download():
data_len = ctx.data.info().get('Content-length', None)
+ print("data_len: ", data_len)
# Range HTTP header may be ignored/unsupported by a webserver
# (e.g. extractor/scivee.py, extractor/bambuser.py).
@@ -218,7 +223,7 @@
def retry(e):
to_stdout = ctx.tmpfilename == '-'
- if not to_stdout:
+ if not to_stdout and ctx.stream is not None:
ctx.stream.close()
ctx.stream = None
ctx.resume_len = byte_counter if to_stdout else os.path.getsize(encodeFilename(ctx.tmpfilename))
@@ -238,6 +243,7 @@
retry(e)
byte_counter += len(data_block)
+ print("byte_counter: ", byte_counter)
# exit loop when download is finished
if len(data_block) == 0:
@@ -307,18 +313,31 @@
# ctx.block_size = block_size
raise NextFragment()
- if ctx.stream is None:
- self.to_stderr('\n')
- self.report_error('Did not get any data blocks')
- return False
- if ctx.tmpfilename != '-':
- ctx.stream.close()
-
- if data_len is not None and byte_counter != data_len:
- err = ContentTooShortError(byte_counter, int(data_len))
- if count <= retries:
- retry(err)
- raise err
+ # Deal with bilibili last fragment shorter than expected length
+ if info_dict.get('extractor') == 'BiliBili' and info_dict.get('n_entries', 1) > 1 \
+ and info_dict.get('n_entries', 0) == info_dict.get('playlist_index', -1):
+ if ctx.stream is None:
+ self.to_stderr('\nDid not get any data blocks')
+ elif ctx.tmpfilename != '-':
+ ctx.stream.close()
+
+ if data_len is not None and byte_counter != data_len:
+ err = ContentTooShortError(byte_counter, int(data_len))
+ if count <= retries:
+ retry(err)
+ else:
+ if ctx.stream is None:
+ self.to_stderr('\n')
+ self.report_error('Did not get any data blocks')
+ return False
+ if ctx.tmpfilename != '-':
+ ctx.stream.close()
+
+ if data_len is not None and byte_counter != data_len:
+ err = ContentTooShortError(byte_counter, int(data_len))
+ if count <= retries:
+ retry(err)
+ raise err
self.try_rename(ctx.tmpfilename, ctx.filename)