/// <summary> /// /// </summary> /// <param name="source"></param> /// <returns></returns> public bool IsOfFormat(MediaSourceContext source) { var result = CheckMimeTypeAndExtension(source); if (!result) return false; // Perform further parsing return OnMatched(source); }
protected virtual bool CheckMimeTypeAndExtension(MediaSourceContext source) { // Check file extension then mime type var fileExt = source.Source.FileExtension(); var isExt = true; if (!String.IsNullOrWhiteSpace(fileExt) && FileExtensions().Any()) { isExt = (FileExtensions().Any(ext => String.Equals(fileExt,ext,StringComparison.InvariantCultureIgnoreCase))); } var isMime = true; var mimetype = source.Source.Metadata["MimeType"]; if (!String.IsNullOrWhiteSpace(mimetype) && MimeTypes().Any()) { isMime = (MimeTypes().Any(mime =>String.Equals(mimetype,mime,StringComparison.InvariantCultureIgnoreCase))); } // TODO: Not sure about having to match both but it's the only way now to distinguish between e.g. ogg video or ogg audio // Need to check how IIS handles this kind of thing; and probably we'll end up needing to check codecs in every instance // But that's for another week... return (isExt && isMime); }
public void HeaderFiltering(MediaQueryContext query, MediaHeaderContext header) { // Build a temporary source to test formats var testSource = new MediaSource() { Url = header.LocationContext.Location, TimeStamp = header.TimeStamp }; testSource.Metadata["ContentLength"] = header.ContentLength.ToString(); testSource.Metadata["MimeType"] = header.ContentType; testSource.Metadata["Title"] = header.Title; testSource.Metadata["SourceName"] = HeaderName; var testContext = new MediaSourceContext(testSource) { Stream = header.LocationContext.Stream }; var formats = _gardenService.Value.MatchFormats(testContext,query.MediaStereotype).ToList(); // Match a format, add it to sources if (formats.Any()) { testContext.Formats = formats; var format = formats.First(); testSource.MediaStereotype = format.MediaStereotype; testSource.FormatName = format.FormatName; query.Sources.Add(testContext); } else { // Helpful message for debugging sources that don't work :) Services.Notifier.Warning(T("No matching media formats found at {0} (with MIME type '{1}' and file extension '{2}')", testSource.Url, testSource.Metadata["MimeType"], testSource.FileExtension() )); } }
/// <summary> /// Overridable method to perform further checking if required /// </summary> /// <param name="source"></param> /// <returns></returns> protected virtual bool OnMatched(MediaSourceContext source) { return true; }
public bool IsOfFormat(MediaSourceContext source) { // All formats count as binary // TODO: Could do basic check to eliminate text formats. Maybe change implementation of MimeMediaFormat slightly so we can do != checks as well as == return true; }