コード例 #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);
        }
コード例 #2
0
        private static void PublishAnalytics(MediaClient mediaClient, MediaPublish contentPublish, IJob job, ITask[] encoderTasks)
        {
            IAsset encoderOutput = encoderTasks.Length == 0 ? null : encoderTasks[0].OutputAssets[0];

            string[]   accountCredentials = new string[] { contentPublish.StorageAccountName, contentPublish.StorageAccountKey };
            BlobClient blobClient         = new BlobClient(accountCredentials);
            string     processorId1       = Constant.Media.ProcessorId.VideoAnnotation;
            string     processorId2       = Constant.Media.ProcessorId.FaceDetection;
            string     processorId3       = Constant.Media.ProcessorId.FaceRedaction;
            string     processorId4       = Constant.Media.ProcessorId.MotionDetection;
            string     processorId5       = Constant.Media.ProcessorId.ContentModeration;
            string     processorId6       = Constant.Media.ProcessorId.CharacterRecognition;

            string[] processorIds  = new string[] { processorId1, processorId2, processorId3, processorId4, processorId5, processorId6 };
            ITask[]  analyticTasks = GetJobTasks(job, processorIds);
            using (DocumentClient documentClient = new DocumentClient())
            {
                foreach (ITask analyticTask in analyticTasks)
                {
                    PublishAnalytics(blobClient, documentClient, contentPublish, analyticTask, encoderOutput);
                }
            }
            processorId1  = Constant.Media.ProcessorId.SpeechAnalyzer;
            processorIds  = new string[] { processorId1 };
            analyticTasks = GetJobTasks(job, processorIds);
            foreach (ITask analyticTask in analyticTasks)
            {
                PublishTextTracks(blobClient, analyticTask, encoderOutput);
            }
        }
コード例 #3
0
ファイル: Workflow.cs プロジェクト: lulzzz/SkyMedia
        private static void TrackJob(string directoryId, string authToken, IJob job, MediaJobTask[] jobTasks)
        {
            User authUser = new User(authToken);

            string storageAccountName = job.InputMediaAssets[0].StorageAccountName;
            string storageAccountKey  = Storage.GetAccountKey(authToken, storageAccountName);

            MediaPublish contentPublish = new MediaPublish()
            {
                PartitionKey       = authUser.MediaAccount.Id,
                RowKey             = job.Id,
                MediaAccount       = authUser.MediaAccount,
                StorageAccountName = storageAccountName,
                StorageAccountKey  = storageAccountKey,
                UserId             = authUser.Id,
                MobileNumber       = authUser.MobileNumber
            };

            TableClient tableClient = new TableClient();
            string      tableName   = Constant.Storage.Table.ContentPublish;

            tableClient.InsertEntity(tableName, contentPublish);

            ContentProtection[] contentProtections = MediaClient.GetContentProtections(directoryId, job, jobTasks);
            foreach (ContentProtection contentProtection in contentProtections)
            {
                tableName = Constant.Storage.Table.ContentProtection;
                contentProtection.PartitionKey = contentPublish.RowKey;
                tableClient.InsertEntity(tableName, contentProtection);
            }
        }
コード例 #4
0
ファイル: Account.cs プロジェクト: lulzzz/SkyMedia
        private static void DeleteJob(string accountId, IJob job)
        {
            TableClient  tableClient    = new TableClient();
            string       tableName      = Constant.Storage.Table.ContentPublish;
            MediaPublish contentPublish = tableClient.GetEntity <MediaPublish>(tableName, accountId, job.Id);

            if (contentPublish != null)
            {
                tableClient.DeleteEntity(tableName, contentPublish);
                MediaClient.DeleteContentProtections(tableClient, contentPublish.RowKey);
            }
            job.Delete();
        }
コード例 #5
0
        public static MediaPublished PublishContent(string queueName)
        {
            MediaPublished mediaPublished = null;
            QueueClient    queueClient    = new QueueClient();
            MediaPublish   contentPublish = queueClient.GetMessage <MediaPublish>(queueName, out string messageId, out string popReceipt);

            if (contentPublish != null)
            {
                mediaPublished = PublishContent(contentPublish);
                queueClient.DeleteMessage(queueName, messageId, popReceipt);
            }
            return(mediaPublished);
        }
コード例 #6
0
        private void PublishInsight(string authToken, string indexId)
        {
            User         authUser       = new User(authToken);
            MediaPublish insightPublish = new MediaPublish
            {
                PartitionKey = authUser.MediaAccount.Id,
                RowKey       = indexId,
                MediaAccount = authUser.MediaAccount
            };
            TableClient tableClient = new TableClient();
            string      tableName   = Constant.Storage.Table.InsightPublish;

            tableClient.UpsertEntity(tableName, insightPublish);
        }
コード例 #7
0
        public static MediaPublished PublishContent(MediaPublish contentPublish)
        {
            string accountId = contentPublish.PartitionKey;
            string jobId     = contentPublish.RowKey;

            MediaClient mediaClient = new MediaClient(contentPublish.MediaAccount);
            IJob        job         = mediaClient.GetEntityById(MediaEntity.Job, jobId) as IJob;

            MediaPublished mediaPublished = null;

            if (job != null)
            {
                mediaClient.SetProcessorUnits(job, null, ReservedUnitType.Basic, false);
                PublishJob(mediaClient, job, contentPublish);
                mediaPublished = new MediaPublished()
                {
                    UserId        = contentPublish.UserId,
                    MobileNumber  = contentPublish.MobileNumber,
                    StatusMessage = GetNotificationMessage(accountId, job)
                };
            }
            return(mediaPublished);
        }
コード例 #8
0
 private static void PublishJob(MediaClient mediaClient, IJob job, MediaPublish contentPublish)
 {
     ITask[] encoderTasks = GetEncoderTasks(job);
     if (encoderTasks.Length == 0)
     {
         foreach (IAsset inputAsset in job.InputMediaAssets)
         {
             PublishAnalytics(mediaClient, contentPublish, job, encoderTasks);
         }
     }
     else
     {
         foreach (ITask encoderTask in encoderTasks)
         {
             ContentProtection contentProtection = GetContentProtection(job.Id, encoderTask.Id);
             foreach (IAsset outputAsset in encoderTask.OutputAssets)
             {
                 PublishAsset(mediaClient, outputAsset, contentProtection);
                 PublishAnalytics(mediaClient, contentPublish, job, encoderTasks);
             }
         }
     }
 }
コード例 #9
0
        public static void PurgePublishInsight(TableClient tableClient)
        {
            DocumentClient documentClient = new DocumentClient();
            string         collectionId   = Constant.Database.Collection.ContentInsight;

            JObject[] documents = documentClient.GetDocuments(collectionId);
            foreach (JObject document in documents)
            {
                if (document["accountId"] != null)
                {
                    MediaAccount mediaAccount = new MediaAccount()
                    {
                        Id          = document["accountId"].ToString(),
                        DomainName  = document["accountDomain"].ToString(),
                        EndpointUrl = document["accountEndpoint"].ToString(),
                        ClientId    = document["clientId"].ToString(),
                        ClientKey   = document["clientKey"].ToString()
                    };
                    string assetId = document["assetId"].ToString();

                    MediaClient mediaClient = new MediaClient(mediaAccount);
                    IAsset      asset       = mediaClient.GetEntityById(MediaEntity.Asset, assetId) as IAsset;
                    if (asset == null)
                    {
                        string documentId = document["id"].ToString();
                        documentClient.DeleteDocument(collectionId, documentId);

                        string       tableName      = Constant.Storage.Table.InsightPublish;
                        MediaPublish insightPublish = tableClient.GetEntity <MediaPublish>(tableName, mediaAccount.Id, documentId);
                        if (insightPublish != null)
                        {
                            tableClient.DeleteEntity(tableName, insightPublish);
                        }
                    }
                }
            }
        }
コード例 #10
0
ファイル: Account.cs プロジェクト: lulzzz/SkyMedia
        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();
        }
コード例 #11
0
        private static void PublishAnalytics(BlobClient blobClient, DocumentClient documentClient, MediaPublish contentPublish, ITask jobTask, IAsset encoderOutput)
        {
            foreach (IAsset outputAsset in jobTask.OutputAssets)
            {
                string[] fileNames = GetFileNames(outputAsset, Constant.Media.FileExtension.Json);
                foreach (string fileName in fileNames)
                {
                    string         documentData        = string.Empty;
                    string         sourceContainerName = outputAsset.Uri.Segments[1];
                    CloudBlockBlob sourceBlob          = blobClient.GetBlob(sourceContainerName, null, fileName);
                    using (Stream sourceStream = sourceBlob.OpenRead())
                    {
                        StreamReader streamReader = new StreamReader(sourceStream);
                        documentData = streamReader.ReadToEnd();
                    }

                    JObject document = JObject.Parse(documentData);
                    document = DocumentClient.SetContext(document, contentPublish.MediaAccount, outputAsset.Id);
                    MediaProcessor?mediaProcessor = Processor.GetMediaProcessor(jobTask.MediaProcessorId);
                    string         documentId     = UpsertDocument(documentClient, document, mediaProcessor.Value, outputAsset, fileName);

                    if (encoderOutput != null)
                    {
                        string assetFileName = mediaProcessor.Value.ToString();
                        if (!string.IsNullOrEmpty(documentId))
                        {
                            assetFileName = string.Concat(assetFileName, Constant.TextDelimiter.Identifier, documentId);
                        }
                        assetFileName = string.Concat(assetFileName, Constant.Media.FileExtension.Json);

                        IAssetFile assetFile = encoderOutput.AssetFiles.Create(assetFileName);
                        using (Stream sourceStream = sourceBlob.OpenRead())
                        {
                            StreamReader streamReader = new StreamReader(sourceStream);
                            assetFile.Upload(sourceStream);
                        }
                    }
                }
            }
        }