Retrieving initial timestamp is more robust.

This commit is contained in:
Frédéric Tronel
2024-06-08 14:32:56 +02:00
parent f5393cda3b
commit 31f8cf2047

View File

@@ -150,11 +150,11 @@ def dumpFilms(films):
logger.info('%d - %s enregistré le %s sur %s. Durée: %s. %s' % (fid, film['title'], film['date'], film['channel'], film['duration'], film['url']))
fid = fid + 1
def getInitialTSFromBuffer(content):
def getInitialTSFromBuffer(content, delta=0.1):
logger = logging.getLogger(__name__)
logger.debug('Determining initial timestamp from content')
with Popen(['ffprobe','/dev/stdin','-loglevel', 'quiet', '-read_intervals', '0%+0.1', '-show_entries', 'frame=frame_no,best_effort_timestamp_time', '-of','json'], stdout=PIPE, stdin=PIPE) as ffprobe:
with Popen(['ffprobe','/dev/stdin','-loglevel', 'quiet', '-read_intervals', ('0%%+%f' % delta), '-show_entries', 'frame=frame_no,best_effort_timestamp_time', '-of','json'], stdout=PIPE, stdin=PIPE) as ffprobe:
out, _ = ffprobe.communicate(input=content)
frames = json.load(BytesIO(out))
logger.debug('Frames: %s' % frames)
@@ -257,8 +257,16 @@ def downloadMovie(url, outputFileName):
total = timedelta(seconds=total)
logger.debug('Header: %s' % r.headers)
initialTS = getInitialTSFromBuffer(r.content)
initialTS = None
nbRetries = 0
maxRetries = 10
while initialTS == None and nbRetries < maxRetries:
initialTS = getInitialTSFromBuffer(r.content, delta=0.1*nbRetries)
nbRetries = nbRetries+1
logger.debug('Initial timestamp: %s' % initialTS)
if initialTS == None:
logger.error('Impossible to retrieve initial timestamp')
exit(-1)
lastTS = getLastTSFromBuffer(r.content)
logger.debug('Last timestamp: %s' % lastTS)
delta = lastTS-initialTS