コード例 #1
0
ファイル: CommandJob.cs プロジェクト: hananoki/MMConv
        /// <summary>
        /// CueSheetを元に分割してエンコードする
        /// </summary>
        /// <param name="j"></param>
        public static void JobCDSplitM4A(CommandJobData j)
        {
            foreach (var f in j.fileInfoList)
            {
                var filepath = f.filepath;
                Helper.SetCurrentDirectory(filepath.GetDirectory());

                var outputDir = MainWindowHelper.ChangeOutputDir(j.outputDir, filepath).changeShortPath();
                var wavdir    = outputDir + "\\" + filepath.GetBaseName() + "_WAV";

                //結合wavをcueで分割する
                MainWindowHelper.SetNotifyText("WAVに分割しています", interval: 0);
                SplitWav(wavdir, filepath);

                //分割WavをCueSheetを元にリネーム
                ApplyWavDirCueSheet(wavdir, filepath);

                var fdirM4A = outputDir + "\\" + filepath.GetBaseName();
                if (!Directory.Exists(fdirM4A))
                {
                    Directory.CreateDirectory(fdirM4A);
                }
                if (File.Exists(filepath.ChangeExtention("jpg")))
                {
                    File.Copy(filepath.ChangeExtention("jpg"), fdirM4A + "\\cover.jpg", true);
                    File.Copy(filepath.ChangeExtention("jpg"), wavdir + "\\cover.jpg", true);
                }

                string[] m4a = Directory.GetFiles(fdirM4A, "*.m4a", SearchOption.TopDirectoryOnly);
                if (m4a.Length == 0)
                {
                    string[] files2 = Directory.GetFiles(wavdir, "*.wav", SearchOption.TopDirectoryOnly);
                    int      num    = 0;
                    Parallel.For(0, files2.Length, MainWindow.m_parallelOptions, i => {
                        num++;
                        MainWindowHelper.SetNotifyText("エンコード処理中... ({0}/{1})".format(num, files2.Length), interval: 0);
                        string output = fdirM4A + "\\" + files2[i].getFileName().ChangeExtention("m4a");
                        StartProcess(
                            "neroAacEnc",
                            "-lc -q 1.00 -if {0} -of {1}".format(files2[i].quote(), output.quote()));
                        StartProcess("mp3gain", "/r /c /p {0}".format(output.quote()));
                    });
                }
            }
            MainWindowHelper.SetNotifyText(@"「CD -> SplitM4A」が完了しました");
        }
コード例 #2
0
ファイル: CommandJob.cs プロジェクト: hananoki/MMConv
        /// <summary>
        /// WAV結合
        /// </summary>
        /// <param name="j"></param>
        public static void JobWavJoin(CommandJobData j)
        {
            //	string args = "";
            var cueSheet = new CueSheet(j.fileInfoList.Count);

            Helper.SetCurrentDirectory(j.fileInfoList[0].filepath.GetDirectory());

            //updateFileList( j.fileInfoList );

            int num = 0;

            RunParallel(j, (i, fileinfo, outputDir) => {
                var filepath = fileinfo.filepath;
                num++;
                MainWindowHelper.SetNotifyText("解析中... ({0}/{1})".format(num, j.fileInfoList.Count), interval: 0);

                using (var p = new System.Diagnostics.Process()) {
                    p.StartInfo.FileName               = @"sox";
                    p.StartInfo.Arguments              = "--i {0}".format(filepath.quote());
                    p.StartInfo.UseShellExecute        = false;
                    p.StartInfo.CreateNoWindow         = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.RedirectStandardError  = true;
                    p.Start();
                    string[] stdout = p.StandardOutput.ReadToEnd().Replace("\r", "").Split('\n');
                    foreach (var line in stdout)
                    {
                        if (Regex.Matches(line, @"Duration").Count == 0)
                        {
                            continue;
                        }
                        var mm = Regex.Matches(line, @"Duration.*([0-9][0-9]):([0-9][0-9])\.([0-9][0-9])");
                        var m  = mm[0];

                        cueSheet.setAudioInfo(i, m.Groups[1].Value, m.Groups[2].Value, m.Groups[3].Value);
                    }
                }
            });

            cueSheet.makeFormat();

            var performerList = new List <string>();

            for (int i = 0; i < cueSheet.m_track.Length; ++i)
            {
                cueSheet[i].title     = j.fileInfoList[i].trackName;
                cueSheet[i].performer = j.fileInfoList[i].artist;
                if (performerList.Contains(j.fileInfoList[i].artist) == false)
                {
                    performerList.Add(j.fileInfoList[i].artist);
                }
            }

            cueSheet.m_performer = "Various Artists";
            if (performerList.Count < 3 && performerList[0] != "")
            {
                cueSheet.m_performer = performerList[0];
            }
            cueSheet.m_title = "no title";
            if (j.fileInfoList[0].album != "")
            {
                cueSheet.m_title = j.fileInfoList[0].album;
            }
            cueSheet.m_genre = j.fileInfoList[0].genre;
            cueSheet.m_date  = j.fileInfoList[0].recordedDate;

            StringBuilder str = new StringBuilder();

            foreach (var f in j.fileInfoList.Select((v, i) => { return(new { v, i }); }))
            {
                if (0 < f.i)
                {
                    str.Append(" ");
                }
                str.Append(f.v.filepath.getFileName().quote());
            }

            var    newOutput  = MainWindowHelper.ChangeOutputDir(j.outputDir, j.fileInfoList[0].filepath);
            string outputName = @"{0}\{1} - {2}.wav".format(newOutput, cueSheet.m_performer, cueSheet.m_title);

            //ファイル名に使用できない文字を取得
            char[] invalidChars = System.IO.Path.GetInvalidFileNameChars();

            var dname = outputName.GetDirectory();
            var fname = outputName.getFileName();

            //fname = fname.Replace( "~", "〜" );
            fname = fname.Replace("?", "?");
            //fname = fname.Replace( " ", "_" );

            if (fname.IndexOfAny(invalidChars) < 0)
            {
                Console.WriteLine("ファイル名に使用できない文字は使われていません。");
            }
            else
            {
                Console.WriteLine("ファイル名に使用できない文字が使われています。");
                MessageBox.Show("不正なファイル名です。\n" + fname);
                return;
            }

            //System.Text.RegularExpressions.Regex r =
            //	new System.Text.RegularExpressions.Regex(
            //		"[\\x00-\\x1f<>:\"/\\\\|?*]" +
            //		"|^(CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9]|CLOCK\\$)(\\.|$)" +
            //		"|[\\. ]",
            //		System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            ////マッチしたら、不正なファイル名
            //if( r.IsMatch( fname ) ) {
            //	Console.WriteLine( "不正なファイル名です。" + fname );
            //	MessageBox.Show( "不正なファイル名です。\n" + fname );
            //	return;
            //}

            outputName = dname + "\\" + fname;

            str.Append(" ");
            str.Append(outputName.quote());

            cueSheet.write(outputName.ChangeExtention("cue"));
            MainWindowHelper.SetNotifyText(@"wavファイルを結合しています... [{0}]".format(outputName));
            StartProcess("sox", str.ToString());

            MainWindowHelper.SetNotifyText(@"「WAV結合」が完了しました [{0}]".format(outputName));
        }