コード例 #1
0
def _download(stream: Stream,
              target: Optional[str] = None,
              filename: Optional[str] = None) -> None:
    filesize_megabytes = stream.filesize // 1048576
    print(f"{filename or stream.default_filename} | {filesize_megabytes} MB")
    file_path = stream.get_file_path(filename=filename, output_path=target)
    if stream.exists_at_path(file_path):
        print(f"Already downloaded at:\n{file_path}")
        return

    stream.download(output_path=target, filename=filename)
    sys.stdout.write("\n")
コード例 #2
0
def download_stream(yt: YouTube, stream: Stream):

    with progressbar.DataTransferBar(max_value=stream.filesize) as bar:

        def on_progress(stream, chunk: bytes, bytes_remaining: int):
            # bar.update(len(chunk))
            bar.update(stream.filesize - bytes_remaining)

        def on_complete(stream, file_path: str):
            bar.finish()
            print(f'Downloaded at {file_path}')

        yt.register_on_progress_callback(on_progress)
        yt.register_on_complete_callback(on_complete)
        stream.download()
コード例 #3
0
def _download(stream: Stream) -> None:
    print("\n{fn} | {fs} bytes".format(fn=stream.default_filename,
                                       fs=stream.filesize))
    stream.download()
    sys.stdout.write("\n")
コード例 #4
0
def _download(stream: Stream, target: Optional[str] = None) -> None:
    filesize_megabytes = stream.filesize // 1048576
    print(f"{stream.default_filename} | {filesize_megabytes} MB")
    stream.download(output_path=target)
    sys.stdout.write("\n")