Exemple #1
0
        public async Task <IActionResult> DownloadVideo([FromBody] DownloadRequestDto downloadRequestDto)
        {
            if (!Uri.IsWellFormedUriString(downloadRequestDto.Url, UriKind.RelativeOrAbsolute))
            {
                return(BadRequest("Url must be well formed Uri string"));
            }

            uint quality = downloadRequestDto.MetaDataInfo?.Quality ?? 720;

            if (!IsValidQuality(quality))
            {
                return(BadRequest("Invalid Video Quality setting"));
            }

            var res = await _downloaderService.TryDownloadAsync(downloadRequestDto.Url, downloadRequestDto.ConversionTarget, quality);

            if (res.HasError)
            {
                return(BadRequest(res.Err().Message.Get()));
            }

            var videoInfo = res.Some();

            // Setup metadata
            await _metaDataService.WriteMetadata(videoInfo, downloadRequestDto.MetaDataInfo, downloadRequestDto.ConversionTarget);

            return(CreatedAtRoute("GetFile",
                                  new { controller = "File", fileNameAndExtension = videoInfo.FileName }, videoInfo));
        }