Exemplo n.º 1
0
        public static MediaPublished PublishInsight(MediaPublish insightPublish)
        {
            string accountId = insightPublish.PartitionKey;
            string indexId   = insightPublish.RowKey;

            IndexerClient indexerClient = new IndexerClient(accountId, insightPublish.MediaAccount.IndexerKey);
            JObject       index         = indexerClient.GetIndex(indexId, null, false);

            MediaPublished mediaPublished = null;
            string         assetId        = IndexerClient.GetAssetId(index);

            if (!string.IsNullOrEmpty(assetId))
            {
                MediaClient mediaClient = new MediaClient(insightPublish.MediaAccount);
                IAsset      asset       = mediaClient.GetEntityById(MediaEntity.Asset, assetId) as IAsset;

                DocumentClient documentClient = new DocumentClient();
                index = DocumentClient.SetContext(index, insightPublish.MediaAccount, assetId);
                string documentId = UpsertDocument(documentClient, index, MediaProcessor.VideoIndexer, asset, null);

                mediaPublished = new MediaPublished
                {
                    AssetId       = assetId,
                    IndexId       = indexId,
                    DocumentId    = documentId,
                    UserId        = insightPublish.UserId,
                    MobileNumber  = insightPublish.MobileNumber,
                    StatusMessage = string.Empty
                };
            }
            return(mediaPublished);
        }
Exemplo n.º 2
0
        private static MediaTrack[] GetTextTracks(MediaClient mediaClient, IndexerClient indexerClient, IAsset asset)
        {
            List <MediaTrack> textTracks = new List <MediaTrack>();
            WebClient         webClient  = new WebClient();
            string            documentId = DocumentClient.GetDocumentId(asset, out bool videoIndexer);

            if (!string.IsNullOrEmpty(documentId) && videoIndexer && indexerClient.IndexerEnabled)
            {
                string             webVttUrl      = indexerClient.GetWebVttUrl(documentId, null);
                HttpRequestMessage requestMessage = webClient.GetRequest(HttpMethod.Get, webVttUrl);
                string             webVttData     = webClient.GetResponse <string>(requestMessage);
                JObject            index          = indexerClient.GetIndex(documentId, null, false);
                string             languageLabel  = IndexerClient.GetLanguageLabel(index);
                MediaTrack         textTrack      = new MediaTrack()
                {
                    Type      = GetTextTrackType(webVttData),
                    Label     = languageLabel,
                    SourceUrl = webVttUrl,
                };
                textTracks.Add(textTrack);
            }
            string[] webVttUrls = mediaClient.GetWebVttUrls(asset);
            for (int i = 0; i < webVttUrls.Length; i++)
            {
                string             webVttUrl      = webVttUrls[i];
                HttpRequestMessage requestMessage = webClient.GetRequest(HttpMethod.Get, webVttUrl);
                string             webVttData     = webClient.GetResponse <string>(requestMessage);
                string             languageLabel  = Language.GetLanguageLabel(webVttUrl);
                if (!string.IsNullOrEmpty(webVttUrl))
                {
                    MediaTrack textTrack = new MediaTrack()
                    {
                        Type      = GetTextTrackType(webVttData),
                        Label     = languageLabel,
                        SourceUrl = webVttUrl,
                    };
                    textTracks.Add(textTrack);
                }
            }
            return(textTracks.ToArray());
        }
Exemplo n.º 3
0
        private static void DeleteAsset(string authToken, string accountId, MediaClient mediaClient, IAsset asset)
        {
            string documentId = DocumentClient.GetDocumentId(asset, out bool videoIndexer);

            if (!string.IsNullOrEmpty(documentId))
            {
                DocumentClient documentClient = new DocumentClient();
                string         collectionId   = Constant.Database.Collection.ContentInsight;
                documentClient.DeleteDocument(collectionId, documentId);
                if (videoIndexer)
                {
                    IndexerClient indexerClient = new IndexerClient(authToken);
                    if (indexerClient.IndexerEnabled)
                    {
                        indexerClient.DeleteVideo(documentId, true);
                    }

                    TableClient  tableClient    = new TableClient();
                    string       tableName      = Constant.Storage.Table.InsightPublish;
                    MediaPublish insightPublish = tableClient.GetEntity <MediaPublish>(tableName, accountId, documentId);
                    if (insightPublish != null)
                    {
                        tableClient.DeleteEntity(tableName, insightPublish);
                    }
                }
            }
            foreach (ILocator locator in asset.Locators)
            {
                locator.Delete();
            }
            for (int i = asset.DeliveryPolicies.Count - 1; i >= 0; i--)
            {
                asset.DeliveryPolicies.RemoveAt(i);
            }
            asset.Delete();
        }
Exemplo n.º 4
0
        public static MediaJob GetJob(string authToken, MediaClient mediaClient, MediaJob mediaJob, MediaJobInput[] jobInputs)
        {
            List <MediaJobTask> jobTasks = new List <MediaJobTask>();

            foreach (MediaJobTask jobTask in mediaJob.Tasks)
            {
                MediaJobTask[] tasks = null;
                switch (jobTask.MediaProcessor)
                {
                case MediaProcessor.EncoderStandard:
                case MediaProcessor.EncoderPremium:
                    tasks = GetEncoderTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.VideoIndexer:
                    IndexerClient indexerClient = new IndexerClient(authToken);
                    if (indexerClient.IndexerEnabled)
                    {
                        foreach (MediaJobInput jobInput in jobInputs)
                        {
                            IAsset asset      = mediaClient.GetEntityById(MediaEntity.Asset, jobInput.AssetId) as IAsset;
                            string documentId = DocumentClient.GetDocumentId(asset, out bool videoIndexer);
                            if (videoIndexer)
                            {
                                indexerClient.ResetIndex(authToken, documentId);
                            }
                            else
                            {
                                indexerClient.IndexVideo(authToken, mediaClient, asset, jobTask.ContentIndexer);
                            }
                        }
                    }
                    break;

                case MediaProcessor.VideoAnnotation:
                    tasks = GetVideoAnnotationTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.VideoSummarization:
                    tasks = GetVideoSummarizationTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.FaceDetection:
                    tasks = GetFaceDetectionTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.SpeechAnalyzer:
                    tasks = GetSpeechAnalyzerTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.MotionDetection:
                    tasks = GetMotionDetectionTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.ContentModeration:
                    tasks = GetContentModerationTasks(mediaClient, jobTask, jobInputs);
                    break;

                case MediaProcessor.CharacterRecognition:
                    tasks = GetCharacterRecognitionTasks(mediaClient, jobTask, jobInputs);
                    break;
                }
                if (tasks != null)
                {
                    jobTasks.AddRange(tasks);
                }
            }
            mediaJob.Tasks = jobTasks.ToArray();
            if (string.IsNullOrEmpty(mediaJob.Name))
            {
                mediaJob.Name = jobInputs[0].AssetName;
            }
            return(mediaJob);
        }
Exemplo n.º 5
0
        private static MediaStream[] GetMediaStreams(string authToken, MediaClient mediaClient, IAsset asset, bool clipperView, bool filtersOnly)
        {
            List <MediaStream> mediaStreams = new List <MediaStream>();

            IndexerClient indexerClient = new IndexerClient(authToken);

            List <MediaInsight> contentInsight = new List <MediaInsight>();

            if (!clipperView)
            {
                string documentId = DocumentClient.GetDocumentId(asset, out bool videoIndexer);
                if (!string.IsNullOrEmpty(documentId) && videoIndexer && indexerClient.IndexerEnabled)
                {
                    MediaInsight insight = new MediaInsight()
                    {
                        ProcessorId   = Processor.GetProcessorId(MediaProcessor.VideoIndexer, null),
                        ProcessorName = Processor.GetProcessorName(MediaProcessor.VideoIndexer),
                        DocumentId    = documentId,
                        SourceUrl     = indexerClient.GetInsightUrl(documentId, true)
                    };
                    contentInsight.Add(insight);
                }

                string[] fileNames = MediaClient.GetFileNames(asset, Constant.Media.FileExtension.Json);
                foreach (string fileName in fileNames)
                {
                    string[] fileNameInfo = fileName.Split(Constant.TextDelimiter.Identifier);
                    if (Enum.TryParse(fileNameInfo[0], out MediaProcessor processor) && fileNameInfo.Length == 2)
                    {
                        documentId = fileNameInfo[1].Replace(Constant.Media.FileExtension.Json, string.Empty);
                        MediaInsight insight = new MediaInsight()
                        {
                            ProcessorId   = Processor.GetProcessorId(processor, null),
                            ProcessorName = Processor.GetProcessorName(processor),
                            DocumentId    = documentId,
                            SourceUrl     = string.Empty
                        };
                        contentInsight.Add(insight);
                    }
                }

                contentInsight.Sort(OrderByProcessor);
            }

            MediaStream mediaStream = new MediaStream()
            {
                Id     = asset.Id,
                Name   = asset.Name,
                Type   = "asset",
                Source = new StreamSource()
                {
                    Src            = mediaClient.GetLocatorUrl(asset),
                    ProtectionInfo = mediaClient.GetStreamProtections(authToken, asset)
                },
                TextTracks     = GetTextTracks(mediaClient, indexerClient, asset),
                ContentInsight = contentInsight.ToArray(),
            };

            if (!filtersOnly)
            {
                mediaStreams.Add(mediaStream);
            }

            foreach (IStreamingAssetFilter assetFilter in asset.AssetFilters)
            {
                MediaStream filteredStream = mediaStream.DeepCopy();
                filteredStream.Id         = assetFilter.Id;
                filteredStream.Name       = string.Concat(mediaStream.Name, "<br><br>+ ", assetFilter.Name);
                filteredStream.Type       = "filter";
                filteredStream.Source.Src = string.Concat(filteredStream.Source.Src, "(filter=", assetFilter.Name, ")");
                mediaStreams.Add(filteredStream);
            }

            return(mediaStreams.ToArray());
        }