Пример #1
0
        private void textBoxSubs2File_Validating(object sender, CancelEventArgs e)
        {
            string error       = null;
            string filePattern = ((TextBox)sender).Text.Trim();

            string[] files = UtilsCommon.getNonHiddenFiles(filePattern);

            if ((error == null) && (UtilsSubs.getNumSubsFiles(filePattern) == 0))
            {
                error = "Please provide a valid subtitle file. \nOnly .srt, .ass and .ssa are allowed.";
                invalidCount++;
            }

            if ((error == null))
            {
                foreach (string f in files)
                {
                    if (!isSupportedSubtitleFormat(f))
                    {
                        error = "Please provide a valid subtitle file. \nOnly .srt, .ass and .ssa are allowed.";
                        invalidCount++;
                        break;
                    }
                }
            }

            if ((error == null) && (UtilsSubs.getNumSubsFiles(filePattern) != UtilsSubs.getNumSubsFiles(textBoxSubs1File.Text.Trim())))
            {
                error = "The number of files here must match\nthe number of subtitle files in Subs1.";
                invalidCount++;
            }

            errorProvider1.SetError((Control)sender, error);
        }
        private void textBoxMediaFile_Validating(object sender, CancelEventArgs e)
        {
            string error       = null;
            string filePattern = ((TextBox)sender).Text.Trim();

            string[] files = UtilsCommon.getNonHiddenFiles(filePattern);

            // Do error checking here

            errorProvider1.SetError((Control)sender, error);
        }
        /// <summary>
        /// Update the global settings based on GUI.
        /// </summary>
        private void updateSettings()
        {
            mediaFiles         = UtilsCommon.getNonHiddenFiles(textBoxMediaFile.Text.Trim());
            audioStream        = (InfoStream)comboBoxStreamAudioFromVideo.SelectedItem;
            outputDir          = textBoxOutputDir.Text.Trim();
            deckName           = textBoxName.Text.Trim().Replace(" ", "_");
            episodeStartNumber = Convert.ToInt32(numericUpDownEpisodeStartNumber.Text.Trim());
            isSingleFile       = radioButtonSingle.Checked;

            if (groupBoxCheckLyrics.Checked)
            {
                Settings.Instance.Subs[0].FilePattern         = textBoxSubs1File.Text.Trim();
                Settings.Instance.Subs[0].TimingsEnabled      = radioButtonTimingSubs1.Checked;
                Settings.Instance.Subs[0].TimeShift           = (int)numericUpDownTimeShiftSubs1.Value;
                Settings.Instance.Subs[0].Files               = UtilsSubs.getSubsFiles(Settings.Instance.Subs[0].FilePattern).ToArray();
                Settings.Instance.Subs[0].Encoding            = InfoEncoding.longToShort(this.comboBoxEncodingSubs1.Text);
                Settings.Instance.Subs[0].RemoveNoCounterpart = this.checkBoxRemoveLinesWithoutCounterpartSubs1.Checked;
                Settings.Instance.Subs[0].RemoveStyledLines   = this.checkBoxRemoveStyledLinesSubs1.Checked;

                Settings.Instance.Subs[1].FilePattern         = textBoxSubs2File.Text.Trim();
                Settings.Instance.Subs[1].TimingsEnabled      = radioButtonTimingSubs2.Checked;
                Settings.Instance.Subs[1].TimeShift           = (int)numericUpDownTimeShiftSubs2.Value;
                Settings.Instance.Subs[1].Encoding            = InfoEncoding.longToShort(this.comboBoxEncodingSubs2.Text);
                Settings.Instance.Subs[1].RemoveNoCounterpart = this.checkBoxRemoveLinesWithoutCounterpartSubs2.Checked;
                Settings.Instance.Subs[1].RemoveStyledLines   = this.checkBoxRemoveStyledLinesSubs2.Checked;

                if (Settings.Instance.Subs[1].FilePattern.Trim().Length > 0)
                {
                    Settings.Instance.Subs[1].Files = UtilsSubs.getSubsFiles(Settings.Instance.Subs[1].FilePattern).ToArray();
                }
                else
                {
                    Settings.Instance.Subs[1].Files = new string[0];
                }

                Settings.Instance.TimeShiftEnabled = groupBoxCheckTimeShift.Checked;
            }

            if (!isSingleFile)
            {
                clipLength = UtilsSubs.stringToTime(maskedTextBoxClipLength.Text.Trim());
            }

            useSpan = this.groupBoxCheckSpan.Checked;

            if (useSpan)
            {
                spanStart = UtilsSubs.stringToTime(maskedTextBoxSpanStart.Text.Trim());
                spanEnd   = UtilsSubs.stringToTime(maskedTextBoxSpanEnd.Text.Trim());
            }

            bitrate = Convert.ToInt32(comboBoxBitrate.Text.Trim());
        }
Пример #4
0
        /// <summary>
        /// Get list of subtitle files for the provided file pattern.
        /// </summary>
        public static List <string> getSubsFiles(string filePattern)
        {
            List <string> subsFiles = new List <string>();

            string[] allFiles = UtilsCommon.getNonHiddenFiles(filePattern);

            foreach (string file in allFiles)
            {
                if (isSupportedSubtitleFormat(file))
                {
                    subsFiles.Add(file);
                }
            }

            return(subsFiles);
        }
Пример #5
0
        /// <summary>
        /// Get number of subtitles or IDX/SUB pairs for the provided file pattern.
        /// </summary>
        public static int getNumSubsFiles(string filePattern)
        {
            int numSub = 0;

            string[] subsFiles = UtilsCommon.getNonHiddenFiles(filePattern);

            foreach (string file in subsFiles)
            {
                if (isSupportedSubtitleFormat(file))
                {
                    numSub++;
                }
            }

            return(numSub);
        }
        private void textBoxSubs2File_Validating(object sender, CancelEventArgs e)
        {
            string error       = null;
            string filePattern = ((TextBox)sender).Text.Trim();

            string[] files = UtilsCommon.getNonHiddenFiles(filePattern);

            if (groupBoxCheckLyrics.Checked)
            {
                if ((radioButtonTimingSubs2.Checked) && (filePattern == ""))
                {
                    error = "Since you want to use subs2 timings,\nplease enter a valid Subs2 subtitle file here";
                    invalidCount++;
                }

                if ((error == null) && (filePattern != ""))
                {
                    if ((error == null) && (UtilsSubs.getNumSubsFiles(filePattern) == 0))
                    {
                        error = "Please provide a valid subtitle file. \nOnly .srt, .ass, .ssa, .lrc and .trs are allowed.";
                        invalidCount++;
                    }

                    if ((error == null))
                    {
                        foreach (string f in files)
                        {
                            if (!isSupportedSubtitleFormat(f))
                            {
                                error = "Please provide a valid subtitle file. \nOnly .srt, .ass, .ssa, .lrc and .trs are allowed.";
                                invalidCount++;
                                break;
                            }
                        }
                    }

                    if ((error == null) && (UtilsSubs.getNumSubsFiles(filePattern) != UtilsCommon.getNonHiddenFiles(textBoxMediaFile.Text.Trim()).Length))
                    {
                        error = "The number of files here must match\nthe number of files in Media";
                        invalidCount++;
                    }
                }
            }

            errorProvider1.SetError((Control)sender, error);
        }
Пример #7
0
        /// <summary>
        /// Does the expanded file pattern contain vobsubs?
        /// </summary>
        public static bool filePatternContainsVobsubs(string filePattern)
        {
            bool containsVobsubs = false;

            string[] subsFiles = UtilsCommon.getNonHiddenFiles(filePattern);

            foreach (string file in subsFiles)
            {
                string ext = file.Substring(file.LastIndexOf(".")).ToLower();

                if (ext == ".idx")
                {
                    containsVobsubs = true;
                    break;
                }
            }

            return(containsVobsubs);
        }
        private void textBoxMediaFile_TextChanged(object sender, EventArgs e)
        {
            string filePattern = this.textBoxMediaFile.Text.Trim();

            string[] files = UtilsCommon.getNonHiddenFiles(filePattern);

            this.comboBoxStreamAudioFromVideo.Enabled = true;
            this.labelAudioStream.Enabled             = true;

            this.comboBoxStreamAudioFromVideo.Items.Clear();

            if (files.Length != 0)
            {
                // Based on the first video file in the file pattern, get the list of available streams.
                string            firstFile    = files[0];
                List <InfoStream> audioStreams = UtilsVideo.getAvailableAudioStreams(firstFile);

                if (audioStreams.Count > 0)
                {
                    foreach (InfoStream stream in audioStreams)
                    {
                        this.comboBoxStreamAudioFromVideo.Items.Add(stream);
                    }
                }
                else
                {
                    // Show the default stream when the available streams cannot be detected
                    this.comboBoxStreamAudioFromVideo.Items.Add(new InfoStream());
                }

                this.comboBoxStreamAudioFromVideo.SelectedIndex = 0;
            }
            else
            {
                this.comboBoxStreamAudioFromVideo.Enabled = false;
                this.labelAudioStream.Enabled             = false;
            }
        }
Пример #9
0
        /// <summary>
        /// In the provided file pattern have a corresponding .sub file for each .idx file encountered?
        /// </summary>
        public static bool isVobsubFilePatternCorrect(string filePattern)
        {
            bool isCorrect = false;
            int  numIdx    = 0;
            int  numSub    = 0;

            string[] subsFiles = UtilsCommon.getNonHiddenFiles(filePattern);

            foreach (string file in subsFiles)
            {
                string ext = file.Substring(file.LastIndexOf(".")).ToLower();

                if (ext == ".idx")
                {
                    numIdx++;

                    string fileNoExt = file.Substring(0, file.LastIndexOf("."));
                    string subFile   = fileNoExt + ".sub";

                    if (File.Exists(subFile))
                    {
                        numSub++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if ((numIdx > 0) && (numIdx == numSub))
            {
                isCorrect = true;
            }


            return(isCorrect);
        }
Пример #10
0
        /// <summary>
        /// Parse the actors from the subtitle file (if possible) and populate the actors list.
        /// </summary>
        private void buttonActorCheck_Click(object sender, EventArgs e)
        {
            string[] subs1Files = null;
            string[] subs2Files = null;

            listBoxActors.Items.Clear();

            if (radioButtonSubs1Actor.Checked)
            {
                if (subs1FilePattern.Length == 0)
                {
                    UtilsMsg.showErrMsg("Can't check - Subs1 file isn't valid.");
                    return;
                }
                else
                {
                    subs1Files = UtilsCommon.getNonHiddenFiles(subs1FilePattern);

                    if (subs1Files.Length > 0)
                    {
                        foreach (string f in subs1Files)
                        {
                            if (!isActorSupportedSubtitleFormat(f))
                            {
                                UtilsMsg.showErrMsg("Can't check - Incorrect subtitle format found in Subs1 (only .ass/.ssa allowed).");
                                return;
                            }
                        }
                    }
                    else
                    {
                        UtilsMsg.showErrMsg("Can't check - No .ass/ssa files were found in Subs1.");
                        return;
                    }
                }
            }
            else
            {
                if (subs2FilePattern.Length == 0)
                {
                    UtilsMsg.showErrMsg("Can't check - Subs2 file isn't valid.");
                    return;
                }
                else
                {
                    subs2Files = UtilsCommon.getNonHiddenFiles(subs2FilePattern);

                    if (subs2Files.Length > 0)
                    {
                        foreach (string f in subs2Files)
                        {
                            if (!isActorSupportedSubtitleFormat(f))
                            {
                                UtilsMsg.showErrMsg("Can't check - Incorrect subtitle format found in Subs2 (only .ass/.ssa allowed).");
                                return;
                            }
                        }
                    }
                    else
                    {
                        UtilsMsg.showErrMsg("Can't check - No .ass/ssa files were found in Subs2.");
                        return;
                    }
                }
            }

            string[] fileList = null;
            Encoding fileEncoding;

            int subsNum = 1;

            if (radioButtonSubs1Actor.Checked)
            {
                subsNum      = 1;
                fileList     = subs1Files;
                fileEncoding = Encoding.GetEncoding(InfoEncoding.longToShort(this.subs1Encoding));
            }
            else
            {
                subsNum      = 2;
                fileList     = subs2Files;
                fileEncoding = Encoding.GetEncoding(InfoEncoding.longToShort(this.subs2Encoding));
            }

            List <string> actorList = new List <string>();

            // Get list of actors from all episodes
            foreach (string file in fileList)
            {
                SubsParser      subsParser    = new SubsParserASS(null, file, fileEncoding, subsNum);
                List <InfoLine> subsLineInfos = subsParser.parse();

                foreach (InfoLine info in subsLineInfos)
                {
                    string actor = info.Actor.Trim();
                    if (!actorList.Contains(actor))
                    {
                        actorList.Add(actor);
                    }
                }
            }

            foreach (string actor in actorList)
            {
                string addActor = actor;
                listBoxActors.Items.Add(addActor);
            }

            for (int i = 0; i < listBoxActors.Items.Count; i++)
            {
                listBoxActors.SetSelected(i, true);
            }
        }
Пример #11
0
        /// <summary>
        /// Get list of subtitle files for the provided file pattern.
        /// </summary>
        public static List <string> getSubsFiles(string filePattern)
        {
            string[] allFiles = UtilsCommon.getNonHiddenFiles(filePattern);

            return(allFiles.Where(isSupportedSubtitleFormat).ToList());
        }
Пример #12
0
        /// <summary>
        /// Get number of subtitles or IDX/SUB pairs for the provided file pattern.
        /// </summary>
        public static int getNumSubsFiles(string filePattern)
        {
            string[] subsFiles = UtilsCommon.getNonHiddenFiles(filePattern);

            return(subsFiles.Count(isSupportedSubtitleFormat));
        }
Пример #13
0
        /// <summary>
        /// Does the expanded file pattern contain vobsubs?
        /// </summary>
        public static bool filePatternContainsVobsubs(string filePattern)
        {
            string[] subsFiles = UtilsCommon.getNonHiddenFiles(filePattern);

            return(subsFiles.Select(file => file.Substring(file.LastIndexOf(".")).ToLower()).Any(ext => ext == ".idx"));
        }