public async Task <IActionResult> GetVideo(string id, string quality) { string videoPath = DownloaderConfiguration.videoDownloadPath + $"\\{id}.mp4"; //Check if provided quality as parameter is available in the video var videoMetadata = await clientHelper.GetVideoMetadataAsync(id); if (!((List <string>)videoMetadata.qualities).Contains(quality)) { return(BadRequest("Invalid quality !")); } //Check if user is authorized and has required AccountLevel var isAlowedToDownload = await checker.CanDownloadInCertainQualityAsync(quality, User.Identity.IsAuthenticated, User.Identity.Name); if (!isAlowedToDownload.isAllowed) { return(BadRequest(isAlowedToDownload.errorMessageIfNotAllowed)); } try { await clientHelper.DownloadVideoAsync(id, quality, videoPath); } catch (ArgumentException) { return(BadRequest(new string("Provided ID is incorrect"))); } return(new PhysicalFileResultAndDelete(videoPath, "video/mp4")); }
public async Task DownloadVideo_CanDownloadVideo(string id, string videoPath, string quality = "144p") { string videoPathAndName = videoPath + $"//{id}.mp4"; await target.DownloadVideoAsync(id, quality, videoPathAndName); Assert.True(File.Exists(videoPathAndName)); await CleanDirectory.DeleteFileAsync(videoPath, id + ".mp4"); }