private void PlayAudio(Chapter chapter)
 {
     if (chapter.HasAudio)
     {
         if (mp3Player != null)
         {
             mp3Player.Ctlcontrols.stop();
             mp3Player.currentPlaylist.clear();
             mp3Player.URL = null;
         }
         string cacheLocation = Path.Combine(Configuration.Instance.CacheFolderLocation, chapter.HashID + ".mp3");
         File.Copy(chapter.GetAudioFileLocation(), cacheLocation, true);
         mp3Player.URL = new Uri(cacheLocation).ToString();
         mp3Player.Ctlcontrols.play();
     }
 }
Exemple #2
0
 public bool ShouldMakeAudio(Chapter chapter, bool secondaryPass)
 {
     //if (_chapters == null || _chapters.Count == 0)
     //    return false;
     if (_lastReadChapter != null && _lastReadChapter.Index > chapter.Index && !secondaryPass)
     {
         return(false);
     }
     //if (Configuration.Instance.LanguageVoiceDictionary[NovelSource.NovelLanguage] == null || Configuration.Instance.LanguageVoiceDictionary[NovelSource.NovelLanguage].Equals("No Voice Selected"))
     //    return false;
     //Do not make audio for novel not selected
     if (!MakeAudio)
     {
         return(false);
     }
     //Do not make audio for novel that is dropped
     if (State == NovelState.Dropped)
     {
         return(false);
     }
     //Do not make audio for novel already read and setting checked for making tts for chapter already read
     if (chapter.Read && !Configuration.Instance.MakeTTSForChapterAlreadyRead)
     {
         return(false);
     }
     //Do make audio for chapter that has text and chapter that has no audio
     if (chapter.HasText && !chapter.HasAudio)
     {
         return(true);
     }
     //Remake audio if text is editted after an audio file is made
     if (chapter.HasText && chapter.HasAudio)
     {
         if (File.GetLastWriteTime(chapter.GetAudioFileLocation()) < File.GetLastWriteTime(chapter.GetTextFileLocation()))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Exemple #3
0
        public void DeleteChapter(Chapter deleteChapter, bool blackList, bool verifyData = true)
        {
            if (NovelLibrary.libraryData.Chapters.Any(chapter => chapter.ID == deleteChapter.ID))
            {
                if (deleteChapter.HasAudio)
                {
                    File.Delete(deleteChapter.GetAudioFileLocation());
                }
                if (deleteChapter.HasText)
                {
                    File.Delete(deleteChapter.GetTextFileLocation());
                }
                if (deleteChapter.ID == LastReadChapterID)
                {
                    Console.WriteLine(deleteChapter.ID + " " + deleteChapter.Index + " " + deleteChapter.ChapterTitle);
                    if (deleteChapter.Index > 0)
                    {
                        LastReadChapter = GetChapter(deleteChapter.Index - 1);
                    }
                    else if (deleteChapter.Index == 0 && ChapterCount > 1)
                    {
                        LastReadChapter = GetChapter(1);
                    }
                    else
                    {
                        LastReadChapter = null;
                    }
                }
                ChapterUrl[] urls = deleteChapter.ChapterUrls.ToArray <ChapterUrl>();
                if (urls != null)
                {
                    if (blackList)
                    {
                        deleteChapter.Valid = false;
                    }
                    else
                    {
                        NovelLibrary.libraryData.Chapters.DeleteOnSubmit(deleteChapter);
                        NovelLibrary.libraryData.ChapterUrls.DeleteAllOnSubmit(deleteChapter.ChapterUrls);
                    }
                }
                else
                {
                    NovelLibrary.libraryData.Chapters.DeleteOnSubmit(deleteChapter);
                }
                if (chapterList.Contains(deleteChapter))
                {
                    chapterList.Remove(deleteChapter);
                }
                isDirty = true;
                NovelLibrary.libraryData.SubmitChanges();

                //foreach (Chapter c in chapters)
                //    Console.WriteLine(c.ChapterTitle + " " + c.Index +" " + c.ID);
                if (verifyData)
                {
                    Chapter[] chapters = NovelChapters.ToArray <Chapter>();
                }
                NotifyPropertyChanged("ChapterCountStatus");
            }
        }