Esempio n. 1
0
        private static MediaInsight GetMediaInsight(MediaClient mediaClient, Asset asset)
        {
            MediaInsight mediaInsight = new MediaInsight();

            if (mediaClient.IndexerEnabled())
            {
                using (DatabaseClient databaseClient = new DatabaseClient(false))
                {
                    string         collectionId = Constant.Database.Collection.MediaAssets;
                    MediaAssetLink assetLink    = databaseClient.GetDocument <MediaAssetLink>(collectionId, asset.Name);
                    if (assetLink != null)
                    {
                        string insightId = null;
                        if (assetLink.JobOutputs.ContainsKey(MediaTransformPreset.VideoIndexer))
                        {
                            insightId = assetLink.JobOutputs[MediaTransformPreset.VideoIndexer];
                        }
                        else if (assetLink.JobOutputs.ContainsKey(MediaTransformPreset.AudioIndexer))
                        {
                            insightId = assetLink.JobOutputs[MediaTransformPreset.AudioIndexer];
                        }
                        if (!string.IsNullOrEmpty(insightId) && mediaClient.IndexerInsightExists(insightId, out JObject insight))
                        {
                            mediaInsight.WidgetUrl = mediaClient.IndexerGetInsightUrl(insightId);
                            mediaInsight.ViewToken = insight["videos"][0]["viewToken"].ToString();
                        }
                    }
                }
            }
            return(mediaInsight);
        }
Esempio n. 2
0
 private void SetOutputAssetLink(MediaTransformPreset[] transformPresets, JobOutputAsset[] jobOutputs, MediaJobOutputInsight outputInsight)
 {
     if (transformPresets.Length > 1 || !string.IsNullOrEmpty(outputInsight.Id))
     {
         string encodingOutputAssetName = null;
         Dictionary <MediaTransformPreset, string> jobOutputAssets = new Dictionary <MediaTransformPreset, string>();
         for (int i = 0; i < transformPresets.Length; i++)
         {
             MediaTransformPreset transformPreset = transformPresets[i];
             if (transformPreset == MediaTransformPreset.AdaptiveStreaming || transformPreset == MediaTransformPreset.ContentAwareEncoding)
             {
                 encodingOutputAssetName = jobOutputs[i].AssetName;
             }
             else
             {
                 jobOutputAssets.Add(transformPreset, jobOutputs[i].AssetName);
             }
         }
         if (!string.IsNullOrEmpty(outputInsight.Id))
         {
             if (outputInsight.VideoIndexer)
             {
                 jobOutputAssets.Add(MediaTransformPreset.VideoIndexer, outputInsight.Id);
             }
             if (outputInsight.AudioIndexer)
             {
                 jobOutputAssets.Add(MediaTransformPreset.AudioIndexer, outputInsight.Id);
             }
         }
         if (!string.IsNullOrEmpty(encodingOutputAssetName))
         {
             MediaAssetLink assetLink = new MediaAssetLink()
             {
                 AssetName    = encodingOutputAssetName,
                 JobOutputs   = jobOutputAssets,
                 MediaAccount = this.MediaAccount,
                 UserAccount  = this.UserAccount
             };
             using (DatabaseClient databaseClient = new DatabaseClient(true))
             {
                 string collectionId = Constant.Database.Collection.MediaAssets;
                 databaseClient.UpsertDocument(collectionId, assetLink);
             }
         }
     }
 }
Esempio n. 3
0
        public static MediaTrack[] GetMediaTracks(MediaClient mediaClient, Asset asset)
        {
            List <MediaTrack> mediaTracks = new List <MediaTrack>();

            using (DatabaseClient databaseClient = new DatabaseClient(false))
            {
                string         collectionId = Constant.Database.Collection.MediaAssets;
                MediaAssetLink assetLink    = databaseClient.GetDocument <MediaAssetLink>(collectionId, asset.Name);
                if (assetLink != null)
                {
                    string trackType      = null;
                    string trackLabel     = null;
                    string trackSourceUrl = null;
                    if (assetLink.JobOutputs.ContainsKey(MediaTransformPreset.AudioIndexer))
                    {
                        trackType  = Constant.Media.Track.AudioTranscript.CaptionsType;
                        trackLabel = Constant.Media.Track.AudioTranscript.CaptionsLabel;
                        string insightId = assetLink.JobOutputs[MediaTransformPreset.AudioIndexer];
                        trackSourceUrl = mediaClient.IndexerGetCaptionsUrl(insightId);
                    }
                    else if (assetLink.JobOutputs.ContainsKey(MediaTransformPreset.AudioAnalyzer))
                    {
                        trackType  = Constant.Media.Track.AudioTranscript.SubtitlesType;
                        trackLabel = Constant.Media.Track.AudioTranscript.SubtitlesLabel;
                        string assetName = assetLink.JobOutputs[MediaTransformPreset.AudioAnalyzer];
                        string fileName  = Constant.Media.Track.AudioTranscript.FileName;
                        trackSourceUrl = mediaClient.GetDownloadUrl(assetName, fileName);
                    }
                    if (!string.IsNullOrEmpty(trackSourceUrl))
                    {
                        MediaTrack mediaTrack = new MediaTrack()
                        {
                            Type      = trackType,
                            Label     = trackLabel,
                            SourceUrl = trackSourceUrl
                        };
                        mediaTracks.Add(mediaTrack);
                    }
                }
            }
            return(mediaTracks.ToArray());
        }