public AccountController(IConfiguration config, IEncrypt encryptor, UserIdentityDbContext identityDbContext, UserAndVideoDbContext userAndVideoDbContext) { _config = config; _identityDbContext = identityDbContext; _encryptor = encryptor; _userAndVideoDbContext = userAndVideoDbContext; }
public static async Task Initial(IServiceProvider serviceProvider) { UserAndVideoDbContext context = serviceProvider.GetRequiredService <UserAndVideoDbContext>(); if (!context.Users.Any()) { string currentDirectory = Directory.GetCurrentDirectory(); int pictureSerial = 0; for (int i = 0; i < 20; i++) { pictureSerial = i % 4; User user = new User() { AvatarLocation = Path.Combine(currentDirectory, $"{pictureSerial}.jpg"), UserName = $"User{i+1}", Id = i + 1, Email = $"User{i+1}@cnblog.com" }; await context.Users.AddAsync(user); await context.SaveChangesAsync(); } } }
public static async Task Initial(IServiceProvider provider) { FFmpeg.ExecutablesPath = @"D:\office softwares\FFMpeg"; UserAndVideoDbContext context = provider.GetRequiredService <UserAndVideoDbContext>(); string videoDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Video"); User author = context.Users.Include(u => u.Works).FirstOrDefault(u => u.Id == 1); if (!context.Videos.Any()) { for (int i = 1; i <= 6; i++) { string videoPath = Path.Combine(videoDirectory, $"{i}.mp4"); string picPath = Path.Combine(videoDirectory, $"{i}.jpg"); if (File.Exists(picPath)) { File.Delete(picPath); } //获取视频信息 IMediaInfo mediaInfo = await MediaInfo.Get(videoPath); //以 0 秒时的画面作为封面图并保存在本地 Conversion.Snapshot(videoPath, picPath, TimeSpan.FromSeconds(0)).Start().Wait(); Video video = new Video() { Title = $"轻音少女 第{i}集", Author = context.Users.FirstOrDefault(u => u.Id == 0), Category = Category.番剧, VideoLocation = videoPath, Duration = mediaInfo.Duration, PublishDateTime = DateTime.Now, ThumbnailLocation = PictureTrimmer.GetLocalTrimmedPicture(picPath), Tag = "轻音少女", VideoView = 0 }; author.Works.Add(video); await context.Videos.AddAsync(video); await context.SaveChangesAsync(); } } }