예제 #1
0
 public void RemovePaddingChapters()
 {
     if (Chapters.FirstOrDefault()?.IsPaddingChapter ?? false)
     {
         Chapters.RemoveAt(0);
     }
     if (Chapters.LastOrDefault()?.IsPaddingChapter ?? false)
     {
         Chapters.RemoveAt(Chapters.Count - 1);
     }
 }
예제 #2
0
        public Chapter GetChapter(long position)
        {
            var foundChapter = Chapters.LastOrDefault(ch => ch.StartTime < position);

            if (foundChapter == null)
            {
                _logger.Error($"Couldn't find chapter for position {position} in book {ShortTitle}. ");
                return(new Chapter {
                    Title = "Chapter", StartTime = 0, Duration = RawLength
                });
            }

            return(foundChapter);
        }
예제 #3
0
        private void ffMpegAsyncHandlerActivation(object sendingProcess, DataReceivedEventArgs outLine)
        {
            onCancel();

            if (outLine.Data is null)
            {
                return;
            }

#if TRACE && EXTRA
            Trace.WriteLine(outLine.Data);
#endif
            Log(4, this, () => ID + outLine.Data.SubstitUser());

            Match match = null;
            if (!Chapters.IsNull() && !_listComplete)
            {
                match = _rgxChapter.Match(outLine.Data);
                if (match.Success)
                {
                    var chapter = new Chapter();
                    Chapters.Add(chapter);
                    chapter.Time.Begin = tryParseSeconds(match);
                    chapter.Time.End   = tryParseSeconds(match, 2);
                    return;
                }
                else
                {
                    match = _rgxAnyStream.Match(outLine.Data);
                    if (match.Success)
                    {
                        _listComplete = true;
                    }
                    else
                    {
                        var chapter = Chapters.LastOrDefault();
                        if (!chapter.IsNull())
                        {
                            match = _rgxChapterMeta.Match(outLine.Data);
                            if (match.Success)
                            {
                                chapter.Name = string.Empty;
                                return;
                            }
                            else
                            {
                                if (chapter.Name == string.Empty)
                                {
                                    match = _rgxChapterTitle.Match(outLine.Data);
                                    if (match.Success)
                                    {
                                        chapter.Name = match.Groups[1].Value;
                                    }
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            match = _rgxErrorHeader.Match(outLine.Data);
            if (match.Success)
            {
                _success = false;
            }
            else
            {
                match = _rgxErrorActivationOption.Match(outLine.Data);
                if (match.Success)
                {
                    _success = false;
                }
                else
                {
                    match = _rgxInvalid.Match(outLine.Data);
                    if (match.Success)
                    {
                        _success = false;
                    }
                    else
                    {
                        match = _rgxNoActivatonOpt.Match(outLine.Data);
                        if (match.Success)
                        {
                            HasNoActivation = true;
                        }
                        else
                        {
                            match = _rgxAudioStream.Match(outLine.Data);
                            if (match.Success)
                            {
                                string format = match.Groups[1].Value;
                                IsMp3Stream = format.ToLowerInvariant() == "mp3";
                            }
                            else
                            {
                                match = _rgxAaFile.Match(outLine.Data);
                                if (match.Success)
                                {
                                    IsAaFile = true;
                                }
                                else
                                {
                                    match = _rgxAaxFile.Match(outLine.Data);
                                    if (match.Success)
                                    {
                                        IsAaxFile = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }