Correction d'un bug qui empêchait de retrouver correctement les timestamps initiaux et finaux.

This commit is contained in:
Frédéric Tronel
2024-01-06 15:56:00 +01:00
parent dc7c8acb00
commit 2ea2cf0fc6

View File

@@ -153,9 +153,11 @@ def dumpFilms(films):
def getInitialTSFromBuffer(content):
logger = logging.getLogger(__name__)
with Popen(['ffprobe','/dev/stdin','-loglevel', 'quiet', '-read_intervals', '0%+0.000001', '-show_entries', 'frame=frame_no,best_effort_timestamp_time', '-of','json'], stdout=PIPE, stdin=PIPE) as ffprobe:
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:
out, _ = ffprobe.communicate(input=content)
frames = json.load(BytesIO(out))
logger.debug('Frames: %s' % frames)
if 'frames' in frames:
frames = frames['frames']
if len(frames) > 0:
@@ -173,10 +175,12 @@ def getInitialTSFromBuffer(content):
def getLastTSFromBuffer(content):
logger = logging.getLogger(__name__)
logger.debug('Determining last timestamp from content.')
length = len(content)
with Popen(['ffprobe', '/dev/stdin', '-loglevel', 'quiet', '-show_entries', 'frame=frame_no,best_effort_timestamp_time', '-of','json'], stdout=PIPE, stdin=PIPE) as ffprobe:
out, _ = ffprobe.communicate(input=content[max(0,length-100000):])
out, _ = ffprobe.communicate(input=content[max(0,length-200000):])
frames = json.load(BytesIO(out))
logger.debug('Frames: %s' % frames)
if 'frames' in frames:
frames = frames['frames']
if len(frames) > 0:
@@ -247,12 +251,15 @@ def downloadMovie(url, outputFileName, duration):
if m == None:
logger.error('Impossible to parse timestamps' % r.headers['TimeSeekRange.dlna.org'])
exit(-1)
total = int(m.group('totalsecs'))+(int(m.group('totalms')))/1000
total = timedelta(seconds=total)
logger.debug('Header: %s' % r.headers)
initialTS = getInitialTSFromBuffer(r.content)
logger.debug('Initial timestamp: %s' % initialTS)
lastTS = getLastTSFromBuffer(r.content)
logger.debug('Last timestamp: %s' % lastTS)
delta = lastTS-initialTS
ratio = delta/total
estimatedLength = ceil(len(r.content)/ratio)