aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-01-20 23:56:48 +0100
committerneodarz <neodarz@neodarz.net>2019-01-20 23:57:30 +0100
commit77ca92fc440dcf152dc8ebd023bfe64913ce1e42 (patch)
treee7de379a6a07a3169f6cb97990c83b1ddb79b71d
parent4c038d8100cd7b27252c600d94c6676eaa7e29b4 (diff)
downloadconvert.py-77ca92fc440dcf152dc8ebd023bfe64913ce1e42.tar.xz
convert.py-77ca92fc440dcf152dc8ebd023bfe64913ce1e42.zip
Fix duration and time detection in ffmpeg output
-rwxr-xr-xconvert.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/convert.py b/convert.py
index 0a7c034..9f3ac2e 100755
--- a/convert.py
+++ b/convert.py
@@ -75,17 +75,17 @@ for file in sorted(os.listdir(sourcedir)):
thread.close
elif i == 2:
unknown_line = thread.match.group(0)
- if re.match(r'.*Duration.*', str(unknown_line)):
- count = 0
- for element in unknown_line.split():
- count += 1
- if re.match(r"^b'Duration:'$", str(element)):
- break
- total = str(unknown_line.split()[count]).split("'")[1].split(',')[0]
+ ffmpeg_time = re.search('(Duration: [0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])', str(unknown_line), re.IGNORECASE)
+
+ if ffmpeg_time:
+ total = str(ffmpeg_time[0]).split(' ')[1]
totalRange = time.strptime(total.split('.')[0],'%H:%M:%S')
totalRangeS = datetime.timedelta(hours=totalRange.tm_hour,minutes=totalRange.tm_min,seconds=totalRange.tm_sec).total_seconds()
- if re.match(r'.*time=.*', str(unknown_line)):
- timeRange = time.strptime(str(unknown_line).partition("time=")[2].split('.')[0],'%H:%M:%S')
+
+ ffmpeg_time = re.search('(time=[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])', str(unknown_line), re.IGNORECASE)
+
+ if ffmpeg_time:
+ timeRange = time.strptime(str(ffmpeg_time[0]).split('.')[0].split('=')[1],'%H:%M:%S')
timeRangeS = datetime.timedelta(hours=timeRange.tm_hour,minutes=timeRange.tm_min,seconds=timeRange.tm_sec).total_seconds()
print(str(round(100*timeRangeS/totalRangeS, 1))+"% / 100% "+str(exist), end='\r')