Example #1
0
        public override void HandleExecute(ChainRequest request)
        {
            myRequest             = (ButlerProcessRequest)request;
            _MediaServicesContext = new CloudMediaContext(myRequest.MediaAccountName, myRequest.MediaAccountKey);
            myBlobManager         = BlobManagerFactory.CreateBlobManager(myRequest.ProcessConfigConn);
            allPorcessData        = myBlobManager.GetProcessConfig(myRequest.ButlerRequest.ControlFileUri, myRequest.ProcessTypeId);
            //1. Select VTT
            IAsset asset   = (from m in _MediaServicesContext.Assets select m).Where(m => m.Id == myRequest.AssetId).FirstOrDefault();
            var    vttFile = (from f in asset.AssetFiles select f).Where(f => f.Name.EndsWith(".vtt")).FirstOrDefault();

            vttFile.Download(myRequest.ProcessInstanceId);
            string readText = File.ReadAllText(myRequest.ProcessInstanceId);

            System.IO.File.Delete(myRequest.ProcessInstanceId);

            //2. Cognitive Service
            IAzureMLTextAnalyticsClient myClient = new AzureMLTextAnalyticsClient();
            Language myLanguage   = (Language)Enum.Parse(typeof(Language), allPorcessData.Read(DotControlConfigKeys.TextAnalitycsStepLanguage));
            string   apiURL       = allPorcessData.Read(DotControlConfigKeys.TextAnalitycsStepApiURL);
            string   apiKey       = allPorcessData.Read(DotControlConfigKeys.TextAnalitycsStepApiKey);
            FileType ft           = FileType.VTT;
            string   jsonResponse = myClient.keyPhrasesTxt(readText, myLanguage, ft, apiURL, apiKey);

            //3. Add File
            string assetFileName = "keyPhrases." + myRequest.ProcessInstanceId + ".txt";
            var    xf            = asset.AssetFiles.Create(assetFileName);

            File.WriteAllText(assetFileName, jsonResponse);
            xf.Upload(assetFileName);
            File.Delete(myRequest.ProcessInstanceId);
            asset.Update();
        }
Example #2
0
        public override void HandleExecute(ChainRequest request)
        {
            myRequest = (ButlerProcessRequest)request;
            var           myBlobManager  = BlobManagerFactory.CreateBlobManager(myRequest.ProcessConfigConn);
            IjsonKeyValue dotControlData = myBlobManager.GetProcessConfig(myRequest.ButlerRequest.ControlFileUri, myRequest.ProcessTypeId);

            switch (dotControlData.Read(DotControlConfigKeys.SelectAssetByType))
            {
            case "assetid":
                myRequest.AssetId = dotControlData.Read(DotControlConfigKeys.SelectAssetByValue);
                break;

            default:
                var    _MediaServicesContext = new CloudMediaContext(myRequest.MediaAccountName, myRequest.MediaAccountKey);
                string AssetName             = dotControlData.Read(DotControlConfigKeys.SelectAssetByValue);
                try
                {
                    IAsset asset = (from m in _MediaServicesContext.Assets select m).Where(m => m.Name == AssetName).FirstOrDefault();
                    myRequest.AssetId = asset.Id;
                }
                catch (Exception X)
                {
                    throw new Exception("Error Loading Asset by name " + AssetName);
                }

                break;
            }
        }
        public string GetMediaProcessorName(IjsonKeyValue ProcessConfigData, string keyName, string DefaultValue)
        {
            string theValue = DefaultValue;

            if (ProcessConfigData.Read(keyName) != "")
            {
                theValue = ProcessConfigData.Read(keyName);
            }
            return(theValue);
        }
        /// <summary>
        /// Send HTTP Get request with process instance ID
        /// </summary>
        private void HttpGetNotification()
        {
            //CallBack URL with token and all info except Transaction ID
            string url = dotControlConfig.Read(MediaButler.Common.DotControlConfigKeys.httpNotificationStepGetOnFinishUrl);
            //Add process Instance ID as value parameter on the URL
            var httpRequest = WebRequest.Create(url + myRequest.ProcessInstanceId);

            var httpResponse = (HttpWebResponse)httpRequest.GetResponse();

            using (var sr = new StreamReader(httpResponse.GetResponseStream()))
            {
                string xResponse = sr.ReadToEnd();
                Trace.TraceInformation(xResponse);
                myRequest.Log.Add(xResponse);
            }
        }
        public string GetMediaProcessorName(IjsonKeyValue dotControlData, IjsonKeyValue processData)
        {
            string theName = "Media Encoder Standard";

            if (dotControlData.Read(DotControlConfigKeys.GridEncodeStepMediaProcessorName) != "")
            {
                theName = dotControlData.Read(DotControlConfigKeys.GridEncodeStepMediaProcessorName);
            }
            else
            {
                if (processData.Read(DotControlConfigKeys.GridEncodeStepMediaProcessorName) != "")
                {
                    theName = processData.Read(DotControlConfigKeys.GridEncodeStepMediaProcessorName);
                }
            }
            return(theName);
        }
        public string[] GetLoadEncodignProfiles(IjsonKeyValue dotControlData, IjsonKeyValue processData, List <string> MezzanineFiles, string ProcessConfigConn, string StepConfiguration)
        {
            var myBlobManager = BlobManagerFactory.CreateBlobManager(ProcessConfigConn);

            string[] EncodingProfiles;
            int      profileId = 0;

            if (!string.IsNullOrEmpty(dotControlData.Read(DotControlConfigKeys.GridEncodeStepEncodeConfigList)))
            {
                //Definition encoders on instance level DotcControl File
                var Xlist = dotControlData.ReadArray(DotControlConfigKeys.GridEncodeStepEncodeConfigList).ToArray();
                EncodingProfiles = new string[Xlist.Count()];

                foreach (var profile in Xlist)
                {
                    string url = MezzanineFiles.Where(f => f.ToLower().EndsWith(profile.ToString().ToLower())).FirstOrDefault();
                    if (url == null)
                    {
                        throw new Exception("Encoding profile is not on file package!");
                    }
                    EncodingProfiles[profileId] = myBlobManager.ReadTextBlob(new Uri(url));
                    profileId += 1;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(processData.Read(DotControlConfigKeys.GridEncodeStepEncodeConfigList)))
                {
                    //Definition Encoders profile on process level
                    var profileNameList = processData.ReadArray(DotControlConfigKeys.GridEncodeStepEncodeConfigList).ToArray();
                    EncodingProfiles = new string[profileNameList.Count()];
                    foreach (var profileName in profileNameList)
                    {
                        EncodingProfiles[profileId] = myBlobManager.ReadTextBlob("mediabutlerbin", "encoderdefinitions/" + profileName);
                        profileId += 1;
                    }
                }
                else
                {
                    //Definition on Process definition
                    string encodigProfileFileName;
                    if (string.IsNullOrEmpty(StepConfiguration))
                    {
                        //Use default
                        encodigProfileFileName = "H264 Multiple Bitrate 1080p.json";
                    }
                    else
                    {
                        //Use process level definition
                        encodigProfileFileName = StepConfiguration;
                    }

                    EncodingProfiles = new string[] { LoadEncodeProfile(encodigProfileFileName, ProcessConfigConn) };
                }
            }
            return(EncodingProfiles);
        }
Example #7
0
        private void Setup()
        {
            //this.mySenGridData = new SenGridData();
            //mySenGridData = Newtonsoft.Json.JsonConvert.DeserializeObject<SenGridData>(this.StepConfiguration);
            var           myBlobManager = BlobManagerFactory.CreateBlobManager(myRequest.ProcessConfigConn);
            IjsonKeyValue myConfig      = myBlobManager.GetProcessConfig(myRequest.ButlerRequest.ControlFileUri, myRequest.ProcessTypeId);
            string        jsonTx        = myConfig.Read(DotControlConfigKeys.SendGridStepConfig);

            mySenGridData = JsonConvert.DeserializeObject <SenGridData>(jsonTx);
        }
        public override void HandleExecute(ChainRequest request)
        {
            myRequest             = (ButlerProcessRequest)request;
            _MediaServicesContext = new CloudMediaContext(myRequest.MediaAccountName, myRequest.MediaAccountKey);
            myBlobManager         = BlobManagerFactory.CreateBlobManager(myRequest.ProcessConfigConn);
            //IjsonKeyValue dotControlData = myBlobManager.GetDotControlData(myRequest.ButlerRequest.ControlFileUri);
            IjsonKeyValue dotControlData = myBlobManager.GetProcessConfig(myRequest.ButlerRequest.ControlFileUri, myRequest.ProcessTypeId);

            string searchServiceName = dotControlData.Read(DotControlConfigKeys.InjectTTMLSearchServiceName);
            string adminApiKey       = dotControlData.Read(DotControlConfigKeys.InjectTTMLadminApiKey);
            string indexName         = dotControlData.Read(DotControlConfigKeys.InjectTTMLindexName);

            SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(adminApiKey));

            if (!serviceClient.Indexes.Exists(indexName))
            {
                CreateVideoTextIndex(serviceClient, indexName);
            }

            IAsset asset = (from m in _MediaServicesContext.Assets select m).Where(m => m.Id == myRequest.AssetId).FirstOrDefault();

            UploadTTML(serviceClient, indexName, asset);
        }
        public override void HandleExecute(ChainRequest request)
        {
            myRequest   = (ButlerProcessRequest)request;
            blobManager = BlobManagerFactory.CreateBlobManager(myRequest.ProcessConfigConn);

            string jsonControlFile = blobManager.ReadTextBlob(new Uri(myRequest.ButlerRequest.ControlFileUri));

            dotControlConfig = new jsonKeyValue(jsonControlFile);
            if (dotControlConfig.Read(MediaButler.Common.DotControlConfigKeys.httpNotificationStepGetOnFinishUrl) != "")
            {
                //GET
                HttpGetNotification();
            }
            else
            {
                //POST
                HttpPostNotification();
            }
        }
Example #10
0
        private List <IJobConfiguration> GetJobConfig(string ProcessId, string InputAssetId, string OutPutAssetId)
        {
            List <IJobConfiguration> myJobs = new List <IJobConfiguration>();
            JArray MultiJobTaskEncode       = (JArray)allPorcessData.ReadArray("MultiJobTaskEncode");

            consolidateId = int.Parse(allPorcessData.Read("ConsolidateOutput"));

            for (int i = 0; i < MultiJobTaskEncode.Count(); i++)
            {
                string   ProcessorName   = (string)MultiJobTaskEncode[i]["ProcessorName"];
                string[] ProfileFileList = ((JArray)MultiJobTaskEncode[i]["ProfileFileList"]).ToObject <string[]>();
                string[] FilesToCopy     = ((JArray)MultiJobTaskEncode[i]["FilesToCopy"]).ToObject <string[]>();
                for (int profileId = 0; profileId < ProfileFileList.Count(); profileId++)
                {
                    ProfileFileList[profileId] = myBlobManager.ReadTextBlob("mediabutlerbin", "encoderdefinitions/" + ProfileFileList[profileId]);
                }
                JobConfiguration J = new JobConfiguration(ProcessorName, ProcessId);
                J.AddTask(ProfileFileList, InputAssetId, OutPutAssetId, FilesToCopy);
                myJobs.Add(J);
            }

            return(myJobs);
        }
Example #11
0
        public override void HandleExecute(ChainRequest request)
        {
            //1. Step Setup
            myRequest             = (ButlerProcessRequest)request;
            _MediaServicesContext = new CloudMediaContext(myRequest.MediaAccountName, myRequest.MediaAccountKey);
            myEncodigSupport      = new EncoderSupport(_MediaServicesContext);
            myBlobManager         = BlobManagerFactory.CreateBlobManager(myRequest.ProcessConfigConn);
            IjsonKeyValue dotControlData = myBlobManager.GetDotControlData(myRequest.ButlerRequest.ControlFileUri);
            IjsonKeyValue processData    = new jsonKeyValue(myBlobManager.GetButlerConfigurationValue(ProcessConfigKeys.DefualtPartitionKey, myRequest.ProcessTypeId + ".config"));

            IjsonKeyValue allPorcessData = myBlobManager.GetProcessConfig(myRequest.ButlerRequest.ControlFileUri, myRequest.ProcessTypeId);

            //2. Get Current Asset
            IAsset asset = (from m in _MediaServicesContext.Assets select m).Where(m => m.Id == myRequest.AssetId).FirstOrDefault();

            //3. JOB parameters
            string OutputAssetsName   = asset.Name + "_mbIndex2";
            string JobName            = string.Format("GridEncodeStep_{1}_{0}", myRequest.ProcessInstanceId, asset.Name);
            string MediaProcessorName = myEncodigSupport.GetMediaProcessorName(allPorcessData, DotControlConfigKeys.Index2EncodeStepMediaProcessorName, "Azure Media Indexer 2 Preview");

            string[] encodeConfigurations = myEncodigSupport.GetLoadEncodignProfiles(dotControlData, processData, DotControlConfigKeys.Index2EncodeStepEncodeConfigList, myRequest.ButlerRequest.MezzanineFiles, myRequest.ProcessConfigConn, this.StepConfiguration);

            //4. Execute JOB and Wait
            IJob currentJob = myEncodigSupport.ExecuteGridJob(OutputAssetsName, JobName, MediaProcessorName, encodeConfigurations, "Indexing Task", asset.Id, MyEncodigSupport_OnJobError, MyEncodigSupport_JobUpdate);

            //5. Copy subtitles files to input asste?
            if ("yes" == dotControlData.Read(DotControlConfigKeys.Index2PreviewCopySubTitles))
            {
                CopyCaptions(currentJob.OutputMediaAssets.FirstOrDefault(), asset);
                currentJob.OutputMediaAssets.FirstOrDefault().Delete();
            }
            else
            {
                myRequest.AssetId = currentJob.OutputMediaAssets.FirstOrDefault().Id;
            }
        }