Example #1
0
        public HttpResponseMessage GetParseData()
        {
            string textData = Request.Content.ReadAsStringAsync().Result;

            string[]             parseData;
            List <SplitterModel> parseDataList = new List <SplitterModel>();
            SplitterModel        SM;
            HttpResponseMessage  res;

            try
            {
                SubtitleSplitter.SubtitleParser sp = new SubtitleParser();
                parseData = sp.Parse(textData);
                foreach (string s in parseData)
                {
                    SM             = new SplitterModel();
                    SM.titleString = s;
                    parseDataList.Add(SM);
                }

                res = Request.CreateResponse(HttpStatusCode.OK);
                var json = JsonConvert.SerializeObject(parseDataList);
                res.Content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
            }
            catch (Exception e)
            {
                res = Request.CreateResponse(HttpStatusCode.InternalServerError);
            }

            return(res);
        }
Example #2
0
        public void SubtitleParserTests()
        {
            var directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            // This file contains a segment with invalid timestamp format
            try
            {
                string path        = string.Format("{0}\\{1}", directory, "Content\\timestamperror.srt");
                var    translation = SubtitleParser.Parse(path, "srt");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(SubtitleParseException));
            }

            // This file contains 3 segments, the last one has id 9999 and should therefore be cut off
            string path2        = string.Format("{0}\\{1}", directory, "Content\\cutsOff.srt");
            var    translation2 = SubtitleParser.Parse(path2, "srt");

            Assert.IsTrue(translation2.TranslationSegments.Count == 2);


            // This file contains a segment with invalid id
            try
            {
                string path        = string.Format("{0}\\{1}", directory, "Content\\idError.srt");
                var    translation = SubtitleParser.Parse(path, "srt");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(SubtitleParseException));
            }
        }
Example #3
0
        public void ParseStringWithLessThan25Chars()
        {
            string          SAMPLE_TEXT    = "Please write a program";
            ISubtitleParser subTitleParser = new SubtitleParser();
            var             expectResult   = subTitleParser.Parse(SAMPLE_TEXT);

            Assert.That(expectResult.Count.Equals(1));
        }
Example #4
0
        public void RemoveRedundentWhiteSpaces()
        {
            string          SAMPLE_TEXT    = "Please   write  a program";
            ISubtitleParser subTitleParser = new SubtitleParser();
            var             expectResult   = subTitleParser.Parse(SAMPLE_TEXT);

            Assert.AreNotEqual(expectResult, SAMPLE_TEXT);
        }
Example #5
0
        public void BreakSentenceWithIn5Chars()
        {
            string          SAMPLE_TEXT    = "Please write a progr,am 12";
            ISubtitleParser subTitleParser = new SubtitleParser();
            var             expectResult   = subTitleParser.Parse(SAMPLE_TEXT);

            Assert.That(expectResult[1].Length.Equals(5));
        }
        public void Parse()
        {
            string srtContent = File.ReadAllText("./test.srt");
            string lrcContent = File.ReadAllText("./test.lrc");
            var    srt        = SubtitleParser.Parse(srtContent);
            var    lrc        = SubtitleParser.Parse(lrcContent);

            Assert.True(srt != null && lrc != null);
        }
Example #7
0
        public void ParseTest_Blank_Text()
        {
            string SAMPLE_TEXT = "";

            var controller = new SubtitleParser();


            string[] Result = controller.Parse(SAMPLE_TEXT);

            Assert.AreEqual(Result[0].ToString(), "Please insert Some Values for parsing.");
        }
Example #8
0
        public void ParseTest_Comma_RemainlessFiveChar_Text()
        {
            string SAMPLE_TEXT = "Hi,there";

            var controller = new SubtitleParser();


            string[] Result = controller.Parse(SAMPLE_TEXT);
            Assert.IsNotNull(Result);
            Assert.AreEqual(Result.Length, 1);
        }
Example #9
0
        private async void OpenLyricsFile_Button_OnClick(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();

            picker.FileTypeFilter.Add(".lrc");
            picker.FileTypeFilter.Add(".srt");
            var file = await picker.PickSingleFileAsync();

            if (file is null)
            {
                return;
            }

            string content = await FileIO.ReadTextAsync(file);

            var subtitleBlock = SubtitleParser.Parse(content);

            Main_ScrollSubtitlePreview.Source = subtitleBlock.Lines.ToLineUiList();
        }
Example #10
0
        public void ParseTest_Sample_Text()
        {
            string SAMPLE_TEXT =
                "Please write a program that breaks this text into small chucks. Each chunk should have a maximum length of 25 " +
                "characters. The program should try to break on complete sentences or punctuation marks if possible.  " +
                "If a comma or sentence break occurs within 5 characters of the max line length, the line should be broken early.  " +
                "The exception to this rule is when the next line will only contain 5 characters.  Redundant whitespace should " +
                "not be counted between lines, and any duplicate   spaces should be removed.  " +
                "Does this make sense? If not please ask for further clarification, an array containing " +
                "the desired outcome has been provided below. Any text beyond this point is not part of the instructions, " +
                "it's only here to ensure test converge. Finish line. Aaa asdf asdfjk las, asa.";

            var controller = new SubtitleParser();


            string[] Result = controller.Parse(SAMPLE_TEXT);

            Assert.IsNotNull(Result);
            Assert.AreNotEqual(Result[0].ToString(), "Getting some error while parsing.");
        }
Example #11
0
        /* Private members */

        private Subtitles ParsedSubtitles(string path, Encoding fileEncoding, SubtitleFormat format, float inputFrameRate, string text)
        {
            SubtitleCollection collection        = null;
            SubtitleParser     subtitleParser    = new SubtitleParser(includeIncompleteSubtitles);
            ParsingProperties  parsingProperties = subtitleParser.Parse(text, format, inputFrameRate, out collection, out incompleteSubtitles);

            SubtitleProperties subtitleProperties = new SubtitleProperties(parsingProperties);

            collection.SetPropertiesForAll(subtitleProperties);

            Subtitles subtitles = new Subtitles(collection, subtitleProperties);

            CompleteTimingsAfterParsing(subtitles, parsingProperties);

            fileProperties = new FileProperties(path, fileEncoding, format.Type, parsingProperties.TimingMode);

            Logger.Info("[SubtitleFactory] Opened \"{0}\" with encoding \"{1}\", format \"{2}\", timing mode \"{3}\" and frame rate \"{4}\" (input frame rate was \"{5}\")",
                        path, fileEncoding, format.Name, parsingProperties.TimingMode, subtitleProperties.CurrentFrameRate, inputFrameRate);

            return(subtitles);
        }
        //GET: api/Subtitle
        public List <string> GetSubtitle(string input)
        {
            SubtitleParser subtitleParser = new SubtitleParser();

            return(subtitleParser.Parse(input));
        }
Example #13
0
        public ActionResult CreateTranslation(int?id, int?languageID, HttpPostedFileBase file)
        {
            var    media = _unitOfWork.MediaRepository.GetByID(id);
            string type  = "";

            if (languageID == null)
            {
                ViewBag.Errormsg   = "Tungumál verður að vera valið.";
                ViewBag.LanguageID = new SelectList(_unitOfWork.LanguageRepository.Get(), "ID", "Name");
                type = media.GetType().BaseType.Name;
                switch (type)
                {
                case "Movie":
                    return(View("CreateMovieTranslation", media));

                case "Show":
                    return(View("CreateShowTranslation", media));

                case "Clip":
                    return(View("CreateClipTranslation", media));

                default:
                    throw new ApplicationException();
                }
            }
            var translationToFind = _unitOfWork.TranslationRepository.Get()
                                    .Where(t => t.MediaID == id)
                                    .Where(t => t.LanguageID == languageID)
                                    .SingleOrDefault();

            if (translationToFind == null)
            {
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path     = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                    file.SaveAs(path);
                    var translation = SubtitleParser.Parse(path, "srt");
                    translation.LanguageID = languageID.Value;
                    media.Translations.Add(translation);
                }
                else
                {
                    media.Translations.Add(new Translation {
                        LanguageID = languageID.Value
                    });
                }
                _unitOfWork.MediaRepository.Update(media);
                var userid = User.Identity.GetUserId();
                var user   = _unitOfWork.UserRepository.GetByID(userid);
                user.NewTranslations++;
                _unitOfWork.Save();
                HasRequest(id.Value, languageID.Value);
                var newTranslation = _unitOfWork.TranslationRepository.Get().OrderByDescending(t => t.ID).First();
                return(RedirectToAction("Index", "Translation", new { id = newTranslation.ID }));
            }
            ViewBag.Errormsg   = "Þessi þýðing er nú þegar til.";
            ViewBag.LanguageID = new SelectList(_unitOfWork.LanguageRepository.Get(), "ID", "Name");
            type = media.GetType().BaseType.Name;
            switch (type)
            {
            case "Movie":
                return(View("CreateMovieTranslation", media));

            case "Show":
                return(View("CreateShowTranslation", media));

            case "Clip":
                return(View("CreateClipTranslation", media));

            default:
                throw new ApplicationException();
            }
        }
Example #14
0
 public ActionResult CreateShow(ShowTranslationViewModel showTranslation, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         var show           = showTranslation.Show;
         var showToCheckFor = _unitOfWork.ShowRepository.Get()
                              .Where(s => s.Title == show.Title)
                              .Where(s => s.Series == show.Series)
                              .Where(s => s.Episode == show.Episode)
                              .SingleOrDefault();
         if (showToCheckFor == null)
         {
             show.Translations = new List <Translation>();
             if (file != null && file.ContentLength > 0)
             {
                 var fileName = Path.GetFileName(file.FileName);
                 var path     = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                 file.SaveAs(path);
                 var translation = SubtitleParser.Parse(path, "srt");
                 translation.LanguageID = showTranslation.LanguageID;
                 show.Translations.Add(translation);
             }
             else
             {
                 show.Translations.Add(new Translation {
                     LanguageID = showTranslation.LanguageID
                 });
             }
             _unitOfWork.ShowRepository.Insert(show);
             var userid = User.Identity.GetUserId();
             var user   = _unitOfWork.UserRepository.GetByID(userid);
             user.NewTranslations++;
             _unitOfWork.Save();
             var newTranslation = _unitOfWork.TranslationRepository.Get().OrderByDescending(t => t.ID).First();
             return(RedirectToAction("Index", "Translation", new { id = newTranslation.ID }));
         }
         else if (_unitOfWork.TranslationRepository.Get()
                  .Where(t => t.MediaID == showToCheckFor.ID)
                  .Where(t => t.LanguageID == showTranslation.LanguageID)
                  .SingleOrDefault() == null)
         {
             if (file != null && file.ContentLength > 0)
             {
                 var fileName = Path.GetFileName(file.FileName);
                 var path     = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                 file.SaveAs(path);
                 var translation = SubtitleParser.Parse(path, "srt");
                 translation.LanguageID = showTranslation.LanguageID;
                 showToCheckFor.Translations.Add(translation);
             }
             else
             {
                 showToCheckFor.Translations.Add(new Translation {
                     LanguageID = showTranslation.LanguageID
                 });
             }
             _unitOfWork.ShowRepository.Update(showToCheckFor);
             var userid = User.Identity.GetUserId();
             var user   = _unitOfWork.UserRepository.GetByID(userid);
             user.NewTranslations++;
             _unitOfWork.Save();
             HasRequest(showToCheckFor.ID, showTranslation.LanguageID);
             var newTranslation = _unitOfWork.TranslationRepository.Get().OrderByDescending(t => t.ID).First();
             return(RedirectToAction("Index", "Translation", new { id = newTranslation.ID }));
         }
         ViewBag.Errormsg = "Þessi þýðing er nú þegar til.";
     }
     ViewBag.CategoryID = new SelectList(_unitOfWork.CategoryRepository.Get(), "ID", "Name", showTranslation.Show.CategoryID);
     ViewBag.LanguageID = new SelectList(_unitOfWork.LanguageRepository.Get(), "ID", "Name");
     return(View("CreateShow"));
 }
Example #15
0
 private void AssertThrowsParsingException(SubtitleParser parser)
 {
     Assert.Throws <ParsingException>(
         () => parser.Parse(
             UnvalidatedSubtitleTests.CreateUnvalidatedSubtitle1()));
 }
Example #16
0
 public List <Subtitle> Parse(string fileContent)
 {
     return(_subtitleParser.Parse(fileContent));
 }
Example #17
0
 public ActionResult CreateClip(ClipTranslationViewModel clipTranslation, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         var clip           = clipTranslation.Clip;
         var clipToCheckFor = _unitOfWork.ClipRepository.Get()
                              .Where(c => c.Title == clip.Title)
                              .Where(c => c.ReleaseYear == clip.ReleaseYear)
                              .SingleOrDefault();
         if (clipToCheckFor == null)
         {
             clip.Translations = new List <Translation>();
             if (file != null && file.ContentLength > 0)
             {
                 var fileName = Path.GetFileName(file.FileName);
                 var path     = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                 file.SaveAs(path);
                 var translation = SubtitleParser.Parse(path, "srt");
                 translation.LanguageID = clipTranslation.LanguageID;
                 clip.Translations.Add(translation);
             }
             else
             {
                 clip.Translations.Add(new Translation {
                     LanguageID = clipTranslation.LanguageID
                 });
             }
             clip.Link = "//www.youtube.com/embed/" + YoutubeParser.parseLink(clip.Link);
             _unitOfWork.ClipRepository.Insert(clip);
             var userid = User.Identity.GetUserId();
             var user   = _unitOfWork.UserRepository.GetByID(userid);
             user.NewTranslations++;
             _unitOfWork.Save();
             var newTranslation = _unitOfWork.TranslationRepository.Get().OrderByDescending(t => t.ID).First();
             return(RedirectToAction("Index", "Translation", new { id = newTranslation.ID }));
         }
         else if (_unitOfWork.TranslationRepository.Get()
                  .Where(t => t.MediaID == clipToCheckFor.ID)
                  .Where(t => t.LanguageID == clipTranslation.LanguageID)
                  .SingleOrDefault() == null)
         {
             if (file != null && file.ContentLength > 0)
             {
                 var fileName = Path.GetFileName(file.FileName);
                 var path     = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                 file.SaveAs(path);
                 var translation = SubtitleParser.Parse(path, "srt");
                 translation.LanguageID = clipTranslation.LanguageID;
                 clipToCheckFor.Translations.Add(translation);
             }
             else
             {
                 clipToCheckFor.Translations.Add(new Translation {
                     LanguageID = clipTranslation.LanguageID
                 });
             }
             _unitOfWork.ClipRepository.Update(clipToCheckFor);
             var userid = User.Identity.GetUserId();
             var user   = _unitOfWork.UserRepository.GetByID(userid);
             user.NewTranslations++;
             _unitOfWork.Save();
             HasRequest(clipToCheckFor.ID, clipTranslation.LanguageID);
             var newTranslation = _unitOfWork.TranslationRepository.Get().OrderByDescending(t => t.ID).First();
             return(RedirectToAction("Index", "Translation", new { id = newTranslation.ID }));
         }
         ViewBag.Errormsg = "Þessi þýðing er nú þegar til.";
     }
     ViewBag.CategoryID = new SelectList(_unitOfWork.CategoryRepository.Get(), "ID", "Name", clipTranslation.Clip.CategoryID);
     ViewBag.LanguageID = new SelectList(_unitOfWork.LanguageRepository.Get(), "ID", "Name");
     return(View("CreateClip"));
 }