From d92f6d7725720e3facf90b0fdefc1ef4eb1c2227 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 11 Mar 2022 10:45:01 +0100 Subject: youtube video: fix video with redirect not getting content length correctly, re-enable youtube timestamp --- src/Downloader.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/Downloader.cpp') diff --git a/src/Downloader.cpp b/src/Downloader.cpp index cb9f448..57a0349 100644 --- a/src/Downloader.cpp +++ b/src/Downloader.cpp @@ -310,8 +310,20 @@ namespace QuickMedia { return offset; } + static ssize_t read_eintr(int fd, void *buffer, size_t size) { + while(true) { + ssize_t bytes_read = read(fd, buffer, size); + if(bytes_read == -1) { + if(errno != EINTR) + return -1; + } else { + return bytes_read; + } + } + } + static int64_t read_fn(YoutubeReadProgram *program, char *buf, uint64_t nbytes) { - ssize_t bytes_read = read(program->read_program.read_fd, buf, nbytes); + ssize_t bytes_read = read_eintr(program->read_program.read_fd, buf, nbytes); if(bytes_read > 0) { program->offset += bytes_read; program->bytes_downloaded += bytes_read; @@ -319,15 +331,12 @@ namespace QuickMedia { // End of current range, progress to next range bytes_read = seek_fn(program, program->offset); if(bytes_read >= 0) { - bytes_read = read(program->read_program.read_fd, buf, nbytes); + bytes_read = read_eintr(program->read_program.read_fd, buf, nbytes); if(bytes_read > 0) { program->offset += bytes_read; program->bytes_downloaded += bytes_read; } } - } else if(bytes_read < 0) { - if(errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) - return 0; } return bytes_read; } -- cgit v1.2.3