private void onDataArrival(Exception ex, MediaInfoEntity mediaInfo) { if (this.InvokeRequired) { this.Invoke(new MediaInfoUtil.OnDataArrival(onDataArrival), ex, mediaInfo); } else { actionOnDataArrival(ex, mediaInfo); } }
private void actionOnDataArrival(Exception ex, MediaInfoEntity mediaInfo) { if (ex != null) { MessageBox.Show(ex.ToString()); return; } //画面尺寸 String videoSize = mediaInfo.VideoWidth + " * " + mediaInfo.VideoHeight; //视频时长 string[] times = mediaInfo.VideoTime.Trim().ToUpper().Split(' '); int hour = 0; int.TryParse(times[0].Replace("H", ""), out hour); int min = 0; int.TryParse(times[1].Replace("MN", ""), out min); string vedioTime = String.Format("{0}:{1}", hour.ToString(), min.ToString().PadLeft(2, '0')); //文件大小 string fileSize = mediaInfo.FileSize.ToUpper().Replace("GIB", "G"); int index = dgvMediaInfos.Rows.Add(); dgvMediaInfos.Rows[index].Cells["SeqNo"].Value = dgvMediaInfos.RowCount; dgvMediaInfos.Rows[index].Cells["category"].Value = txtOutTitle.Text; dgvMediaInfos.Rows[index].Cells["filenameOfChn"].Value = mediaInfo.FileNameOfChn; dgvMediaInfos.Rows[index].Cells["fileSize"].Value = fileSize; dgvMediaInfos.Rows[index].Cells["videoSize"].Value = videoSize; dgvMediaInfos.Rows[index].Cells["videoTime"].Value = vedioTime; dgvMediaInfos.Rows[index].Cells["videoBitrate"].Value = mediaInfo.VideoBitRate; dgvMediaInfos.Rows[index].Cells["subTitle"].Value = mediaInfo.Subtitles; dgvMediaInfos.Rows[index].Cells["fileName"].Value = mediaInfo.FileName; dgvMediaInfos.Rows[index].Cells["fileLength"].Value = mediaInfo.FileLength; dgvMediaInfos.Rows[index].Cells["disk"].Value = cmbDisk.Text.Trim(); dgvMediaInfos.Rows[index].Cells["completeName"].Value = mediaInfo.CompletePath; //if (sw == null && fs == null) //{ // //创建CSV输出文件 // createOutputCsv(mediaInfo.FileRoot); //} //outputDataToCsv(mediaInfo, dgvMediaInfos.RowCount); }
private void getMediaInfo(String dir, String rootName) { DirectoryInfo dirInfo = new DirectoryInfo(dir); //例外目录 bool isExcept = isException(dir); if (isExcept) { return; } String rootName_out = getFileRoot(dir); string[] dirs = Directory.GetDirectories(dir);//得到子目录 IEnumerator iter = dirs.GetEnumerator(); while (iter.MoveNext()) { string str = (string)(iter.Current); rootName = getFileRoot(str); getMediaInfo(str, rootName); } FileInfo[] files = new DirectoryInfo(dir).GetFiles(); if (files.Length > 0) { MediaInfoEntity mediaInfo = null; for (int i = 0; i < files.Length; i++) { //跳过隐藏文件 String attString = files[i].Attributes.ToString(); Boolean isHidden = attString.ToUpper().Contains("HIDDEN"); if (isHidden) { continue; } if (files[i].Name.ToUpper().EndsWith("SRT") || files[i].Name.ToUpper().EndsWith("ASS") || files[i].Name.ToUpper().EndsWith("SSA")) { //字幕文件 } if (files[i].Name.ToUpper().EndsWith("MKV") || files[i].Name.ToUpper().EndsWith("AVI") || files[i].Name.ToUpper().EndsWith("MOV") || files[i].Name.ToUpper().EndsWith("MP4") || files[i].Name.ToUpper().EndsWith("MPG") || files[i].Name.ToUpper().EndsWith("MPEG") || files[i].Name.ToUpper().EndsWith("RM") || files[i].Name.ToUpper().EndsWith("FLV") || files[i].Name.ToUpper().EndsWith("TS") || files[i].Name.ToUpper().EndsWith("VOB") || files[i].Name.ToUpper().EndsWith("DAT") || files[i].Name.ToUpper().EndsWith("RMVB")) { Exception e = null; try { MediaInfo mi = new MediaInfo(); mi.Open(files[i].FullName); mi.Option("Complete"); String s = mi.Inform(); mi.Close(); mediaInfo = generateInfo(s); mediaInfo.FileName = files[i].Name; mediaInfo.FileParent = files[i].Directory.Name; mediaInfo.FileRoot = rootName_out; mediaInfo.FileLength = files[i].Length; if (noFolderFlag) { mediaInfo.FileNameOfChn = getFileNameOfChn(files[i].Name); mediaInfo.Subtitles = getSubTitle(null); } else { if (rootName_out != null && rootName_out.Contains("【") && rootName_out.Contains("】")) { mediaInfo.FileNameOfChn = rootName_out; } else { mediaInfo.FileNameOfChn = getFileNameOfChn(files[i].Directory.Name); } mediaInfo.Subtitles = getSubTitle(files[i]); } } catch (Exception ex) { e = ex; } if (DataArrival != null) { DataArrival(e, mediaInfo); } } } } }
private MediaInfoEntity generateInfo(String s) { MediaInfoEntity mediaInfo = new MediaInfoEntity(); String[] v = s.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < v.Length; i++) { if (mediaInfo.FileSize != null && mediaInfo.VideoTime != null && mediaInfo.VideoHeight != null && mediaInfo.VideoWidth != null && mediaInfo.VideoBitRate != null && mediaInfo.CompletePath != null) { break; } if (v[i].Replace(" ", "").ToUpper().Contains("FileSize".ToUpper())) { String[] tv = v[i].Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries); if (mediaInfo.FileSize == null) { mediaInfo.FileSize = tv[1]; } continue; } if (v[i].Replace(" ", "").ToUpper().Contains("Duration".ToUpper())) { String[] tv = v[i].Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries); if (mediaInfo.VideoTime == null) { mediaInfo.VideoTime = tv[1]; } continue; } if (v[i].Replace(" ", "").ToUpper().Contains("BitRate".ToUpper())) { String[] tv = v[i].Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries); if (mediaInfo.VideoBitRate == null && tv[1].Contains("Kbps")) { mediaInfo.VideoBitRate = tv[1].ToUpper().Replace(" ", "").Replace("KBPS", " Kbps"); } continue; } if (v[i].Replace(" ", "").ToUpper().Contains("Width".ToUpper())) { String[] tv = v[i].Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries); if (mediaInfo.VideoWidth == null) { mediaInfo.VideoWidth = tv[1].ToUpper().Replace(" ", "").Replace("PIXELS", ""); } continue; } if (v[i].Replace(" ", "").ToUpper().Contains("Height".ToUpper())) { String[] tv = v[i].Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries); if (mediaInfo.VideoHeight == null) { mediaInfo.VideoHeight = tv[1].ToUpper().Replace(" ", "").Replace("PIXELS", ""); } continue; } if (v[i].Replace(" ", "").ToUpper().Contains("Completename".ToUpper())) { String[] tv = v[i].Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries); string[] paths = tv[2].Split('\\'); Array.Resize(ref paths, paths.Length - 1); string path = string.Join("\\", paths); if (mediaInfo.CompletePath == null) { mediaInfo.CompletePath = path; } continue; } } return(mediaInfo); }