private void UploadIngestManifests(MediaIngestManifest ingestManifest, string rssUrl, int videoCount) { XmlDocument rssDocument; StorageBlobClient blobClient = new StorageBlobClient(); using (WebClient webClient = new WebClient(null)) { HttpRequestMessage webRequest = webClient.GetRequest(HttpMethod.Get, rssUrl); rssDocument = webClient.GetResponse <XmlDocument>(webRequest); } XmlElement channel = rssDocument.DocumentElement["channel"]; XmlNodeList videos = channel.SelectNodes("item"); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(rssDocument.NameTable); namespaceManager.AddNamespace(Constant.Media.Channel9.NamespacePrefix, Constant.Media.Channel9.NamespaceUrl); for (int i = 0; i < videoCount; i++) { XmlNode video = videos[i]; XmlNode videoContent = video.SelectSingleNode(Constant.Media.Channel9.XPathQuery, namespaceManager); string videoUrl = videoContent.Attributes["url"].Value; string videoDescription = video.SelectSingleNode("title").InnerText; videoUrl = videoUrl.Replace(Constant.Media.Channel9.UrlHttp, Constant.Media.Channel9.UrlHttps); videoUrl = videoUrl.Replace(Constant.Media.Channel9.Http, Constant.Media.Channel9.Https); ingestManifest.JobInputFileUrl = videoUrl; ingestManifest.JobOutputAssetDescriptions = new string[] { videoDescription }; UploadIngestManifest(blobClient, ingestManifest); } }
public IStorageBlob Convert(ICloudBlob input) { if (input == null) { return(null); } CloudBlobClient sdkClient = input.ServiceClient; Debug.Assert(sdkClient != null); IStorageBlobClient client = new StorageBlobClient(sdkClient); CloudBlobContainer sdkContainer = input.Container; Debug.Assert(sdkContainer != null); IStorageBlobContainer container = new StorageBlobContainer(client, sdkContainer); CloudBlockBlob blockBlob = input as CloudBlockBlob; if (blockBlob != null) { return(new StorageBlockBlob(container, blockBlob)); } else { return(new StoragePageBlob(container, (CloudPageBlob)input)); } }
public JsonResult Create(string transformName, string jobName, string jobDescription, Priority jobPriority, string jobData, string inputFileUrl, string inputAssetName, MediaJobOutputMode outputAssetMode, string streamingPolicyName) { try { Job job = null; string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { bool videoAnalyzerPreset = false; bool audioAnalyzerPreset = false; Transform transform = mediaClient.GetEntity <Transform>(MediaEntity.Transform, transformName); foreach (TransformOutput transformOutput in transform.Outputs) { if (transformOutput.Preset is VideoAnalyzerPreset) { videoAnalyzerPreset = true; } else if (transformOutput.Preset is AudioAnalyzerPreset) { audioAnalyzerPreset = true; } } string insightId = null; Asset inputAsset = null; string assetDescription = null; if (!string.IsNullOrEmpty(inputAssetName)) { inputAsset = mediaClient.GetEntity <Asset>(MediaEntity.Asset, inputAssetName); assetDescription = inputAsset.Description; } if (mediaClient.IndexerEnabled() && (videoAnalyzerPreset || audioAnalyzerPreset)) { bool audioOnly = !videoAnalyzerPreset && audioAnalyzerPreset; insightId = mediaClient.IndexerUploadVideo(mediaClient.MediaAccount, inputAsset, null, jobPriority, true, audioOnly); } if (!string.IsNullOrEmpty(transformName)) { if (string.IsNullOrEmpty(inputFileUrl) && inputAsset != null) { StorageBlobClient blobClient = new StorageBlobClient(mediaClient.MediaAccount, inputAsset.StorageAccountName); MediaAsset mediaAsset = new MediaAsset(mediaClient, inputAsset); string fileName = mediaAsset.Files[0].Name; inputFileUrl = blobClient.GetDownloadUrl(inputAsset.Container, fileName, false); } string[] assetDescriptions = new string[] { assetDescription }; string[] assetAlternateIds = new string[] { insightId }; job = mediaClient.CreateJob(authToken, transformName, jobName, jobDescription, jobPriority, jobData, inputFileUrl, inputAssetName, outputAssetMode, assetDescriptions, assetAlternateIds, streamingPolicyName); } } return(Json(job)); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }
public JsonResult Data(string assetName, string fileName, string insightId) { try { JContainer insights = null; string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { if (!string.IsNullOrEmpty(insightId)) { if (mediaClient.IndexerInsightExists(insightId, out JObject insight)) { insights = insight; } } else { Asset asset = mediaClient.GetEntity <Asset>(MediaEntity.Asset, assetName); StorageBlobClient blobClient = new StorageBlobClient(mediaClient.MediaAccount, asset.StorageAccountName); CloudBlockBlob fileBlob = blobClient.GetBlockBlob(asset.Container, null, fileName); using (Stream fileStream = fileBlob.OpenReadAsync().Result) { StreamReader fileReader = new StreamReader(fileStream); string fileData = fileReader.ReadToEnd().TrimStart(); if (fileData.StartsWith("[")) { insights = JArray.Parse(fileData); } else { insights = JObject.Parse(fileData); } } } } return(Json(insights)); } catch (ValidationException ex) { Error error = new Error() { Type = HttpStatusCode.BadRequest, Message = ex.Message }; return(new JsonResult(error) { StatusCode = (int)error.Type }); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }
public JsonResult Workflow(string storageAccount, string assetName, string assetDescription, string assetAlternateId, string[] fileNames, bool adaptiveStreaming, bool thumbnailImages, bool videoAnalyzer, bool audioAnalyzer, bool videoIndexer, bool audioIndexer) { try { Asset[] inputAssets; List <Job> jobs = new List <Job>(); string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { Transform transform = mediaClient.CreateTransform(adaptiveStreaming, thumbnailImages, videoAnalyzer, audioAnalyzer, videoIndexer, audioIndexer); inputAssets = CreateInputAssets(mediaClient, storageAccount, assetName, assetDescription, assetAlternateId, fileNames); foreach (Asset inputAsset in inputAssets) { Job job = null; string insightId = null; if (mediaClient.IndexerEnabled() && (videoIndexer || audioIndexer)) { bool audioOnly = !videoIndexer && audioIndexer; insightId = mediaClient.IndexerUploadVideo(mediaClient.MediaAccount, inputAsset, null, Priority.Normal, true, audioOnly); } if (transform != null) { StorageBlobClient blobClient = new StorageBlobClient(mediaClient.MediaAccount, inputAsset.StorageAccountName); MediaAsset mediaAsset = new MediaAsset(mediaClient, inputAsset); string fileName = mediaAsset.Files[0].Name; string inputFileUrl = blobClient.GetDownloadUrl(inputAsset.Container, fileName, false); MediaJobOutputMode outputAssetMode = MediaJobOutputMode.SingleAsset; string[] outputAssetDescriptions = new string[] { assetDescription }; string[] outputAssetAlternateIds = new string[] { insightId }; PredefinedStreamingPolicy streamingPolicy = PredefinedStreamingPolicy.ClearStreamingOnly; job = mediaClient.CreateJob(authToken, transform.Name, null, null, Priority.Normal, null, inputFileUrl, inputAsset.Name, outputAssetMode, outputAssetDescriptions, outputAssetAlternateIds, streamingPolicy); } if (job != null) { if (!string.IsNullOrEmpty(insightId)) { job.CorrelationData.Add("insightId", insightId); } jobs.Add(job); } else { inputAsset.AlternateId = insightId; } } } return(jobs.Count > 0 ? Json(jobs.ToArray()) : Json(inputAssets)); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }
public JsonResult Block(string name, int chunk, int chunks, string storageAccount, string contentType) { string authToken = HomeController.GetAuthToken(Request, Response); User userProfile = new User(authToken); StorageBlobClient blobClient = new StorageBlobClient(userProfile.MediaAccount, storageAccount); Stream blockStream = Request.Form.Files[0].OpenReadStream(); string containerName = Constant.Storage.BlobContainer.MediaServices; blobClient.UploadBlock(blockStream, containerName, name, chunk, chunks, contentType); return(Json(chunk)); }
private void UploadIngestManifest(StorageBlobClient blobClient, MediaIngestManifest ingestManifest) { string ingestManifestJson = JsonConvert.SerializeObject(ingestManifest); string containerName = Constant.Storage.BlobContainer.MediaServices; string assetName = Path.GetFileNameWithoutExtension(ingestManifest.JobInputFileUrl); string fileName = string.Concat(Constant.Media.IngestManifest.TriggerPrefix, Constant.TextDelimiter.Manifest, assetName, Constant.Media.IngestManifest.FileExtension); CloudBlockBlob manifest = blobClient.GetBlockBlob(containerName, null, fileName); manifest.Properties.ContentType = Constant.Media.ContentType.IngestManifest; manifest.UploadTextAsync(ingestManifestJson).Wait(); }
public TrainSetManager(IPrincipal principal, ApiUserStore userStore, IMapper mapper, ITrainSetStore trainSetStore, ITwitterCollectionsStore twitterCollectionsStore, ITwitterSourcesStore twitterSourcesStore, IUserSocialsStore userSocialsStore, TwitterClient twitterClient, VReader vReader, StorageBlobClient storageBlobClient) : base(principal, userStore, mapper) { _trainSets = trainSetStore; _twitterCollectionsStore = twitterCollectionsStore; _twitterSourcesStore = twitterSourcesStore; _userSocialsStore = userSocialsStore; _twitterClient = twitterClient; _vReader = vReader; _storageBlobClient = storageBlobClient; }
private Asset[] CreateInputAssets(MediaClient mediaClient, string storageAccount, string assetName, string assetDescription, string assetAlternateId, string[] fileNames) { List <Asset> inputAssets = new List <Asset>(); StorageBlobClient blobClient = new StorageBlobClient(mediaClient.MediaAccount, storageAccount); foreach (string fileName in fileNames) { string sourceContainer = Constant.Storage.BlobContainer.MediaServices; Asset inputAsset = mediaClient.CreateAsset(blobClient, blobClient, storageAccount, assetName, assetDescription, assetAlternateId, sourceContainer, fileName); inputAssets.Add(inputAsset); } return(inputAssets.ToArray()); }
public JsonResult Create(int assetCount, string assetType, bool assetPublish) { try { string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { StorageBlobClient sourceBlobClient = new StorageBlobClient(); StorageBlobClient assetBlobClient = new StorageBlobClient(mediaClient.MediaAccount, mediaClient.PrimaryStorageAccount); for (int i = 1; i <= assetCount; i++) { List <Task> uploadTasks = new List <Task>(); string containerName = Constant.Storage.BlobContainer.MediaServices; string directoryPath = assetType; string assetName = MediaAsset.GetAssetName(sourceBlobClient, containerName, directoryPath, out MediaFile[] sourceFiles); assetName = string.Concat(i.ToString(), Constant.Media.Asset.NameDelimiter, assetName); Asset asset = mediaClient.CreateAsset(mediaClient.PrimaryStorageAccount, assetName); foreach (MediaFile sourceFile in sourceFiles) { CloudBlockBlob sourceBlob = sourceBlobClient.GetBlockBlob(containerName, directoryPath, sourceFile.Name); CloudBlockBlob assetBlob = assetBlobClient.GetBlockBlob(asset.Container, null, sourceFile.Name); Stream sourceStream = sourceBlob.OpenReadAsync().Result; Task uploadTask = assetBlob.UploadFromStreamAsync(sourceStream); uploadTasks.Add(uploadTask); } if (assetPublish) { Task.WaitAll(uploadTasks.ToArray()); string streamingPolicyName = assetType == Constant.Media.Asset.SingleBitrate ? PredefinedStreamingPolicy.DownloadOnly : PredefinedStreamingPolicy.ClearStreamingOnly; mediaClient.CreateLocator(asset.Name, asset.Name, streamingPolicyName, null); } } } return(Json(assetCount)); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }
public void Syndicate(string rssUrl = "https://channel9.msdn.com/Shows/AI-Show/feed/mp4high", int videoCount = Constant.Media.Channel9.DefaultIngestVideoCount) { StorageBlobClient blobClient = new StorageBlobClient(); string containerName = Constant.Storage.BlobContainer.MediaServices; string fileName = string.Concat(Constant.Media.IngestManifest.TriggerPrefix, Constant.Media.IngestManifest.FileExtension); CloudBlockBlob manifestFile = blobClient.GetBlockBlob(containerName, null, fileName); if (manifestFile.ExistsAsync().Result) { MediaIngestManifest ingestManifest; using (Stream manifestStream = manifestFile.OpenReadAsync().Result) { StreamReader manifestReader = new StreamReader(manifestStream); string manifestData = manifestReader.ReadToEnd(); ingestManifest = JsonConvert.DeserializeObject <MediaIngestManifest>(manifestData); } using (MediaClient mediaClient = new MediaClient(null, ingestManifest.MediaAccount)) { Account.DeleteEntities(mediaClient, false); } UploadIngestManifests(ingestManifest, rssUrl, videoCount); } }
private static MediaIngestManifest CreateAsset(MediaClient mediaClient, MediaIngestManifest ingestManifest, out Asset inputAsset, ILogger logger) { string storageAccount = mediaClient.PrimaryStorageAccount; string assetName = ingestManifest.AssetName; string assetDescription = ingestManifest.AssetDescription; string assetAlternateId = ingestManifest.AssetAlternateId; string sourceContainer = Constant.Storage.BlobContainer.MediaServices; string[] fileNames = ingestManifest.FileNames; StorageBlobClient assetBlobClient = new StorageBlobClient(ingestManifest.MediaAccount, storageAccount); inputAsset = mediaClient.CreateAsset(_blobClient, assetBlobClient, storageAccount, assetName, assetDescription, assetAlternateId, sourceContainer, fileNames); string logData = string.Concat("New Asset: ", JsonConvert.SerializeObject(inputAsset)); WriteLog(ingestManifest.Name, logData, logger, false); ingestManifest.AssetName = inputAsset.Name; if (string.IsNullOrEmpty(ingestManifest.JobInputFileUrl) && ingestManifest.JobInputMode == MediaJobInputMode.AssetFile) { string fileName = fileNames[0]; ingestManifest.JobInputFileUrl = assetBlobClient.GetDownloadUrl(inputAsset.Container, fileName, false); } return(ingestManifest); }
public NeuralManager(IPrincipal principal, ApiUserStore userStore, IMapper mapper, INeuralStore neuralStore, StorageBlobClient storageBlobClient) : base(principal, userStore, mapper) { _neuralStore = neuralStore; _storageBlobClient = storageBlobClient; }