// **************************************************************************** // // ChaptersToCue // Copyright (C) 2018-2021 Grigory Chudov (gchudov@gmail.com) // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // **************************************************************************** using System; using System.IO; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using CUETools.CDImage; using CUETools.CTDB; using CUETools.Codecs; namespace CUETools.ChaptersToCue { class Program { static void Usage() { Console.WriteLine("Usage : CUETools.ChaptersToCue.exe "); Console.WriteLine(); Console.WriteLine("-i, --input File containing chapter times"); Console.WriteLine("-o, --output Output filename; Default: Artist - year - album.cue"); Console.WriteLine("-t, --tracks File containing track filenames"); Console.WriteLine("-m, --meta query CTDB for metadata;"); Console.WriteLine("--celltimes Input is in Celltimes format;"); Console.WriteLine("--image Use image file to calculate duration"); } static void Main(string[] args) { TextWriter stdout = Console.Out; Console.SetOut(Console.Error); Console.WriteLine("CUETools.ChaptersToCue v2.1.7 Copyright (C) 2017-2021 Grigory Chudov"); Console.WriteLine("This is free software under the GNU GPLv3+ license; There is NO WARRANTY, to"); Console.WriteLine("the extent permitted by law. for details."); bool queryMeta = false; bool celltimes = false; int fps_mul = 0; int fps_div = 1; string inputPath = "-"; string outputPath = null; string tracksPath = null; string imagePath = null; for (int arg = 0; arg < args.Length; arg++) { bool ok = true; if ((args[arg] == "-i" || args[arg] == "--input") && ++arg < args.Length) inputPath = args[arg]; else if ((args[arg] == "-o" || args[arg] == "--output") && ++arg < args.Length) outputPath = args[arg]; else if ((args[arg] == "-t" || args[arg] == "--tracks") && ++arg < args.Length) tracksPath = args[arg]; else if (args[arg] == "--image" && ++arg < args.Length) imagePath = args[arg]; else if (args[arg] == "-m" || args[arg] == "--meta") queryMeta = true; else if (args[arg] == "--celltimes" && ++arg < args.Length) { celltimes = true; ok = int.TryParse(args[arg], out fps_mul); if (ok && fps_mul == 30) { fps_mul = 30000; fps_div = 1001; } } else ok = false; if (!ok) { Usage(); return; } } string strtoc = ""; string extension = null; if (tracksPath != null) { //CUEToolsCodecsConfig config = new CUEConfig(); //TagLib.UserDefined.AdditionalFileTypes.Config = config; TimeSpan pos = new TimeSpan(0); using (TextReader sr = tracksPath == "-" ? Console.In : new StreamReader(tracksPath)) { while (sr.Peek() >= 0) { string line = sr.ReadLine(); extension = Path.GetExtension(line); TagLib.File sourceInfo = TagLib.File.Create(new TagLib.File.LocalFileAbstraction(line)); strtoc += string.Format(" {0}", (int)(pos.TotalSeconds * 75)); pos += sourceInfo.Properties.Duration; } } strtoc += string.Format(" {0}", (int)(pos.TotalSeconds * 75)); } else { using (TextReader sr = inputPath == "-" ? Console.In : new StreamReader(inputPath)) { if (celltimes) { strtoc += string.Format(" {0}", 0); while (sr.Peek() >= 0) { string line = sr.ReadLine(); strtoc += string.Format(" {0}", long.Parse(line) * 75 * fps_div / fps_mul); } } else { while (sr.Peek() >= 0) { string line = sr.ReadLine(); Regex r = new Regex(@"^CHAPTER(?\d\d)(?