public static WebMediaInfo GetMediaInfo(MediaSource source) { // Timeshiftings are a special case, as they can't be cached and need an additional path resolving step if (source.MediaType == WebMediaType.TV) { if (tvCache.ContainsKey(source.Id) && DateTime.Now - tvCache[source.Id].Item1 > TimeSpan.FromSeconds(60)) { return(tvCache[source.Id].Item2); } TsBuffer tsBuffer = new TsBuffer(source.Id); Log.Debug("Using path {0} from TS buffer {1} as source for {2}", tsBuffer.GetCurrentFilePath(), source.Id, source.GetDebugName()); WebMediaInfo info = LoadMediaInfo(tsBuffer.GetCurrentFilePath()); tvCache[source.Id] = new Tuple <DateTime, WebMediaInfo>(DateTime.Now, info); return(info); } using (var context = source.CreateNetworkContext()) { // verify the file actually exists and is accessible over the local file system if (!source.Exists) { Log.Warn("Trying to load MediaInfo for {0}, which does not exist or is inaccessible", source.GetDebugName()); return(null); } else if (!source.SupportsDirectAccess) { Log.Warn("Loading MediaInfo for non-direct access source {0} isn't supported yet", source.GetDebugName()); return(null); } // if we got the file in the cache, return it if we have it and the file hasn't been changed var fileInfo = source.GetFileInfo(); if (source.MediaType != WebMediaType.TV && persistentCache.HasForSource(source)) { var cachedItem = persistentCache.GetForSource(source); if (cachedItem.Size == fileInfo.Size && cachedItem.CachedDate >= fileInfo.LastModifiedTime) { return(cachedItem.Info); } } var info = LoadMediaInfo(context.RewritePath(source.GetPath())); if (info != null) { persistentCache.Save(source, new CachedInfoWrapper(info, fileInfo)); } return(info); } }
public static WebMediaInfo GetMediaInfo(MediaSource source) { if (source.MediaType == WebStreamMediaType.TV) { // cache tv files for 10 seconds if (TvCache.ContainsKey(source.Id) && TvCache[source.Id].Item1.AddSeconds(10).CompareTo(DateTime.Now) > 0) { // cache is valid, use it return(TvCache[source.Id].Item2); } // get media info and save it to the cache TsBuffer buf = new TsBuffer(source.Id); WebMediaInfo info = GetMediaInfo(buf.GetCurrentFilePath(), true); TvCache[source.Id] = new Tuple <DateTime, WebMediaInfo>(DateTime.Now, info); return(info); } else if (!source.Exists) { throw new FileNotFoundException(); } else if (source.SupportsDirectAccess) { using (var impersonator = source.GetImpersonator()) { return(GetMediaInfo(source.GetPath(), false)); } } else { // not (yet?) supported throw new NotSupportedException(); } }