Returns the duration in seconds of this audio or video file
175325
def duration(self):
        """"""

        if self.filetype not in ("video", "audio"):
            raise RuntimeError("Only videos and audio have durations")
        return self.info.get("length") or self.info.get("duration")
1301757
def created(filename):
    '''
    
    '''
    if isinstance(filename, file):
        filename = filename.name

    return duration(os.stat(filename)[stat.ST_CTIME])
244906
def duration(self):
        
        duration = 0.0
        if len(self.events) > 0:
            first = datetime.fromtimestamp(self.events[0]['timestamp'])
            last = datetime.fromtimestamp(self.events[-1]['timestamp'])
            duration = (last - first).total_seconds()
        return duration
800849
def frame_to_seconds(self, frame_index, sr):
        
        start_sample, end_sample = self.frame_to_sample(frame_index)
        return sample_to_seconds(start_sample, sampling_rate=sr), sample_to_seconds(end_sample, sampling_rate=sr)
106038
def _event_duration(vevent):
        """"""
        if hasattr(vevent, 'dtend'):
            return vevent.dtend.value - vevent.dtstart.value
        elif hasattr(vevent, 'duration') and vevent.duration.value:
            return vevent.duration.value
        return timedelta(0)
649074
public static String getDuration(long diff) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(new Date(diff));
        StringBuffer s = new StringBuffer();
        if (calendar.get(Calendar.HOUR) > 1) {
            s.append("hours: " + (calendar.get(Calendar.HOUR) - 1) + ", ");
        }
        if (calendar.get(Calendar.MINUTE) > 0) {
            s.append("minutes: " + (calendar.get(Calendar.MINUTE)) + ", ");
        }
        if (calendar.get(Calendar.SECOND) > 0) {
            s.append("seconds: " + (calendar.get(Calendar.SECOND)) + ", ");
        }
        if (calendar.get(Calendar.MILLISECOND) > 1) {
            s.append("milliseconds: " + (calendar.get(Calendar.MILLISECOND)) + ", ");
        }
        s.append("total milliseconds: " + diff);
        return s.toString();
    }
575357
def _duration(self):
        """"""
        duration = 0
        if self.state != STATE_IDLE:
            resp = self._player.query_duration(_FORMAT_TIME)
            duration = resp[1] // _NANOSEC_MULT
        return duration
909835
def get_duration(self):
        """"""

        doc = self._request(self.ws_prefix + ".getInfo", True)

        return _number(_extract(doc, "duration"))
604440
async def recv(self):
        
        if self.readyState != 'live':
            raise MediaStreamError

        sample_rate = 8000
        samples = int(AUDIO_PTIME * sample_rate)

        if hasattr(self, '_timestamp'):
            self._timestamp += samples
            wait = self._start + (self._timestamp / sample_rate) - time.time()
            await asyncio.sleep(wait)
        else:
            self._start = time.time()
            self._timestamp = 0

        frame = AudioFrame(format='s16', layout='mono', samples=samples)
        for p in frame.planes:
            p.update(bytes(p.buffer_size))
        frame.pts = self._timestamp
        frame.sample_rate = sample_rate
        frame.time_base = fractions.Fraction(1, sample_rate)
        return frame
562826
def get_duration(self):
        """"""
        postgame = self.get_postgame()
        if postgame:
            return postgame.duration_int * 1000
        duration = self._header.initial.restore_time
        try:
            while self._handle.tell() < self.size:
                operation = mgz.body.operation.parse_stream(self._handle)
                if operation.type == 'sync':
                    duration += operation.time_increment
                elif operation.type == 'action':
                    if operation.action.type == 'resign':
                        self._cache['resigned'].add(operation.action.player_id)
            self._handle.seek(self.body_position)
        except (construct.core.ConstructError, zlib.error, ValueError):
            raise RuntimeError("invalid mgz file")
        return duration
431588
def get_audio_duration(self):
        
        decoder = timeside.core.get_processor('file_decoder')(
            uri=self.get_uri())
        return decoder.uri_total_duration
195058
def num_samples(self):
        
        with audioread.audio_open(self.path) as f:
            return int(f.duration * f.samplerate)
90730
def _get_minutes(self, duration):
        
        if isinstance(duration, datetime.datetime):
            from_now = (duration - datetime.datetime.now()).total_seconds()
            from_now = math.ceil(from_now / 60)

            if from_now > 0:
                return from_now

            return

        return duration
162053
def get_thumbnail(self, video_path, at_time=0.5):
        
        filename = os.path.basename(video_path)
        filename, __ = os.path.splitext(filename)
        _, image_path = tempfile.mkstemp(suffix='_{}.jpg'.format(filename))

        video_duration = self.get_media_info(video_path)['duration']
        if at_time > video_duration:
            raise exceptions.InvalidTimeError()
        thumbnail_time = at_time

        cmds = [self.ffmpeg_path, '-i', video_path, '-vframes', '1']
        cmds.extend(['-ss', str(thumbnail_time), '-y', image_path])

        process = self._spawn(cmds)
        self._check_returncode(process)

        if not os.path.getsize(image_path):
            # we somehow failed to generate thumbnail
            os.unlink(image_path)
            raise exceptions.InvalidTimeError()

        return image_path
452912
private static int calculateFrameLength(int layer, int bitRate, int sampleRate, int padding) {
        if (layer == AudioFrame.LAYER_1) {
            return (12 * bitRate / sampleRate + padding) * 4;
        } else {
            return 144 * bitRate / sampleRate + padding;
        }
    }
1150095
def total_duration(self):
        
        duration = 0

        for utterance in self.utterances.values():
            duration += utterance.duration

        return duration
176131
function () {
            if (this._duration) {
                return this._duration;
            }
            if (this._start && this._end) {
                return moment.duration(this._end - this._start);
            }
            else {
                return moment.duration(0);
            }
        }