1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import os.path
- import mutagen
- def maxwait(songs, context, conf):
- wait = int(conf.get('EF_MAXWAIT_SEC', 0))
- if wait == 0:
- return True
- print(context)
- curpos, duration = map(int, context['status']['time'].split(':'))
- remaining = duration - curpos
- if remaining > wait:
- return False, 'remaining %d max allowed %d' % (remaining, wait)
- return True
- def get_duration(path):
- '''get track duration in seconds'''
- audio = mutagen.File(path)
- return int(audio.info.length)
- def percentwait(songs, context, conf, getdur=get_duration):
- percentwait = int(conf.get('EF_MAXWAIT_PERC', 0))
- if percentwait == 0:
- return True
- print(context)
- curpos, duration = map(int, context['status']['time'].split(':'))
- remaining = duration - curpos
- eventduration = 0
- for uri in songs['uris']:
- if not uri.startswith('file://'):
- return True, '%s is not a file' % uri
- path = uri[len('file://'):] # strips file://
- eventduration += getdur(path)
- wait = eventduration * (percentwait/100.)
- if remaining > wait:
- return False, 'remaining %d max allowed %d' % (remaining, wait)
- return True
|