public async Task <VideoFileModel> UploadFile(FileUploadDTO fileUpload) { try { var uniqueDirectory = Guid.NewGuid().ToString(); _fileManagerService.CreateVideoDirectory(uniqueDirectory); var fileLocation = Path.Combine(uniqueDirectory, fileUpload.UploadedFile.FileName); var filePath = await _fileManagerService.SaveTempFile(fileUpload.UploadedFile, fileLocation); var mediaInfo = await _ffmpeg.GetMediaInfo(filePath); var videoFile = _mapper.Map <VideoFile>(mediaInfo); videoFile.Filename = fileUpload.UploadedFile.FileName; videoFile.FileDirectory = uniqueDirectory; await _dbContext.Videos.AddAsync(videoFile); await _dbContext.SaveChangesAsync(); return(_mapper.Map <VideoFileModel>(videoFile)); } catch (Exception ex) { Debug.WriteLine(ex.Message); throw new Exception("Internal server error"); } }
public async Task <VideoFile> SaveVideoFile(string fileName, int parentId = default, Status status = default) { try { using (var dbContext = new VideoInformationContext()) { var mediaInfo = await _ffmpeg.GetMediaInfo(fileName); var videoFile = _mapper.Map <VideoFile>(mediaInfo); videoFile.ParentVideoFileId = parentId; videoFile.Filename = Path.GetFileName(fileName); videoFile.FileDirectory = _fileManagerService.GetParentDirectory(fileName); videoFile.Status = status; await dbContext.Videos.AddAsync(videoFile); await dbContext.SaveChangesAsync(); return(videoFile); } } catch (Exception ex) { Debug.WriteLine(ex.Message); throw new Exception("Internal server error"); } }
private async Task UpdateVideoStatus(int id, Status status) { try { using (var dbContext = new VideoInformationContext()) { var video = await dbContext.Videos.FirstOrDefaultAsync(v => v.Id == id); video.Status = status; await dbContext.SaveChangesAsync(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); throw new Exception("Internal server error"); } }
public async Task <List <HLSFile> > SaveHLSBatch(string path, OutputFormat format, int parentVideoId) { try { using (var dbContext = new VideoInformationContext()) { var savedFiles = Directory .EnumerateFiles(path) .Where(file => file.Contains(format.ToString()) && (file.ToLower().EndsWith("ts") || file.ToLower().EndsWith("m3u8"))) .ToList(); foreach (var file in savedFiles) { var extension = file.Substring(file.LastIndexOf('.')); var hls = new HLSFile { Filename = Path.GetFileName(file), FileDirectory = Directory.GetParent(file).Name, ParentVideoFileId = parentVideoId, HLSType = extension.Equals("m3u8") ? HLSType.Playlist : HLSType.PartialVideo }; await dbContext.HLS.AddAsync(hls); } await dbContext.SaveChangesAsync(); return(new List <HLSFile>()); } } catch (Exception ex) { Debug.WriteLine(ex.Message); throw new Exception("Internal server error"); } }