"--write-to -" for writing to to STDOUT

This commit is contained in:
Ritiek Malhotra
2020-05-12 03:49:37 +05:30
parent a365746e45
commit 635c18723b
4 changed files with 53 additions and 33 deletions

View File

@@ -65,16 +65,19 @@ class Track:
total_chunks = self.calculate_total_chunks(stream["filesize"])
progress_bar = self.make_progress_bar(total_chunks)
response = stream["connection"]
if target_path == "-":
# Target is STDOUT
def writer(response, progress_bar, file_io):
for _ in progress_bar:
chunk = response.read(self._chunksize)
sys.stdout.buffer.write(chunk)
file_io.write(chunk)
write_to_stdout = target_path == "-"
if write_to_stdout:
file_io = sys.stdout.buffer
writer(response, progress_bar, file_io)
else:
with open(target_path, "wb") as fout:
for _ in progress_bar:
chunk = response.read(self._chunksize)
fout.write(chunk)
with open(target_path, "wb") as file_io:
writer(response, progress_bar, file_io)
def re_encode(self, input_path, target_path, target_encoding=None,
encoder=EncoderFFmpeg(), show_progress=True):