From 9814d045094861842c078bb3528d1a02beffd402 Mon Sep 17 00:00:00 2001 From: Ashutosh <216.ashutosh@gmail.com> Date: Sun, 14 Feb 2016 21:15:26 +0530 Subject: [PATCH] added progress report for ffmpeg --- youtube_dl/downloader/common.py | 10 +++++++++ youtube_dl/downloader/hls.py | 38 ++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/youtube_dl/downloader/common.py b/youtube_dl/downloader/common.py index 2d5154051..dadbdedc4 100644 --- a/youtube_dl/downloader/common.py +++ b/youtube_dl/downloader/common.py @@ -137,6 +137,16 @@ class FileDownloader(object): multiplier = 1024.0 ** 'bkmgtpezy'.index(matchobj.group(2).lower()) return int(round(number * multiplier)) + @staticmethod + def calc_miliseconds(time): + time = '%s' % time + hours, minutes, seconds = (["0", "0"] + time.split(":"))[-3:] + hours = int(hours) + minutes = int(minutes) + seconds = float(seconds) + miliseconds = int(3600000 * hours + 60000 * minutes + 1000 * seconds) + return int(miliseconds) + def to_screen(self, *args, **kargs): self.ydl.to_screen(*args, **kargs) diff --git a/youtube_dl/downloader/hls.py b/youtube_dl/downloader/hls.py index 2a775bf00..9caf1a9eb 100644 --- a/youtube_dl/downloader/hls.py +++ b/youtube_dl/downloader/hls.py @@ -4,6 +4,7 @@ import os import re import subprocess import sys +import time from .common import FileDownloader from .fragment import FragmentFD @@ -51,8 +52,43 @@ class HlsFD(FileDownloader): self._debug_cmd(args) - proc = subprocess.Popen(args, stdin=subprocess.PIPE) + proc = subprocess.Popen(args, stdin=subprocess.PIPE, stderr=subprocess.PIPE) try: + lineAfterCarriage = '' + totalstream = '' + start = time.time() + while True: + tmpoutput = proc.stderr.read(1) + if tmpoutput == '' and proc.poll() != None: + break + if tmpoutput != '': + downloadedstream = '' + size_av = '0' + lineAfterCarriage += tmpoutput + if tmpoutput == '\r': + if 'Duration' in lineAfterCarriage: + duration_str = [string.split('Duration:')[1:] for string in lineAfterCarriage.split(', ') if 'Duration' in string] + if duration_str and duration_str[0][0]: + totalstream = duration_str[0][0].strip() + + if 'frame' in lineAfterCarriage: + frame_str = [string.strip().split('=') for string in lineAfterCarriage.split(' ') if 'time=' in string] + size_str = [string.lower().split('kb') for string in lineAfterCarriage.split(' ') if 'kb' in string.lower()] + if frame_str and frame_str[0][0] == 'time': + downloadedstream = frame_str[0][1].strip() + + + + if size_str and size_str[0][0]: + size_av = size_str[0][0][1].strip() + + now = time.time() + size_strn = self.parse_bytes(size_av + 'k') + speed_str = self.format_speed(self.calc_speed(start,now,size_strn)) + percentage = self.format_percent(self.calc_percent(self.calc_miliseconds(downloadedstream),self.calc_miliseconds(totalstream))) + self.to_screen('[download] %s: of %s at %s ETA Unknown' % (percentage,totalstream,speed_str)) + + lineAfterCarriage = '' retval = proc.wait() except KeyboardInterrupt: # subprocces.run would send the SIGKILL signal to ffmpeg and the