def getIndexFileSuffix(flightName, sourceShortName, segmentNumber): """ get path to video for PLRP """ if flightName.endswith(sourceShortName): return '%s/prog_index.m3u8' % getSegmentPath(flightName, None, segmentNumber) else: return '%s/prog_index.m3u8' % getSegmentPath( flightName, sourceShortName, segmentNumber)
def adjustSegmentTimes(self, force=False): """ Read through the ts files in this segment's directory and calculate end time. This is used when restarting video because it died. """ if force or not self.endTime: dir = os.path.join(settings.RECORDED_VIDEO_DIR_BASE, util.getSegmentPath(self.episode.shortName, self.source.name, self.segNumber)) videoChunks = glob("%s/*.ts" % dir) videoChunks = sorted(videoChunks, key = lambda chunk: int(re.sub(".+prog_index-(\d+).ts", "\\1", chunk))) if len(videoChunks) > 0: (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(videoChunks[0]) try: index = m3u8.load('%s/%s' % (dir, self.indexFileName)) m3u8segment = index.segments[0] duration = m3u8segment.duration except: print "NO INDEX.M3U8 FILE for segment %s %d" % (self.episode.shortName, self.segNumber) recordingUtil.stopRecordingAndCleanSegments(self.source, videoChunks) return (None, None) startTime = mtime - duration startDT = datetime.fromtimestamp(startTime, pytz.utc) (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(videoChunks[-1]) endTime = mtime endDT = datetime.fromtimestamp(endTime, pytz.utc) print "Segment: Start: %s End: %s" % (startDT, endDT) self.startTime = startDT self.endTime = endDT self.save() return (self.startTime, self.endTime)
def getActiveFlightLatestSegmentIndexFilePath(): """ Get the latest .m3u8 file for the active flight. """ latestSegment = getActiveFlightLatestSegment() latestSegNumber = latestSegment.segNumber activeFlight = BasaltActiveFlight.objects.all()[0] indexFilePath = getSegmentPath(activeFlight.flight.name, "", latestSegNumber) return indexFilePath