From a62ca9d50c8dba33d241991831fbbd23b7ec2043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 15 Jan 2017 20:49:27 +0100 Subject: [PATCH] implemented calculation of looping --- coub-dl.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/coub-dl.py b/coub-dl.py index c68e140..ca762fa 100644 --- a/coub-dl.py +++ b/coub-dl.py @@ -3,6 +3,8 @@ from os import listdir from re import match from sys import argv from enum import Enum +from datetime import timedelta +from math import ceil @@ -41,8 +43,21 @@ for file in listdir(): if match('^{}.*'.format(FILES[filename]), file): FILES[filename] = file -audioLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES[Stream.AUDIO]))) -videoLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES[Stream.VIDEO]))) +audioData= getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES[Stream.AUDIO]))).split(':') +videoData = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES[Stream.VIDEO]))).split(':') + +audioLen = timedelta(hours=float(audioData[0]), minutes=float(audioData[1]), seconds=float(audioData[2])) +videoLen = timedelta(hours=float(videoData[0]), minutes=float(videoData[1]), seconds=float(videoData[2])) print(audioLen) print(videoLen) + +longer = audioLen if audioLen > videoLen else videoLen +shorter = audioLen if audioLen < videoLen else videoLen + +timesLoop = ceil(longer.seconds / shorter.seconds) + +print('Longer: {}'.format(longer)) +print('Shorter: {}'.format(shorter)) + +print('Loop {} times.'.format(timesLoop))