/// <summary> /// 获取一个视频文件的文件信息 /// </summary> /// <param name="path">文件路径</param> /// <returns>VideoFileInfo类型,没有豆瓣ID</returns> public VideoFileInfo.Storage.VideoFileInfo GetVideoFileInfo(string path) { var video = new VideoFileInfo.Storage.VideoFileInfo(); VideoEncoder.Encoder enc = new VideoEncoder.Encoder(); enc.FFmpegPath = "ffmpeg.exe"; VideoEncoder.VideoFile videoFile = new VideoEncoder.VideoFile(path); enc.GetVideoInfo(videoFile); System.TimeSpan totatp = videoFile.Duration; string totalTime = string.Format("{0:00}:{1:00}:{2:00}", (int)totatp.Hours, (int)totatp.Minutes, (int)totatp.Seconds); video.audioBitRate = (float)videoFile.AudioBitRate; video.audioFormat = videoFile.AudioFormat; video.bitRate = (float)videoFile.BitRate; video.duration = totalTime; video.extension = System.IO.Path.GetExtension(path).Substring(1); video.frameRate = (float)videoFile.FrameRate; video.height = videoFile.Height; video.path = path; video.totalFrames = videoFile.TotalFrames; video.userRating = -1; video.videoBitRate = (float)videoFile.VideoBitRate; video.videoFormat = videoFile.VideoFormat; video.width = videoFile.Width; return(video); }
public static VideoFile GetVideoInfo(string iFile) { VideoEncoder.Encoder encoder = new VideoEncoder.Encoder { FFmpegPath = ffmpeg }; VideoFile videoFile = new VideoFile(iFile); encoder.GetVideoInfo(videoFile); TimeSpan duration = videoFile.Duration; StringBuilder stringBuilder = new StringBuilder(); string arg = $"{(int)duration.TotalHours:00}:{duration.Minutes:00}:{duration.Seconds:00}"; stringBuilder.AppendFormat("时间长度:{0}\n", arg); stringBuilder.AppendFormat("高度:{0}\n", videoFile.Height); stringBuilder.AppendFormat("宽度:{0}\n", videoFile.Width); stringBuilder.AppendFormat("数据格式:{0}\n", videoFile.VideoFormat); stringBuilder.AppendFormat("比特率:{0}\n", videoFile.BitRate); stringBuilder.AppendFormat("文件路径:{0}\n", videoFile.File); return(videoFile); }
private List <v_Movie> GetListInternal(string actressName, int?isLiked) { //播放量字典 Dictionary <string, DataValue> dict = this.GetViewCountDict(); string movieServer = _configuration.GetValue <string>("movieServer"); List <v_Movie> LsMovies = new List <v_Movie>(); var dirs = new DirectoryInfo(movieRootPath).GetDirectories(); var actressDirs = string.IsNullOrEmpty(actressName) ? dirs : dirs.Where(y => y.Name.Contains(actressName)); foreach (var actressItem in actressDirs) //每女优 { v_Actress actress = new v_Actress(); actress.FullName = actressItem.Name; var actressFiles = actressItem.GetFiles();// 获取女优图片 foreach (var photoItem in actressFiles) { string picRelativePath = photoItem.FullName.Replace(movieRootPath, ""); string path = movieServer + picRelativePath?.Replace("\\", "/"); actress.Portraits.Add(path); if (string.IsNullOrEmpty(actress.Cover)) { actress.Cover = path; } } var fanHaoDirs = actressItem.GetDirectories(); //所有番号 文件夹 foreach (var fanHaoItem in fanHaoDirs) { TimeSpan _totalTime = new TimeSpan(); var fanHaoFiles = fanHaoItem.GetFiles(); string FanHaoRaw = fanHaoItem.Name; string FanHao = fanHaoItem.Name.TrimEnd("-C".ToCharArray()); v_Movie movie = new v_Movie(); foreach (var item in fanHaoFiles) { var ext = item.Extension; if (ext == ".mp4" || ext == ".webm") //视频 { var Source = movieServer + item.FullName.Replace(movieRootPath, "")?.Replace("\\", "/"); movie.Sources.Add(Source); VideoEncoder.VideoFile videoFile = null; if (!dict.Keys.Any(x => x == FanHao)) { int row = SQLiteHelper.ExecuteNonQuery($"INSERT INTO Dict ( DataKey,DataValue) VALUES ('{FanHao}','0');"); dict.Add(FanHao, new DataValue() { LastAccessTime = DateTime.Now }); } bool isffmpeg = dict[FanHao].TotalTime == "0"; if (isffmpeg) { VideoEncoder.Encoder enc = new VideoEncoder.Encoder(); //ffmpeg.exe的路径,程序会在执行目录(....FFmpeg测试\bin\Debug)下找此文件, enc.FFmpegPath = "ffmpeg.exe"; //视频路径 videoFile = new VideoEncoder.VideoFile(item.FullName); enc.GetVideoInfo(videoFile); _totalTime = _totalTime.Add(videoFile.Duration); //总时长 int row = SQLiteHelper.ExecuteNonQuery($"UPDATE Dict SET TotalTime='{string.Format("{0:00}:{1:00}:{2:00}", (int)_totalTime.TotalHours, _totalTime.Minutes, _totalTime.Seconds)}' WHERE DataKey = '{FanHao}'; "); } else { if (dict.Any(x => x.Key == FanHao)) { TimeSpan.TryParse(dict[FanHao].TotalTime, out TimeSpan t); _totalTime = t; } else { _totalTime = new TimeSpan(); } } if (!LsMovies.Contains(movie)) { movie.Id = LsMovies.Count + 1; movie.FanHao = FanHao; movie.Date = item.CreationTime.ToString("yyyy-MM-dd HH:mm"); movie.CreationTime = item.CreationTime; movie.PostedDate = this.FormatPostedDate(item.CreationTime); movie.LastAccessTime = dict.Any(x => x.Key == FanHao) ? dict[FanHao].LastAccessTime :DateTime.Now; movie.LastAccess = movie.LastAccessTime.ToString("yyyy-MM-dd HH:mm:ss"); movie.ViewCount = dict.Any(x => x.Key == FanHao) ? dict[FanHao].count : 0; movie.IsLiked = dict.Any(x => x.Key == FanHao) ? dict[FanHao].isLiked : 0; movie.Actress = actress; if (isffmpeg) { //mpeg信息 movie.Height = videoFile.Height; movie.Width = videoFile.Width; movie.DisPlayResolution = videoFile.Width + "x" + videoFile.Height; int row = SQLiteHelper.ExecuteNonQuery($"UPDATE Dict SET Height='{videoFile.Height}',Width='{videoFile.Width}' WHERE DataKey = '{FanHao}'; "); } else { movie.Height = dict[FanHao].Height; movie.Width = dict[FanHao].Width; movie.DisPlayResolution = movie.Width + "x" + movie.Height; } LsMovies.Add(movie); } movie.TotalTime = string.Format("{0:00}:{1:00}:{2:00}", (int)_totalTime.TotalHours, _totalTime.Minutes, _totalTime.Seconds); movie.Duration = _totalTime; // //FileInfo fi = new FileInfo(item.FullName); //xx/xx/aa.rar // var rnj= fanHaoFiles.Where(x =>Path.GetExtension( x.Name) == ".jpg" && x.Name.Contains(FanHao)).FirstOrDefault(); // //fi.MoveTo(Path.GetFileNameWithoutExtension(rnj.FullName) + ".mp4"); //xx/xx/xx.rar // if(rnj != null) // { // if(item.FullName.EndsWith("-A.mp4") || item.FullName.EndsWith("-B.mp4")) // { // Console.WriteLine( "$AB集$ " + item.FullName ); // } // else // { // if(FanHaoRaw.EndsWith("-C")) // { // Computer MyComputer = new Computer(); // string newName = FanHaoRaw + Path.GetFileNameWithoutExtension(rnj.FullName).Replace(FanHaoRaw, "").Replace(FanHao, "") + ".mp4"; // MyComputer.FileSystem.RenameFile(item.FullName, newName); // string newJpgName = newName.Replace(".mp4", "") + ".jpg"; // MyComputer.FileSystem.RenameFile(rnj.FullName, newJpgName); // Console.WriteLine( "#中文# " + item.FullName + " => " + newName); // Console.WriteLine( "#中文图片# " + rnj.FullName + " => " + newJpgName); // } // else // { // Computer MyComputer = new Computer(); // string newName = Path.GetFileNameWithoutExtension(rnj.FullName) + ".mp4"; // MyComputer.FileSystem.RenameFile(item.FullName, newName); // Console.WriteLine( item.FullName + " => " + newName); // } // } // } // else // { // Console.WriteLine("[失败]" + item.FullName); // } } if (ext == ".jpg" || ext == ".png") //图片 { string picRelativePath = item.FullName.Replace(movieRootPath, "")?.Replace("\\", "/"); if (item.Name.Contains(FanHao)) { movie.Title = Path.GetFileNameWithoutExtension(item.Name); movie.Cover = movieServer + picRelativePath; } else { movie.Preview.Add(movieServer + picRelativePath); } } } } } //默认值 foreach (var item in LsMovies) { if (item.Cover == null) { continue; } if (!item.Cover.Contains(".jpg")) //视频不包含图片添加默认图片 { item.Cover = "../images/default.jpg"; } } //是否喜欢条件 LsMovies = isLiked == null ? LsMovies : LsMovies.Where(x => x.IsLiked == isLiked.GetValueOrDefault()).ToList(); _memoryCache.Set("movieTempList", LsMovies, new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromMinutes(30))); return(LsMovies); }