added progress report for ffmpeg

This commit is contained in:
Ashutosh 2016-02-14 21:15:26 +05:30
parent 611c1dd96e
commit 9814d04509
2 changed files with 47 additions and 1 deletions

View File

@ -137,6 +137,16 @@ class FileDownloader(object):
multiplier = 1024.0 ** 'bkmgtpezy'.index(matchobj.group(2).lower()) multiplier = 1024.0 ** 'bkmgtpezy'.index(matchobj.group(2).lower())
return int(round(number * multiplier)) 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): def to_screen(self, *args, **kargs):
self.ydl.to_screen(*args, **kargs) self.ydl.to_screen(*args, **kargs)

View File

@ -4,6 +4,7 @@ import os
import re import re
import subprocess import subprocess
import sys import sys
import time
from .common import FileDownloader from .common import FileDownloader
from .fragment import FragmentFD from .fragment import FragmentFD
@ -51,8 +52,43 @@ class HlsFD(FileDownloader):
self._debug_cmd(args) self._debug_cmd(args)
proc = subprocess.Popen(args, stdin=subprocess.PIPE) proc = subprocess.Popen(args, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
try: 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() retval = proc.wait()
except KeyboardInterrupt: except KeyboardInterrupt:
# subprocces.run would send the SIGKILL signal to ffmpeg and the # subprocces.run would send the SIGKILL signal to ffmpeg and the