Beispiel #1
0
        private void setContext(Book.BookPart part = null)
        {
            if (part is null && Book.PartsType != Book.EParts.some)
            {
                part = Book?.Parts?.FirstOrDefault();
            }
            if (part is null || !part.AaxFileItem.Converted)
            {
                return;
            }

            AaxFileItem = part.AaxFileItem;
            double duration = 0;

            if (Book.PartsType != Book.EParts.some)
            {
                duration = Book.Parts.SelectMany(p => p.Tracks).Select(t => t.Time.Duration.TotalSeconds).Sum();
            }
            else
            {
                duration = part.Tracks.Select(t => t.Time.Duration.TotalSeconds).Sum();
            }

            Duration = TimeSpan.FromSeconds(duration);
        }
 public PartChapters(Book.BookPart part)
 {
     Part = part;
 }
        public void GetContentMetadata(Book.BookPart part)
        {
            string contentMetadataFile = findContentMetadataFile(part.AaxFileItem.FileName);

            if (contentMetadataFile is null)
            {
                return;
            }

            string json     = File.ReadAllText(contentMetadataFile);
            var    metadata = JsonConvert.DeserializeObject <json.AppContentMetadata> (json);

            // set the chapters
            var chapters     = new List <Chapter> ();
            var metaChapters = metadata.content_metadata.chapter_info.chapters;

            if (metaChapters.Count == 0)
            {
                return;
            }

            // handle chapters with no name. Set '.' as a placeholder
            var whites = metaChapters.Where(c => string.IsNullOrWhiteSpace(c.title)).ToList();

            whites.ForEach(c => c.title = ".");



            // handle chapters of zero length. Min length must be 1 ms.
            var zeros = metaChapters.Where(c => c.length_ms == 0).ToList();

            Log(3, this, () => $"chapters: #zero={zeros.Count}, #white={whites.Count}");
            if (zeros.Count > 0)
            {
                zeros.ForEach(c => c.length_ms = 1);
                for (int i = 1; i < metaChapters.Count; i++)
                {
                    var ch0       = metaChapters[i - 1];
                    var ch        = metaChapters[i];
                    int chOffsNew = ch0.start_offset_ms + ch0.length_ms;
                    if (ch.start_offset_ms >= chOffsNew)
                    {
                        continue;
                    }
                    int chLenNew = ch.length_ms + ch.start_offset_ms - chOffsNew;
                    if (chLenNew <= 0)
                    {
                        chLenNew = 1;
                    }
                    ch.start_offset_ms = chOffsNew;
                    ch.length_ms       = chLenNew;
                }
            }

            foreach (var ch in metaChapters)
            {
                var chapter = new Chapter();
                chapter.Name       = ch.title.Trim();
                chapter.Time.Begin = TimeSpan.FromMilliseconds(ch.start_offset_ms);
                chapter.Time.End   = TimeSpan.FromMilliseconds(ch.start_offset_ms + ch.length_ms);
                Log(3, this, () => chapter.ToString());
                chapters.Add(chapter);
            }
            part.Chapters2 = chapters;

            // set brandintro and brandoutro times
            part.BrandIntro = TimeSpan.FromMilliseconds(metadata.content_metadata.chapter_info.brandIntroDurationMs);
            part.BrandOutro = TimeSpan.FromMilliseconds(metadata.content_metadata.chapter_info.brandOutroDurationMs);
            part.Duration   = TimeSpan.FromMilliseconds(metadata.content_metadata.chapter_info.runtime_length_ms);

            Log(3, this, () => $"intro={part.BrandIntro.ToStringHMSm ()}, outro={part.BrandOutro.ToStringHMSm ()}, duration={part.Duration.ToStringHMSm ()}");
        }
            public readonly int nnPrt = -1;   // part digits

            public Numbers(Book book, Track track, Book.BookPart part)
            {
                this.nPrt  = part.PartNumber;
                this.nnPrt = book.Parts.Select(p => p.PartNumber).Max().Digits();

                var chapterTracks = part.Tracks?.Where(t => !(track.Chapter is null) && object.ReferenceEquals(t.Chapter, track.Chapter)).ToList();

                this.nChTrk  = (chapterTracks?.IndexOf(track) ?? -1) + 1;
                this.nnChTrk = chapterTracks?.Count.Digits() ?? 0;

                if (book.PartsType == Book.EParts.some)
                {
                    this.nTrk  = (part.Tracks?.IndexOf(track) ?? -1) + 1;
                    this.nTrks = part.Tracks?.Count ?? 0;

                    this.nDsk  = part.PartNumber;
                    this.nDsks = 0;

                    this.nChp  = (part.Chapters?.IndexOf(track.Chapter) ?? -1) + 1;
                    this.nnChp = part.Chapters?.Count.Digits() ?? 0;
                }
                else
                {
                    this.nTrk = book.Parts.Select(pt =>
                    {
                        if (pt != part)
                        {
                            if (pt.PartNumber < part.PartNumber)
                            {
                                return(pt.Tracks?.Count ?? 0);
                            }
                            else
                            {
                                return(0);
                            }
                        }
                        else
                        {
                            return((part.Tracks?.IndexOf(track) ?? -1) + 1);
                        }
                    }).Sum();

                    this.nTrks = book.Parts.Select(p => p.Tracks?.Count() ?? 0).Sum();

                    this.nDsks = book.Parts.Count;


                    this.nChp = book.Parts.Select(pt =>
                    {
                        if (pt != part)
                        {
                            if (pt.PartNumber < part.PartNumber)
                            {
                                return(pt.Chapters?.Count ?? 0);
                            }
                            else
                            {
                                return(0);
                            }
                        }
                        else
                        {
                            if (track.Chapter is null)
                            {
                                return(0);
                            }
                            else
                            {
                                return((pt.Chapters?.IndexOf(track.Chapter) ?? -1) + 1);
                            }
                        }
                    }).Sum();

                    this.nnChp = book.Parts.Select(p => p.Chapters?.Count ?? 0).Sum().Digits();
                    this.nDsk  = book.PartsType == Book.EParts.none ? 1 : part.PartNumber;
                }

                this.nnTrk = this.nTrks.Digits();
            }