Example #1
0
        public async Task <IActionResult> BuildAudioFile(string subwiki, string title)
        {
            WikiTextParser     wtp        = new WikiTextParser();
            WikipediaParseRoot war        = WikipediaDAL.ParseWikitext(subwiki, title);
            List <string>      paragraphs = await wtp.GetParagraphs($"https://en.{subwiki}.org/?curid={war.parse.pageid}");

            string fileURL = await TextToSpeech.SynthesizeAudioAsync(String.Join(",", paragraphs), title);

            ViewBag.Title   = war.parse.title;
            ViewBag.PageId  = war.parse.pageid;
            ViewBag.FileURL = fileURL;

            Audiofiles af = new Audiofiles();

            af.SectionNumber  = 1;
            af.PageId         = war.parse.pageid;
            af.StorageAddress = fileURL;

            if (ModelState.IsValid)
            {
                _context.Audiofiles.Add(af);
                _context.SaveChanges();
            }

            return(RedirectToAction("Wikiparse", "Home", new { subwiki, title }));
        }
        public async Task <IActionResult> AddFavorite(string Title, string Source, int PageId, string Article)
        {
            // Check if the Favorite already exists
            string            userKey       = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            List <Favorites>  userFavorites = _context.Favorites.Where(x => x.UserId == userKey).ToList();
            List <Favorites>  checkTarget   = userFavorites.Where(x => x.PageId == PageId).ToList();
            List <Audiofiles> matches       = _context.Audiofiles.Where(x => x.PageId == PageId).ToList();

            if (matches.Count == 0)
            {
                string fileURL = await TextToSpeech.SynthesizeAudioAsync(Article, Title);

                Audiofiles af = new Audiofiles();
                af.SectionNumber  = 1;
                af.PageId         = PageId;
                af.StorageAddress = fileURL;

                if (ModelState.IsValid)
                {
                    _context.Audiofiles.Add(af);
                    _context.SaveChanges();
                }
            }

            // If it doesn't already exist, create a new one.
            if (checkTarget.Count == 0)
            {
                Favorites F = new Favorites();

                F.Title  = Title;
                F.Source = Source;
                F.PageId = PageId;
                F.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                F.Tags   = "";

                if (ModelState.IsValid)
                {
                    _context.Favorites.Add(F);
                    _context.SaveChanges();
                }
            }

            return(RedirectToAction("ViewFavorites"));
        }