Ejemplo n.º 1
0
        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");
            }
        }
Ejemplo n.º 2
0
 public VideoConverterService(IFileManagerService fileManagerService,
                              VideoInformationContext context,
                              IMapper mapper,
                              IJobRunnerQueue jobRunner,
                              IFFmpegWraperService ffmpeg)
 {
     _fileManagerService = fileManagerService;
     _dbContext          = context;
     _mapper             = mapper;
     _jobRunner          = jobRunner;
     _ffmpeg             = ffmpeg;
 }
Ejemplo n.º 3
0
        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");
            }
        }
Ejemplo n.º 4
0
        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");
            }
        }