Beispiel #1
0
        private void BtnMoveTop_Click(object sender, RoutedEventArgs e)
        {
            TaskDetail item = TaskList.SelectedItem as TaskDetail;

            if (item == null)
            {
                MessageBox.Show("请点击一个任务开始操作", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            switch (tm.MoveTaskTop(item))
            {
            case TaskManager.MoveTaskTopResult.OK:
                break;

            case TaskManager.MoveTaskTopResult.Already:
                MessageBox.Show("任务早已在队列顶部!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Information);
                break;

            case TaskManager.MoveTaskTopResult.Failure:
                MessageBox.Show("无法置顶任务!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
                break;

            default:
                return;
            }
        }
Beispiel #2
0
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            TaskDetail item = TaskList.SelectedItem as TaskDetail;

            if (item == null)
            {
                MessageBox.Show("请点击一个任务开始操作", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (!tm.DeleteTask(item))
            {
                MessageBox.Show("无法删除任务!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            int activeTaskCount = tm.GetActiveTaskCount();

            BtnRun.IsEnabled      = activeTaskCount > 0;
            BtnDelete.IsEnabled   = activeTaskCount > 0;
            BtnEmpty.IsEnabled    = activeTaskCount > 0;
            BtnMoveDown.IsEnabled = activeTaskCount > 1;
            BtnMoveUp.IsEnabled   = activeTaskCount > 1;
            BtnMoveTop.IsEnabled  = activeTaskCount > 2;
            BtnChap.IsEnabled     = activeTaskCount > 0;
        }
Beispiel #3
0
        private static bool HasMatroskaChapter(TaskDetail task)
        {
            FileInfo inputFile = new FileInfo(task.InputFile);

            if (inputFile.Extension != ".mkv")
            {
                Logger.Warn($"{task.InputFile}不是Matroska文件。");
                return(false);
            }

            MediaInfo.MediaInfo MI = new MediaInfo.MediaInfo();
            MI.Open(inputFile.FullName);
            MI.Option("Complete");
            int.TryParse(MI.Get(StreamKind.General, 0, "MenuCount"), out var MenuCount);

            if (MenuCount == 0)
            {
                Logger.Warn($"{task.InputFile}内不含有章节。");
                MI?.Close();
                return(false);
            }

            MI?.Close();
            return(true);
        }
Beispiel #4
0
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            object o = listView1.SelectedItem;

            if (o == null)
            {
                return;
            }

            TaskDetail item = o as TaskDetail;

            if (item.IsRunning)
            {
                MessageBox.Show("无法删除该任务!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!tm.DeleteTask(item))
            {
                MessageBox.Show("任务删除失败!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            BtnRun.IsEnabled = tm.HasNextTask();
            return;
        }
Beispiel #5
0
        private static bool HasBlurayStructure(TaskDetail task)
        {
            FileInfo inputFile = new FileInfo(task.InputFile);

            if (inputFile.Extension != ".m2ts")
            {
                Logger.Warn($"{task.InputFile}不是蓝光原盘文件。");
                return(false);
            }

            if (inputFile.Directory.Name != "STREAM")
            {
                Logger.Warn($"{task.InputFile}不在BDMV文件夹结构内。");
                return(false);
            }

            DirectoryInfo playlist = new DirectoryInfo(Path.Combine(inputFile.Directory.Parent.FullName, "PLAYLIST"));

            if (!playlist.Exists)
            {
                Logger.Warn($"{task.InputFile}没有上级的PLAYLIST文件夹");
                return(false);
            }

            return(playlist.GetFiles("*.mpls").Length > 0);
        }
Beispiel #6
0
 public bool MoveTaskDown(TaskDetail td)
 {
     lock (o)
     {
         int idx1 = taskStatus.IndexOf(td);
         int idx2 = idx1 + 1;
         return(SwapTasksByIndex(idx1, idx2));
     }
 }
Beispiel #7
0
        public static ChapterInfo LoadChapter(TaskDetail task)
        {
            FileInfo    inputFile = new FileInfo(task.InputFile);
            ChapterInfo chapterInfo;

            switch (task.ChapterStatus)
            {
            case ChapterStatus.Yes:
                FileInfo txtChapter = new FileInfo(Path.ChangeExtension(inputFile.FullName, ".txt"));
                if (!txtChapter.Exists)
                {
                    return(null);
                }
                chapterInfo = new OGMParser().Parse(txtChapter.FullName).FirstOrDefault();
                break;

            case ChapterStatus.Maybe:
                DirectoryInfo playlistDirectory =
                    new DirectoryInfo(Path.Combine(inputFile.Directory.Parent.FullName, "PLAYLIST"));
                chapterInfo = GetChapterFromMPLS(playlistDirectory.GetFiles("*.mpls"), inputFile);
                break;

            case ChapterStatus.MKV:
                FileInfo mkvExtract = new FileInfo(".\\tools\\mkvtoolnix\\mkvextract.exe");
                chapterInfo = new MATROSKAParser(mkvExtract.FullName).Parse(inputFile.FullName).FirstOrDefault();
                break;

            default:
                return(null);
            }

            if (chapterInfo == null)
            {
                return(null);
            }

            chapterInfo.Chapters.Sort((a, b) => a.Time.CompareTo(b.Time));
            chapterInfo.Chapters = chapterInfo.Chapters
                                   .Where(x => task.LengthInMiliSec - x.Time.TotalMilliseconds > 1001).ToList();
            if (chapterInfo.Chapters.Count > 1 ||
                chapterInfo.Chapters.Count == 1 && chapterInfo.Chapters[0].Time.Ticks > 0)
            {
                double lastChapterInMiliSec = chapterInfo.Chapters[chapterInfo.Chapters.Count - 1].Time.TotalMilliseconds;
                if (task.LengthInMiliSec - lastChapterInMiliSec < 3003)
                {
                    task.ChapterStatus = ChapterStatus.Warn;
                }
                return(chapterInfo);
            }

            Logger.Info(inputFile.Name + "对应章节为空,跳过封装。");
            return(null);
        }
Beispiel #8
0
 public bool DeleteTask(TaskDetail detail)
 {
     lock (o)
     {
         if (detail.Progress == TaskStatus.TaskProgress.RUNNING)
         {
             return(false);
         }
         else
         {
             return(taskStatus.Remove(detail));
         }
     }
 }
Beispiel #9
0
        private void BtnMoveDown_Click(object sender, RoutedEventArgs e)
        {
            TaskDetail item = TaskList.SelectedItem as TaskDetail;

            if (item == null)
            {
                MessageBox.Show("请点击一个任务开始操作", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (!tm.MoveTaskDown(item))
            {
                MessageBox.Show("无法下移任务!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #10
0
        public static bool GetChapterFromMPLS(TaskDetail task)
        {
            if (!task.InputFile.EndsWith(".m2ts"))
            {
                Logger.Warn($"{ task.InputFile }不是蓝光原盘文件。");
                return(false);
            }

            FileInfo inputFile = new FileInfo(task.InputFile);
            string   folder    = inputFile.DirectoryName;

            if (!folder.EndsWith(@"\BDMV\STREAM"))
            {
                Logger.Warn($"{ task.InputFile }不在BDMV文件夹结构内。");
                return(false);
            }
            folder  = folder.Remove(folder.Length - 6);
            folder += "PLAYLIST";
            DirectoryInfo playlist = new DirectoryInfo(folder);

            if (!playlist.Exists)
            {
                Logger.Warn($"{ task.InputFile }没有上级的PLAYLIST文件夹");
                return(false);
            }

            FileInfo[] allPlaylists = playlist.GetFiles();
            MPLSParser parser       = new MPLSParser();

            foreach (FileInfo mplsFile in allPlaylists)
            {
                IChapterData allChapters = parser.Parse(mplsFile.FullName);
                for (int i = 0; i < allChapters.Count; i++)
                {
                    ChapterInfo chapter = allChapters[i];
                    if (chapter.SourceName + ".m2ts" == inputFile.Name)
                    {
                        //save chapter file
                        string chapterFileName = Path.ChangeExtension(task.InputFile, ".txt");
                        allChapters.Save(ChapterTypeEnum.OGM, chapterFileName, i);
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #11
0
        public static string UpdateChapterStatus(TaskDetail task)
        {
            bool hasChapter = HasChapterFile(task);

            if (hasChapter)
            {
                return(ChapterStatus.Yes.ToString());
            }

            hasChapter = GetChapterFromMPLS(task);
            if (hasChapter)
            {
                return(ChapterStatus.Added.ToString());
            }
            else
            {
                return(ChapterStatus.No.ToString());
            }
        }
Beispiel #12
0
        private void ListView_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            TaskDetail item = TaskList.SelectedItem as TaskDetail;

            if (item == null)
            {
                MessageBox.Show("你需要选择一个任务来打开文件。", "文件夹打开失败", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                string path = Path.GetDirectoryName(item.InputFile);
                string arg  = path;

                if (item.CurrentStatus == "完成")
                {
                    arg = @"/select," + Path.Combine(path, item.OutputFile);
                }
                Process.Start("Explorer.exe", arg);
            }
        }
Beispiel #13
0
        public static OKEFile AddChapter(TaskDetail task)
        {
            FileInfo txtChapter = new FileInfo(Path.ChangeExtension(task.InputFile, ".txt"));

            if (txtChapter.Exists)
            {
                OKEFile        chapterFile = new OKEFile(txtChapter);
                ChapterChecker checker     = new ChapterChecker(chapterFile, task.lengthInMiliSec);
                checker.RemoveUnnecessaryEnd();

                if (checker.IsEmpty())
                {
                    Logger.Info(txtChapter.Name + "为空,跳过封装。");
                    return(null);
                }
                else
                {
                    task.MediaOutFile.AddTrack(new ChapterTrack(chapterFile));
                    return(chapterFile);
                }
            }

            return(null);
        }
Beispiel #14
0
        private readonly object o = new object(); // dummy object used for locking threads.

        public int AddTask(TaskDetail detail)
        {
            TaskDetail td = detail;

            newTaskCount++;
            tidCount++;

            if (td.TaskName == "")
            {
                td.TaskName = "新建任务 - " + newTaskCount.ToString();
            }

            // 初始化任务参数
            td.IsEnabled     = true;
            td.Tid           = tidCount.ToString();
            td.CurrentStatus = "等待中";
            td.ProgressValue = 0.0;
            td.Speed         = "0.0 fps";
            td.TimeRemain    = TimeSpan.FromDays(30);
            td.WorkerName    = "";

            taskStatus.Add(td);
            return(taskStatus.Count);
        }
Beispiel #15
0
 public static ChapterStatus UpdateChapterStatus(TaskDetail task)
 {
     return(HasChapterFile(task) ? ChapterStatus.Yes :
            HasBlurayStructure(task) ? ChapterStatus.Maybe :
            HasMatroskaChapter(task) ? ChapterStatus.MKV : ChapterStatus.No);
 }
Beispiel #16
0
        // 为所有输入文件生成vs脚本,并添加任务至TaskManager。
        private void WizardFinish(object sender, RoutedEventArgs e)
        {
            string[] inputTemplate = Constants.inputRegex.Split(vsScript);

            // 处理MEMORY标签
            if (Constants.memoryRegex.IsMatch(vsScript))
            {
                string[] memoryTag = Constants.memoryRegex.Split(inputTemplate[0]);
                inputTemplate[0] = memoryTag[0] + memoryTag[1] + eachFreeMemory.ToString() + memoryTag[3];
            }

            // 处理DEBUG标签
            if (Constants.debugRegex.IsMatch(vsScript))
            {
                string[] debugTag = Constants.debugRegex.Split(inputTemplate[3]);
                if (debugTag.Length < 4)
                {
                    // error
                    System.Windows.MessageBox.Show("Debug标签语法错误!", "新建任务向导", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                inputTemplate[3] = debugTag[0] + debugTag[1] + "None" + debugTag[3];
            }


            // 新建任务
            // 1、清理残留文件
            // 2、新建脚本文件
            // 3、新建任务参数
            Cleaner cleaner = new Cleaner();

            foreach (string inputFile in wizardInfo.InputFile)
            {
                List <TaskDetail> existing = workerManager.tm.GetTasksByInputFile(inputFile);
                bool skip = existing.Any(i => i.Progress == TaskStatus.TaskProgress.RUNNING || i.Progress == TaskStatus.TaskProgress.WAITING);

                if (skip)
                {
                    System.Windows.MessageBox.Show($"{inputFile}已经在任务列表里,将跳过处理。", $"{inputFile}已经在任务列表里", MessageBoxButton.OK, MessageBoxImage.Error);
                    continue;
                }

                // 清理文件
                cleaner.Clean(inputFile, new List <string> {
                    json.InputScript, inputFile + ".lwi"
                });

                EpisodeConfig config  = null;
                string        cfgPath = inputFile + ".json";
                FileInfo      cfgFile = new FileInfo(cfgPath);
                if (cfgFile.Exists)
                {
                    try
                    {
                        string configStr = File.ReadAllText(cfgPath);
                        config = JsonConvert.DeserializeObject <EpisodeConfig>(configStr);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(ex.ToString(), cfgFile.Name + "文件写错了诶", MessageBoxButton.OK, MessageBoxImage.Error);
                        continue;
                    }
                }

                // 新建vpy文件(inputname.m2ts-mmddHHMM.vpy)
                string vpy = inputTemplate[0] + inputTemplate[1] + "r\"" +
                             inputFile + "\"" + inputTemplate[3];

                DateTime time     = DateTime.Now;
                string   fileName = inputFile + "-" + time.ToString("MMddHHmm") + ".vpy";
                File.WriteAllText(fileName, vpy);

                FileInfo   finfo = new FileInfo(inputFile);
                TaskDetail td    = new TaskDetail
                {
                    TaskName  = string.IsNullOrEmpty(json.ProjectName) ? finfo.Name : json.ProjectName + "-" + finfo.Name,
                    Taskfile  = json.Clone() as TaskProfile,
                    InputFile = inputFile,
                };

                // 更新输入脚本和输出文件拓展名
                td.Taskfile.InputScript = fileName;
                if (config != null)
                {
                    td.Taskfile.Config = config.Clone() as EpisodeConfig;
                }
                td.UpdateOutputFileName();

                // 寻找章节
                td.ChapterStatus = ChapterService.UpdateChapterStatus(td);
                workerManager.AddTask(td);
            }
        }
Beispiel #17
0
 public bool DeleteTask(TaskDetail detail)
 {
     return(DeleteTask(detail.Tid));
 }
Beispiel #18
0
        // 为所有输入文件生成vs脚本,并添加任务至TaskManager。
        private void WizardFinish(object sender, RoutedEventArgs e)
        {
            // 处理PROJECTDIR标签
            if (Constants.projectDirRegex.IsMatch(vsScript))
            {
                string[] dirTag     = Constants.projectDirRegex.Split(vsScript);
                string   projectDir = new DirectoryInfo(wizardInfo.ProjectFile).Parent.FullName;
                vsScript = dirTag[0] + dirTag[1] + "r\"" + projectDir + "\"" + dirTag[3];
            }

            string updatedVsScript = vsScript;

            // 处理MEMORY标签
            if (Constants.memoryRegex.IsMatch(updatedVsScript))
            {
                string[] memoryTag = Constants.memoryRegex.Split(updatedVsScript);
                updatedVsScript = memoryTag[0] + memoryTag[1] + eachFreeMemory.ToString() + memoryTag[3];
            }

            // 处理DEBUG标签
            if (Constants.debugRegex.IsMatch(updatedVsScript))
            {
                string[] debugTag = Constants.debugRegex.Split(updatedVsScript);
                if (debugTag.Length < 4)
                {
                    // error
                    System.Windows.MessageBox.Show("Debug标签语法错误!", "新建任务向导", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                updatedVsScript = debugTag[0] + debugTag[1] + "None" + debugTag[3];
            }

            string[] inputTemplate = Constants.inputRegex.Split(updatedVsScript);

            // 新建任务
            // 1、清理残留文件
            // 2、新建脚本文件
            // 3、新建任务参数
            Cleaner cleaner = new Cleaner();

            foreach (string inputFile in wizardInfo.InputFile)
            {
                List <TaskDetail> existing = workerManager.tm.GetTasksByInputFile(inputFile);
                bool skip = existing.Any(i => i.Progress == TaskStatus.TaskProgress.RUNNING || i.Progress == TaskStatus.TaskProgress.WAITING);

                if (skip)
                {
                    System.Windows.MessageBox.Show($"{inputFile}已经在任务列表里,将跳过处理。", $"{inputFile}已经在任务列表里", MessageBoxButton.OK, MessageBoxImage.Error);
                    continue;
                }

                // 清理文件
                cleaner.Clean(inputFile, new List <string> {
                    json.InputScript, inputFile + ".lwi"
                });

                EpisodeConfig config  = null;
                string        cfgPath = inputFile + ".json";
                FileInfo      cfgFile = new FileInfo(cfgPath);
                if (cfgFile.Exists)
                {
                    try
                    {
                        string configStr = File.ReadAllText(cfgPath);
                        config = JsonConvert.DeserializeObject <EpisodeConfig>(configStr);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(ex.ToString(), cfgFile.Name + "文件写错了诶", MessageBoxButton.OK, MessageBoxImage.Error);
                        continue;
                    }
                }

                // 新建vpy文件(inputname.m2ts-mmddHHMM.vpy)
                string vpy = inputTemplate[0] + inputTemplate[1] + "r\"" +
                             inputFile + "\"" + inputTemplate[3];

                string       inputSuffixPath           = inputFile.Replace(':', '_');
                const string stripCommonPathComponents = "BDBOX/BDROM/BD/BDMV/STREAM/BD_VIDEO"; // FIXME: do not hardcode this.
                string[]     strippedComponents        = stripCommonPathComponents.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var comp in strippedComponents)
                {
                    inputSuffixPath = Regex.Replace(inputSuffixPath, @"[/\\]" + Regex.Escape(comp) + @"[/\\]", "\\");
                }
                Logger.Debug("Transformed input path: " + inputSuffixPath);
                string newPath = new DirectoryInfo(wizardInfo.ProjectFile).Parent.FullName + "/" + inputSuffixPath;
                Directory.CreateDirectory(new DirectoryInfo(newPath).Parent.FullName);
                string outPath = Regex.Replace(newPath, @"[/\\]._[/\\]", "\\output\\");
                Directory.CreateDirectory(new DirectoryInfo(outPath).Parent.FullName);

                DateTime time     = DateTime.Now;
                string   fileName = newPath + "-" + time.ToString("MMddHHmm") + ".vpy";
                File.WriteAllText(fileName, vpy);

                FileInfo   finfo = new FileInfo(inputFile);
                TaskDetail td    = new TaskDetail
                {
                    TaskName  = string.IsNullOrEmpty(json.ProjectName) ? finfo.Name : json.ProjectName + "-" + finfo.Name,
                    Taskfile  = json.Clone() as TaskProfile,
                    InputFile = inputFile,
                };
                td.Taskfile.WorkingPathPrefix = newPath;
                td.Taskfile.OutputPathPrefix  = outPath;

                // 更新输入脚本和输出文件拓展名
                td.Taskfile.InputScript = fileName;
                if (config != null)
                {
                    td.Taskfile.Config = config.Clone() as EpisodeConfig;
                }
                td.UpdateOutputFileName();

                // 寻找章节
                td.ChapterStatus = ChapterService.UpdateChapterStatus(td);
                workerManager.AddTask(td);
            }
        }
Beispiel #19
0
        private static bool HasChapterFile(TaskDetail task)
        {
            FileInfo txtChapter = new FileInfo(Path.ChangeExtension(task.InputFile, ".txt"));

            return(txtChapter.Exists);
        }