def __est_size(self, full_path, tsn='', mime=''): # Size is estimated by taking audio and video bit rate adding 2% vInfo = transcode.video_info(full_path) if not mime: compat = False mimetypes = ['video/x-tivo-mpeg'] if self.use_ts(tsn, full_path): mimetypes = ['video/x-tivo-mpeg', 'video/x-tivo-mpeg-ts'] for mimet in mimetypes: compat = transcode.tivo_compatible_video(vInfo, tsn, mimet)[0] if compat: break else: compat = transcode.tivo_compatible_video(vInfo, tsn, mime)[0] if compat: return int(os.path.getsize(unicode(full_path, 'utf-8'))*1.1) else: # Must be re-encoded audioBPS = config.getMaxAudioBR(tsn) * 1000 #audioBPS = config.strtod(config.getAudioBR(tsn)) videoBPS = transcode.select_videostr(full_path, tsn) bitrate = audioBPS + videoBPS return int((self.__duration(full_path) / 1000) * (bitrate * 1.02 / 8))
def metadata_full(self, full_path, tsn='', mime=''): data = {} vInfo = transcode.video_info(full_path) if ((int(vInfo['vHeight']) >= 720 and config.getTivoHeight >= 720) or (int(vInfo['vWidth']) >= 1280 and config.getTivoWidth >= 1280)): data['showingBits'] = '4096' data.update(metadata.basic(full_path)) if full_path[-5:].lower() == '.tivo': data.update(metadata.from_tivo(full_path)) if full_path[-4:].lower() == '.wtv': data.update(metadata.from_mscore(vInfo['rawmeta'])) if 'episodeNumber' in data: try: ep = int(data['episodeNumber']) except: ep = 0 data['episodeNumber'] = str(ep) if config.getDebug() and 'vHost' not in data: compatible, reason = transcode.tivo_compatible(full_path, tsn, mime) if compatible: transcode_options = {} else: transcode_options = transcode.transcode(True, full_path, '', tsn, mime) data['vHost'] = ( ['TRANSCODE=%s, %s' % (['YES', 'NO'][compatible], reason)] + ['SOURCE INFO: '] + ["%s=%s" % (k, v) for k, v in sorted(vInfo.items(), reverse=True)] + ['TRANSCODE OPTIONS: '] + ["%s" % (v) for k, v in transcode_options.items()] + ['SOURCE FILE: ', os.path.basename(full_path)] ) now = datetime.utcnow() if 'time' in data: if data['time'].lower() == 'file': mtime = os.stat(unicode(full_path, 'utf-8')).st_mtime if (mtime < 0): mtime = 0 try: now = datetime.utcfromtimestamp(mtime) except: logger.warning('Bad file time on ' + full_path) elif data['time'].lower() == 'oad': now = isodt(data['originalAirDate']) else: try: now = isodt(data['time']) except: logger.warning('Bad time format: ' + data['time'] + ' , using current time') duration = self.__duration(full_path) duration_delta = timedelta(milliseconds = duration) min = duration_delta.seconds / 60 sec = duration_delta.seconds % 60 hours = min / 60 min = min % 60 data.update({'time': now.isoformat(), 'startTime': now.isoformat(), 'stopTime': (now + duration_delta).isoformat(), 'size': self.__est_size(full_path, tsn, mime), 'duration': duration, 'iso_duration': ('P%sDT%sH%sM%sS' % (duration_delta.days, hours, min, sec))}) return data
def __duration(self, full_path): return transcode.video_info(full_path)['millisecs']
def metadata_full(self, full_path, tsn='', mime='', mtime=None): data = {} vInfo = transcode.video_info(full_path) if ((int(vInfo['vHeight']) >= 720 and config.getTivoHeight >= 720) or (int(vInfo['vWidth']) >= 1280 and config.getTivoWidth >= 1280)): data['showingBits'] = '4096' data.update(metadata.basic(full_path, mtime)) if full_path[-5:].lower() == '.tivo': data.update(metadata.from_tivo(full_path)) if full_path[-4:].lower() == '.wtv': data.update(metadata.from_mscore(vInfo['rawmeta'])) if 'episodeNumber' in data: try: ep = int(data['episodeNumber']) except: ep = 0 data['episodeNumber'] = str(ep) if config.getDebug() and 'vHost' not in data: compatible, reason = transcode.tivo_compatible( full_path, tsn, mime) if compatible: transcode_options = [] else: transcode_options = transcode.transcode( True, full_path, '', None, False, tsn, mime) data['vHost'] = ( ['TRANSCODE=%s, %s' % (['YES', 'NO'][compatible], reason)] + ['SOURCE INFO: '] + [ "%s=%s" % (k, v) for k, v in sorted(vInfo.items(), reverse=True) ] + ['TRANSCODE OPTIONS: '] + transcode_options + ['SOURCE FILE: ', os.path.basename(full_path)]) now = datetime.utcnow() if 'time' in data: if data['time'].lower() == 'file': if not mtime: mtime = os.path.getmtime(unicode(full_path, 'utf-8')) try: now = datetime.utcfromtimestamp(mtime) except: logger.warning('Bad file time on ' + full_path) elif data['time'].lower() == 'oad': now = isodt(data['originalAirDate']) else: try: now = isodt(data['time']) except: logger.warning('Bad time format: ' + data['time'] + ' , using current time') duration = self.__duration(full_path) duration_delta = timedelta(milliseconds=duration) min = duration_delta.seconds / 60 sec = duration_delta.seconds % 60 hours = min / 60 min = min % 60 data.update({ 'time': now.isoformat(), 'startTime': now.isoformat(), 'stopTime': (now + duration_delta).isoformat(), 'size': self.__est_size(full_path, tsn, mime), 'duration': duration, 'iso_duration': ('P%sDT%sH%sM%sS' % (duration_delta.days, hours, min, sec)) }) return data
def metadata_full(self, full_path, tsn="", mime=""): data = {} vInfo = transcode.video_info(full_path) if (int(vInfo["vHeight"]) >= 720 and config.getTivoHeight >= 720) or ( int(vInfo["vWidth"]) >= 1280 and config.getTivoWidth >= 1280 ): data["showingBits"] = "4096" data.update(metadata.basic(full_path)) if full_path[-5:].lower() == ".tivo": data.update(metadata.from_tivo(full_path)) if full_path[-4:].lower() == ".wtv": data.update(metadata.from_mscore(vInfo["rawmeta"])) if "episodeNumber" in data: try: ep = int(data["episodeNumber"]) except: ep = 0 data["episodeNumber"] = str(ep) if config.getDebug() and "vHost" not in data: compatible, reason = transcode.tivo_compatible(full_path, tsn, mime) if compatible: transcode_options = {} else: transcode_options = transcode.transcode(True, full_path, "", tsn, mime) data["vHost"] = ( ["TRANSCODE=%s, %s" % (["YES", "NO"][compatible], reason)] + ["SOURCE INFO: "] + ["%s=%s" % (k, v) for k, v in sorted(vInfo.items(), reverse=True)] + ["TRANSCODE OPTIONS: "] + ["%s" % (v) for k, v in transcode_options.items()] + ["SOURCE FILE: ", os.path.basename(full_path)] ) now = datetime.utcnow() if "time" in data: if data["time"].lower() == "file": mtime = os.stat(unicode(full_path, "utf-8")).st_mtime if mtime < 0: mtime = 0 try: now = datetime.utcfromtimestamp(mtime) except: logger.warning("Bad file time on " + full_path) elif data["time"].lower() == "oad": now = isodt(data["originalAirDate"]) else: try: now = isodt(data["time"]) except: logger.warning("Bad time format: " + data["time"] + " , using current time") duration = self.__duration(full_path) duration_delta = timedelta(milliseconds=duration) min = duration_delta.seconds / 60 sec = duration_delta.seconds % 60 hours = min / 60 min = min % 60 data.update( { "time": now.isoformat(), "startTime": now.isoformat(), "stopTime": (now + duration_delta).isoformat(), "size": self.__est_size(full_path, tsn, mime), "duration": duration, "iso_duration": ("P%sDT%sH%sM%sS" % (duration_delta.days, hours, min, sec)), } ) return data