示例#1
0
        public static OoyalaVideo GetOoyalaVideo(string assetId, VideoIndexerSettings settings)
        {
            if (settings == null || string.IsNullOrEmpty(settings.OoyalaKey) || string.IsNullOrEmpty(settings.OoyalaSecret))
            {
                return(null);
            }

            var api = new OoyalaAPI(settings.OoyalaKey, settings.OoyalaSecret);

            var output = new OoyalaVideo();

            var asset = api.get("assets/" + assetId, EmptyDict) as Hashtable;

            output.Description = asset?["description"] as string;
            output.Title       = asset?["name"] as string;

            var metadata = api.get($"assets/{assetId}/metadata", EmptyDict) as Hashtable;

            output.Keywords = (metadata?["keywords"] as string)?.Split(',')?.ToList();

            if (api.get($"assets/{assetId}/streams", EmptyDict) is ArrayList streams)
            {
                var q = from stream in streams.OfType <Hashtable>()
                        let streamInfo = stream["is_source"] as bool?
                                         where streamInfo == true
                                         select stream;

                var sourceStream = q.FirstOrDefault();
                output.Url = sourceStream?["url"] as string;
            }

            return(output);
        }
示例#2
0
        private static async Task IndexVideo(CrawlResponse reqBody, VideoIndexerSettings settings)
        {
            if (reqBody == null || string.IsNullOrEmpty(reqBody.Video) || !Uri.TryCreate(reqBody.Video, UriKind.Absolute, out Uri unused))
            {
                return;
            }

            //var account = CloudStorageAccount.Parse(await cogService.GetAzureStorageConnectionStringAsync());
            //var blobClient = account.CreateCloudBlobClient();

            //var container = blobClient.GetContainerReference(BlobCache.ToContainerName(DateTime.UtcNow, cogService.containerName));
            //await container.CreateIfNotExistsAsync();

            //var leaseBlob = container.GetBlockBlobReference(BlobCache.ToBlobName(reqBody.Site, reqBody.Id) + ".lease");
            //leaseBlob.

            using (var operation = Services.TelemetryClient.StartOperation <DependencyTelemetry>("Crawl.VideoIndexer.Enqueue"))
            {
                operation.Telemetry.Properties.Add("url", reqBody.Video);
                operation.Telemetry.Properties.Add("id", reqBody.Id);

                // https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns[?name][&privacy][&videoUrl][&language][&externalId][&metadata][&description][&partition][&callbackUrl][&indexingPreset][&streamingPreset]
                var url   = HttpUtility.UrlEncode(reqBody.Video);
                var id    = HttpUtility.UrlEncode(reqBody.Id);
                var query =
                    "Breakdowns/Api/Partner/Breakdowns" +
                    $"?externalId={id}" +
                    $"&videoUrl={url}" +
                    "&privacy=private&searchable=true";

                string name = reqBody.Title;
                if (string.IsNullOrEmpty(name))
                {
                    name = id;
                }

                query += "&name=" + name;

                if (!string.IsNullOrEmpty(reqBody.Description))
                {
                    query += "&description=" + reqBody.Description;
                }

                if (reqBody.Categories != null && reqBody.Categories.Count > 0)
                {
                    query += "&metadata=" + HttpUtility.UrlEncode(string.Join(" ", reqBody.Categories));
                }

                var localCogService = GetCognitiveService(settings);

                var client = await localCogService.GetHttpClientAsync();


                var httpResponse = await client.PostAsync(client.BaseAddress + query, new MultipartFormDataContent());

                operation.Telemetry.Success    = httpResponse.IsSuccessStatusCode;
                operation.Telemetry.ResultCode = httpResponse.StatusCode.ToString();
            }
        }
示例#3
0
        private static CognitiveService GetCognitiveService(VideoIndexerSettings settings)
        {
            var localCogService = cogService;
            var videoIndexerKey = settings?.VideoIndexerKey;

            if (!string.IsNullOrEmpty(videoIndexerKey))
            {
                localCogService = new CognitiveService("VideoIndexer", apiKey: videoIndexerKey);
            }

            return(localCogService);
        }
示例#4
0
        private static async Task <BlobContent> GetVideoIndexerBreakdownAsync(CrawlResponse reqBody, VideoIndexerSettings settings, TraceWriter log, CancellationToken cancellationToken)
        {
            using (var operation = Services.TelemetryClient.StartOperation <DependencyTelemetry>("Crawl.VideoIndexer.GetBreakdown"))
            {
                var localCogService = GetCognitiveService(settings);

                var client = await localCogService.GetHttpClientAsync();

                var id = HttpUtility.UrlEncode(reqBody.Id);
                var responseMessage = await client.GetAsync($"/Breakdowns/Api/Partner/Breakdowns/Search?externalId={id}", cancellationToken);

                if (!responseMessage.IsSuccessStatusCode)
                {
                    return(null);
                }

                var videoIndexerResponseStr = await responseMessage.Content.ReadAsStringAsync();

                var videoIndexerResponse = JsonConvert.DeserializeObject <VideoIndexerSearchResult>(videoIndexerResponseStr);
                var breakdownId          = videoIndexerResponse.Results?.FirstOrDefault()?.Id;
                if (breakdownId == null)
                {
                    return(null);
                }

                return(await localCogService.RequestAsync(
                           log,
                           reqBody.Site,
                           reqBody.Id,
                           $"/Breakdowns/Api/Partner/Breakdowns/{breakdownId}",
                           reqBody.ForceRefresh,
                           isPost : false,
                           cancellationToken : cancellationToken));
            }
        }