public void setLine(SubtitleLine line)
 {
     lines.Clear();
     lines.Add(line);
     lineNumber = 0;
     lastStartTime = Time.time;
 }
Exemple #2
0
 public void setLine(SubtitleLine line)
 {
     lines.Clear();
     lines.Add(line);
     lineNumber    = 0;
     lastStartTime = Time.time;
 }
Exemple #3
0
        public Hotkey(MainWindow mainWindow)
        {
            this.mainWindow = mainWindow;

            line = new SubtitleLine(mainWindow.lvEditor);

            Initialize();
            AddInputGesture();
            AddCommandBinding();
        }
        public MainWindow()
        {
            InitializeComponent();

            new ViewModels.Hotkey(this);
            subtitle = new Subtitle(this);
            time     = new SubtitleTime();
            line     = new SubtitleLine(lvEditor);
            video    = new Video(this);


            subtitle.New();
        }
Exemple #5
0
 public void UpdateSubtitleLine(int id, string text, string timeStart, string timeStop)
 {
     using (var context = new PandaBase())
     {
         // Locates a SubtitleLine in the database with
         // a given id
         SubtitleLine line = (context.SubtitleLines.Where(l => l.ID == id)
                              .FirstOrDefault <SubtitleLine>());
         // This adds two line breaks at the end of the text,
         // this is necessary for the .srt standard
         line.Text     = text + "\r\n" + "\r\n";
         line.TimeFrom = timeStart;
         line.TimeTo   = timeStop;
         // Marks the entry 'line' in the database as modified,
         // this way code-first knows it should update this entry in the database
         context.Entry(line).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemple #6
0
        private Subtitle BuildSubtitleFromGrid()
        {
            Subtitle nsubtitle = new Subtitle();

            nsubtitle.Header = subtitle.Header;
            nsubtitle.Footer = nsubtitle.Footer;
            nsubtitle.Bodies = new Dictionary <int, SubtitleLine>();
            foreach (DataGridViewRow row in dgvSubtitleSentence.Rows)
            {
                SubtitleLine line    = new SubtitleLine();
                var          number  = Convert.ToInt32(row.Cells[0].Value.ToString());
                var          orgLine = subtitle.Bodies[number];//.SingleOrDefault(i => i.Number == number);
                line.Number    = number;
                line.StartTime = orgLine.StartTime;
                line.EndTime   = orgLine.EndTime;
                line.Text      = row.Cells[2].Value.ToString();
                nsubtitle.Bodies.Add(number, line);
            }
            return(nsubtitle);
        }
Exemple #7
0
        public ActionResult Upload(Subtitle item, HttpPostedFileBase file)
        {
            var filename  = Path.GetFileName(file.FileName);
            var extension = Path.GetExtension(filename);

            //Checks if the file extension is correct and redirects user to error page if required.
            if ((extension != ".srt" && extension != ".txt"))
            {
                return(View("UploadError"));
            }

            Media med      = db.GetMediaByName(item.Title);
            Media newMedia = new Media();

            // If the media doesnt exist it
            // will be created automatically
            if (med == null)
            {
                newMedia.Title = item.Title;
                db.AddMedia(newMedia);
                med = newMedia;
            }

            if (ModelState.IsValid)
            {
                item.MediaID = med.ID;
                item.Author  = User.Identity.Name;
                db.AddSubtitle(item);

                //Code that checks if uploaded file has content
                //before the file is saved to the server.
                if ((file != null) && (file.ContentLength > 0))
                {
                    string fn           = System.IO.Path.GetFileName(file.FileName);
                    string SaveLocation = Server.MapPath("~/App_Data/" + fn);
                    file.SaveAs(SaveLocation);
                }

                SubtitleLine srtLine = new SubtitleLine();

                //Turn file to string
                string srtString = new StreamReader(file.InputStream, Encoding.Default, true).ReadToEnd();

                //regex for srt files from http://www.codeproject.com/Articles/32834/Subtitle-Synchronization-with-C
                string pattern = @"(?<sequence>\d+)\r\n(?<start>\d{2}\:\d{2}\:\d{2},\d{3}) --\> " +
                                 @"(?<end>\d{2}\:\d{2}\:\d{2},\d{3})\r\n(?<text>[\s\S]*?\r\n\r\n)";

                //parse string and send to database
                int  counter = 1;
                bool srtTrue = false;

                foreach (string result in Regex.Split(srtString, pattern))
                {
                    //first instance in the str format is always empty
                    if (counter == 1)
                    {
                        srtLine.Index    = 0;
                        srtLine.TimeFrom = null;
                        srtLine.TimeTo   = null;
                        srtLine.Text     = null;
                    }

                    //second instance is "subtitle number this"
                    if (counter == 2)
                    {
                        srtLine.Index = Convert.ToInt32(result);
                    }

                    //tird instance is TC in
                    if (counter == 3)
                    {
                        srtLine.TimeFrom = result;
                    }

                    //fourth is TC out
                    if (counter == 4)
                    {
                        srtLine.TimeTo = result;
                    }

                    //fifth is the actual onscreen text
                    if (counter == 5)
                    {
                        srtLine.Text       = result;
                        srtLine.SubtitleID = item.ID;
                        counter            = 0;
                    }

                    counter++;

                    // checks to see if all columns in srtLine have been populated
                    // before adding a line to the database.
                    if (srtLine.Index != 0 &&
                        srtLine.TimeFrom != null &&
                        srtLine.TimeTo != null &&
                        srtLine.Text != null &&
                        srtLine.SubtitleID != 0)
                    {
                        db.AddSubtitleLine(srtLine);
                        srtTrue = true;
                    }
                }

                //If columns have been populated the format is fine and file created.
                //Else entires that have been created are deleted and user directed to error page.
                if (srtTrue)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    db.DeleteSubtitle(item);
                    db.DeleteMedia(med);
                    return(View("UploadError"));
                }
            }

            // Gets language dropdown
            ViewBag.Languages = db.GetLanguageListItems();
            return(View(item));
        }