Skip to content

Commit

Permalink
Reducing calls to Video Indexer API by making videos public.
Browse files Browse the repository at this point in the history
  • Loading branch information
efonsecab committed Apr 14, 2024
1 parent b58db18 commit 17fedf2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public partial class VideoInfo

public int? VideoIndexingProcessingPercentage { get; set; }

[StringLength(1000)]
public string PublishedUrl { get; set; }

[ForeignKey("ApplicationUserId")]
[InverseProperty("VideoInfo")]
public virtual AspNetUsers ApplicationUser { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public class VideoInfoModel : IListModel
public string? EnglishCaptions { get; set; }
public int LifetimeSessions { get; set; }
public TimeSpan LifetimeWatchTime { get; set; }
public string? PublishedUrl { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public class IndexVideoFromUriParameters
$"&language={indexVideoFromUriParameters.Language}" +
$"&videoUrl={HttpUtility.UrlEncode(indexVideoFromUriParameters.VideoUri!.ToString())}" +
$"&fileName={HttpUtility.UrlEncode(indexVideoFromUriParameters.FileName)}" +
$"&indexingPreset={indexVideoFromUriParameters.IndexingPreset}";
$"&indexingPreset={indexVideoFromUriParameters.IndexingPreset}" +
$"&Privacy=Public";
requestUrl +=
$"&sendSuccessEmail={true}";
httpClient.DefaultRequestHeaders.Authorization =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,39 @@ CancellationToken cancellationToken
.ToArrayAsync(cancellationToken);
return result;
}

public async Task<VideoInfoModel?> GetVideoInfoByVideoIdAsync(string videoId,
CancellationToken cancellationToken)
{
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
var result = await dbContext.VideoInfo
.Where(p => p.VideoId == videoId)
.AsNoTracking()
.Select(p => new VideoInfoModel
{
VideoInfoId = p.VideoInfoId,
AccountId = p.AccountId,
VideoId = p.VideoId,
Location = p.Location,
Name = p.Name,
Description = p.Description,
FileName = p.FileName,
VideoBloblUrl = p.VideoBloblUrl,
IndexedVideoUrl = p.IndexedVideoUrl,
ApplicationUserId = p.ApplicationUserId,
VideoIndexStatusId = p.VideoIndexStatusId,
VideoDurationInSeconds = p.VideoDurationInSeconds,
VideoIndexSourceClass = p.VideoIndexSourceClass,
Price = p.Price,
ExternalVideoSourceUrl = p.ExternalVideoSourceUrl,
VideoLanguageCode = p.VideoLanguageCode,
VideoVisibilityId = p.VideoVisibilityId,
ThumbnailUrl = p.ThumbnailUrl,
YouTubeVideoId = p.YouTubeVideoId,
PublishedUrl = p.PublishedUrl
})
.SingleOrDefaultAsync(cancellationToken);
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
[VideoIndexJSON] NVARCHAR(MAX) NULL,
[VideoThumbnailPhotoId] BIGINT NULL,
[VideoIndexingProcessingPercentage] INT NULL DEFAULT 0,
[PublishedUrl] NVARCHAR(1000) NULL,
CONSTRAINT [FK_VideoInfo_VideoIndexStatus] FOREIGN KEY ([VideoIndexStatusId]) REFERENCES [FairPlayTube].[VideoIndexStatus]([VideoIndexStatusId]),
CONSTRAINT [FK_VideoInfo_VideoVisibility] FOREIGN KEY ([VideoVisibilityId]) REFERENCES [FairPlayTube].[VideoVisibility]([VideoVisibilityId]),
CONSTRAINT [FK_VideoInfo_Photo_Thumbnail] FOREIGN KEY ([VideoThumbnailPhotoId]) REFERENCES [dbo].[Photo]([PhotoId])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ await dbContext.VideoIndexingTransaction.AddAsync(new VideoIndexingTransaction()
var completedVideoIndex = await azureVideoIndexerService.GetVideoIndexAsync(
singleVideoEntity.VideoId, getviTokenResult.AccessToken!,
stoppingToken);
singleVideoEntity.PublishedUrl = completedVideoIndex!.videos![0].publishedUrl;
singleVideoEntity.VideoIndexJson = JsonSerializer.Serialize(completedVideoIndex);
InsertInsights(singleVideoEntity, completedVideoIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

@rendermode NoPreRender

@inject AzureVideoIndexerServiceConfiguration azureVideoIndexerServiceConfiguration
@inject AzureVideoIndexerService azureVideoIndexerService
@inject IJSRuntime jsRuntime
@inject VideoWatchTimeService videoWatchTimeService
@inject ILogger<WatchVideo> logger;
@inject IUserProviderService userProviderService
@inject SupportedLanguageService supportedLanguageService

@inject VideoInfoService videoInfoService
@inject AzureVideoIndexerServiceConfiguration azureVideoIndexerServiceConfiguration

<FluentLabel Typo="Typography.H3">WatchVideo</FluentLabel>

Expand Down Expand Up @@ -55,8 +54,6 @@ else
public string? VideoId { get; set; }
private static IComponentRenderMode NoPreRender = new InteractiveServerRenderMode(prerender: false);
private bool IsBusy { get; set; }
private GetVideoIndexResponseModel? videoIndex { get; set; }
private GetAccessTokenResponseModel? viAccessTokenResponse { get; set; }
private CancellationTokenSource cancellationTokenSource = new();
private bool UseFallbackMode { get; set; }
private string? FallbackModeUrl { get; set; }
Expand All @@ -75,13 +72,11 @@ else
{
this.IsBusy = true;
StateHasChanged();
var armAccessToken = await azureVideoIndexerService.AuthenticateToAzureArmAsync();
this.viAccessTokenResponse = await azureVideoIndexerService
.GetAccessTokenForArmAccountAsync(armAccessToken, this.cancellationTokenSource.Token);
this.videoIndex = await azureVideoIndexerService
.GetVideoIndexAsync(this.VideoId!, viAccessTokenResponse!.AccessToken!,
this.cancellationTokenSource.Token);
this.VideoUrl = $"{videoIndex!.videos![0].publishedUrl}?accessToken={viAccessTokenResponse.AccessToken}";
var videoInfo = await this.videoInfoService.GetVideoInfoByVideoIdAsync(
this.VideoId!,
this.cancellationTokenSource.Token
);
this.VideoUrl = videoInfo!.PublishedUrl;
this.SupportedLanguages = await supportedLanguageService
.GetAllSupportedLanguageAsync(this.cancellationTokenSource.Token);
StateHasChanged();
Expand Down Expand Up @@ -130,7 +125,7 @@ else

private void OnUseFallbackMode()
{
this.FallbackModeUrl = $"https://www.videoindexer.ai/embed/player/{this.videoIndex!.accountId}/{this.videoIndex.id}/?locale=en&location={azureVideoIndexerServiceConfiguration.Location}&accessToken={this.viAccessTokenResponse!.AccessToken}";
this.FallbackModeUrl = $"https://www.videoindexer.ai/embed/player/{this.azureVideoIndexerServiceConfiguration.AccountId}/{this.VideoId}/?locale=en&location={azureVideoIndexerServiceConfiguration.Location}";
this.UseFallbackMode = true;
StateHasChanged();
}
Expand Down

0 comments on commit 17fedf2

Please sign in to comment.