public static ClipSet ClipSetGet(OrganizationModel organization, FileIdentifier fileIdentifier, List <AlternativeView> alternativeViews, string extension, string mimeType) { var mediaset = MediaService.MediaSetGet(organization, fileIdentifier, alternativeViews, extension, mimeType); var canonicalURL = organization.Read <string>("ClipSetCanonicalURLFormat"); if (canonicalURL != null) { var partial = fileIdentifier.FolderKey?.Split(':')?.LastOrDefault(); canonicalURL = canonicalURL.Replace("__FOLDER_KEY_PARTIAL__", partial); } return(new ClipSet { AutoPlay = mediaset.AutoPlay, MediaType = mediaset.MediaType, Poster = mediaset.Poster, Preload = mediaset.Preload, RootFileIdentifier = mediaset.RootFileIdentifier, Sources = mediaset.Sources, Subtitles = mediaset.Subtitles, Views = mediaset.Views, AllowedOperations = mediaset.AllowedOperations, Segments = null, CanonicalURLFormat = canonicalURL }); }
private async Task ConfigureBackendAsync(OrganizationModel organizationModel, PCMSOrganizationModel pcms) { // create a private folder to store backend configuration var privateFolder = new FolderModel(new FolderIdentifier(organizationModel.Identifier, ":private")) .InitializeEmptyMetadata() .InitializeEmptyPrivileges(); // write the backend configuration into the folder's metadata var backendConfiguration = new BackendConfiguration { DriverTypeName = "Documents.Backends.Drivers.Encryption.Driver, Documents.Backends.Drivers.Encryption", ConfigurationJSON = JsonConvert.SerializeObject(new { NextDriverTypeName = "Documents.Backends.Drivers.S3.Driver, Documents.Backends.Drivers.S3", MasterKey = pcms.MasterEncryptionKey, NextDriverConfigurationJson = JsonConvert.SerializeObject(new { AWSRegion = pcms.AWSS3Region, BucketName = pcms.AWSS3BucketName, pcms.AWSSecretAccessKey, pcms.AWSAccessKeyID }) }) }; privateFolder.Write(MetadataKeyConstants.BACKEND_CONFIGURATION, backendConfiguration); privateFolder.WriteACLs("read", idSystem); privateFolder.WriteACLs("write", idSystem); privateFolder.WriteACLs("gateway", idSystem, idOrganizationMember); privateFolder.Write("synchronize", new { ConnectionString = pcms.PCMSDBConnectionString, pcms.CountyID, LastChangeLogID = 0, LastAccountChangeLogID = 0 }); if (organizationModel.Read <bool?>("synchronize[isactive]") == null) { organizationModel.Write("synchronize[isactive]", true); } await api.Folder.PutAsync(privateFolder); }
public static MediaSet MediaSetGet(OrganizationModel organization, FileIdentifier fileIdentifier, List <AlternativeView> alternativeViews, string extension, string mimeType, bool isPrivileged = false) { bool noTranscodes = false; var mediaSet = new MediaSet { AutoPlay = false, Preload = true, Poster = alternativeViews?.FirstOrDefault(v => v.MimeType == MIME_PNG)?.FileIdentifier }; // query for video formats by mime-type var mp4 = alternativeViews?.FirstOrDefault(v => v.MimeType == MIME_MP4)?.FileIdentifier; var webm = alternativeViews?.FirstOrDefault(v => v.MimeType == MIME_WEBM)?.FileIdentifier; var mp3 = alternativeViews?.FirstOrDefault(v => v.MimeType == MIME_MP3)?.FileIdentifier; var exif = alternativeViews?.FirstOrDefault(v => v.Name == "EXIF")?.FileIdentifier; // check to see if the original was either of the targets if (mp4 == null && mimeType == MIME_MP4) { mp4 = fileIdentifier; } if (webm == null && mimeType == MIME_WEBM) { webm = fileIdentifier; } if (mp3 == null && mimeType == MIME_MP3) { mp3 = fileIdentifier; } var sources = new List <MediaSource>(); mediaSet.Sources = sources; if (mp4 != null) { sources.Add(new MediaSource(mp4, MIME_MP4)); } if (webm != null) { sources.Add(new MediaSource(webm, MIME_WEBM)); } if (mp3 != null) { sources.Add(new MediaSource(mp3, MIME_MP3)); } // if we don't have any of our target formats, try adding the original file if (!sources.Any()) { sources.Add(new MediaSource(fileIdentifier, mimeType)); noTranscodes = true; } var vtt = alternativeViews?.FirstOrDefault(v => v.MimeType == MIME_VTT && v.Name == TranscriptService.FILENAME_VTT)?.FileIdentifier; if (vtt == null) { vtt = alternativeViews?.FirstOrDefault(v => v.MimeType == MIME_VTT)?.FileIdentifier; } if (vtt != null) { mediaSet.Subtitles = new List <MediaSubtitles> { new MediaSubtitles { FileIdentifier = vtt, IsDefault = true, Label = "English", Language = "English" } }; } // let's see how we did mediaSet.MediaType = MediaSet.MediaTypeEnum.Unknown; if (mp3 != null) { mediaSet.MediaType = MediaSet.MediaTypeEnum.Audio; } if (mp4 != null || webm != null) { mediaSet.MediaType = MediaSet.MediaTypeEnum.Video; } // we couldn't find any alternative views, indicating a transcoder // has visited this file. let's check the primary file itself if (noTranscodes && false) { if (mimeType?.ToLower().StartsWith("video") ?? false) { mediaSet.MediaType = MediaSet.MediaTypeEnum.Video; } else if (mimeType?.ToLower().StartsWith("audio") ?? false) { mediaSet.MediaType = MediaSet.MediaTypeEnum.Audio; } } var allowedOperations = new List <AllowedOperation> { AllowedOperation.GetAllowedOperationDownload(fileIdentifier, label: "Download") }; if (mp4 != null) { allowedOperations.Add(AllowedOperation.GetAllowedOperationDownload(mp4, label: "Download MP4")); } if (exif != null) { allowedOperations.Add(AllowedOperation.GetAllowedOperationDownload(exif, label: "Download EXIF")); } if (mediaSet.MediaType == MediaSet.MediaTypeEnum.Audio && mp3 != null) { allowedOperations.Add(AllowedOperation.GetAllowedOperationDownload(mp3, label: "Download MP3")); } if (vtt != null) { allowedOperations.Add(AllowedOperation.GetAllowedOperationDownload(vtt, label: "Download Subtitles")); } else { if (isPrivileged) { if (mp3 != null && organization.Read("transcript[isActive]", defaultValue: false)) { allowedOperations.Add(AllowedOperation.GetAllowedOperationTranscribe(fileIdentifier)); } } } if (isPrivileged) { if (mp4 != null) { allowedOperations.Add(AllowedOperation.GetAllowedOperationWatermarkVideo(mp4)); } } mediaSet.AllowedOperations = allowedOperations; return(mediaSet); }
public async Task <SearchResponse> SearchAsync(OrganizationModel organization, Manager.Models.Requests.SearchRequest request) { var searchConfiguration = organization.Read <SearchConfiguration>("searchConfiguration"); if (request.Filters?.Any() ?? false) { request.Filters = request.Filters.Select(f => { if (f.Name == "pathKey") { f.Name = "_path"; } return(f); }).ToList(); } var results = await Connection.Search.SearchAsync( searchRequest : new SearchRequest { OrganizationIdentifier = organization.Identifier, FolderIdentifier = request.FolderIdentifier, KeywordQuery = request.Keyword, Filters = request.Filters?.Select(ff => new API.Common.Models.Search.Filter { Name = ff.Name, Value = ff.Value }), Paging = request.Paging ?? new PagingArguments { PageIndex = 0, PageSize = 500 } } ); var response = new SearchResponse { Rows = results.Rows.Select(f => { var alternativeViews = f.Metadata?.Read <List <AlternativeView> >(MetadataKeyConstants.ALTERNATIVE_VIEWS); var pathIdentifier = f.Metadata?.MetaPathIdentifierRead(f.FileIdentifier as FolderIdentifier, dontThrow: true); var result = new ManagerFileSearchResult { Identifier = f.FileIdentifier, PathIdentifier = pathIdentifier, FullPath = pathIdentifier?.FullName, Name = f.Name, Views = ViewSetService.DetectFileViews( organization, f.FileIdentifier, f.Metadata.Read <List <AlternativeView> >(MetadataKeyConstants.ALTERNATIVE_VIEWS), f.Extension, f.MimeType ), Created = f.Created, Modified = f.Modified, PreviewImageIdentifier = alternativeViews?.FirstOrDefault(v => v.SizeType == "Thumbnail")?.FileIdentifier, Attributes = BuildAttributes(searchConfiguration, f), Highlights = f.Highlights }; result.ViewerType = result.Views.FirstOrDefault()?.ViewerType ?? Manager.Models.ManagerFileView.ViewerTypeEnum.Unknown; result.Icons = result.Views.FirstOrDefault()?.Icons; return(result); }).ToList(), // if we don't ToList(), then deferred execution happens during the streaming, and you don't // want to debug that again, trust me. TotalMatches = results.TotalMatches, Facets = DecorateFacets(searchConfiguration, results.Facets) }; return(response); }