コード例 #1
0
ファイル: Program.cs プロジェクト: btastic/YTDL
        private static async Task CreateCueFileFromChapters(Video video, string targetMp3File)
        {
            Console.WriteLine("Try getting chapters ... ");
            var chapters = await video.TryGetChaptersAsync(Client);

            if (chapters.Count() == 0)
            {
                var color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("No chapters found for video.");
                Console.ForegroundColor = color;

                return;
            }

            var filePath = Path.GetDirectoryName(targetMp3File);
            var fileName = Path.GetFileName(targetMp3File);
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(targetMp3File);

            var cueSheet = new CueSheet
            {
                Performer = "Various Artists",
                Title     = video.Title,
                File      = fileName,
                FileType  = "MP3",
            };

            int trackIndex = 0;

            foreach (var chapter in chapters)
            {
                var artist = chapter.Title;
                var title  = chapter.Title;

                MatchCollection regexResult = Regex.Matches(chapter.Title, "^(.+)(?=-)|(?!<-)([^-]+)$");

                if (regexResult.Count > 1)
                {
                    if (regexResult[0].Success && regexResult[1].Success)
                    {
                        artist = regexResult[0].Groups[0].Value.Trim();
                        title  = regexResult[1].Groups[0].Value.Trim();
                    }
                }

                var duration = TimeSpan.FromMilliseconds(chapter.TimeRangeStart);

                if (cueSheet.Tracks.Count == 0)
                {
                    cueSheet.AddTrack(title, artist);
                    cueSheet.AddIndex(trackIndex++, 1, 0, 0, 0);
                    continue;
                }

                cueSheet.AddTrack(title, artist);
                cueSheet.AddIndex(trackIndex++, 1, (int)Math.Round(duration.TotalMinutes, MidpointRounding.ToEven), duration.Seconds, 0);
            }

            cueSheet.SaveCue(Path.Combine(filePath, fileNameWithoutExtension + ".cue"));
        }
コード例 #2
0
ファイル: CUEManager.cs プロジェクト: kotn3l/AudioBookCutter
        public void saveMarkersMS(List <TimeSpan> markers, string save, Audio audio)
        {
            CueSheet        cue     = new CueSheet();
            List <TimeSpan> ordered = new List <TimeSpan>(markers.OrderBy(time => time.TotalMilliseconds));

            cue.Title    = Path.GetFileNameWithoutExtension(audio.aPath);
            cue.Comments = new string[1] {
                "MS"
            };
            cue.AddTrack("1. fejezet", "na", DataType.AUDIO);
            cue.AddIndex(0, 1, 0, 0, 0);
            int j = 1;

            for (int i = 0; i < ordered.Count; i++)
            {
                j++;
                cue.AddTrack(j + ". fejezet", "na");
                cue.AddIndex(i + 1, 1, (int)ordered[i].TotalMinutes, ordered[i].Seconds, ordered[i].Milliseconds);
            }

            cue.SaveCue(save);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: TeamShinkansen/CueSharp
        /// <summary>
        /// Create a new cuesheet from scratch
        /// </summary>
        static void NewCueSheet()
        {
            CueSheet cue = new CueSheet();

            //Album performer
            cue.Performer = "Rotterdam Philharmonic Orchestra";
            //Album title
            cue.Title = "Edo de Waart / Rachmaninoff: The 3 Symphonies, The Rock - Disc 1";

            //Create 1st track, with a filename that future tracks will inherit
            cue.AddTrack("Symphony No. 2 in E minor, Op. 27: I. Largo - Allegro moderato", "", "CDImage.ape", FileType.WAVE);
            cue.AddIndex(0, 0, 0, 0, 0);
            cue.AddIndex(0, 1, 0, 0, 33);

            //Create 2nd track, with optional 'Performance' field used
            cue.AddTrack("II. Allegro molto", "Fake G. Uy: Timpani");
            cue.AddIndex(1, 0, 18, 39, 33);
            cue.AddIndex(1, 2, 22, 14, 10); //add another index we'll delete later
            cue.AddIndex(1, 1, 18, 44, 25);

            //Create 3rd track
            cue.AddTrack("III. Adagio", "");
            cue.AddIndex(2, 0, 27, 56, 33);
            cue.AddIndex(2, 1, 27, 59, 40);

            //Create 4th track using a method that gives us more control over the data
            Track tempTrack = new Track(4, DataType.AUDIO);

            tempTrack.Title = "IV. Allegro vivace";
            tempTrack.ISRC  = "0000078652395";
            tempTrack.AddFlag(Flags.CH4);
            tempTrack.AddIndex(0, 41, 57, 33);
            tempTrack.AddIndex(1, 42, 00, 60);
            cue.AddTrack(tempTrack);

            //Create 5th track we'll delete later
            cue.AddTrack("Symphony No. Infinity", "Rachmaninoff's Dog");


            //Remove the bad index from the 2nd track
            cue.RemoveIndex(1, 1);//(trackIndex, indexIndex)
            //Notice the index (array-wise) of the Index (cuesheet min/sec/frame) is '1'
            //but the Index Number is 2. This is to show that index and the Index Number are
            //not the same thing and may or may not be equal.

            //Remove the 5th track
            cue.RemoveTrack(4);

            Console.WriteLine(cue.ToString());
            cue.SaveCue("newCDImage.cue");
        }