Beispiel #1
0
        private void input_SelectionChanged(object sender, string val)
        {
            // get language
            bool   bFound      = false;
            string strLanguage = LanguageSelectionContainer.GetLanguageFromFileName(System.IO.Path.GetFileNameWithoutExtension(input.SelectedText));

            if (!String.IsNullOrEmpty(strLanguage))
            {
                SetLanguage(strLanguage);
                bFound = true;
            }
            else if (input.SelectedText.ToLowerInvariant().EndsWith(".idx"))
            {
                List <SubtitleInfo> subTracks;
                idxReader.readFileProperties(input.SelectedText, out subTracks);
                if (subTracks.Count > 0)
                {
                    SetLanguage(LanguageSelectionContainer.LookupISOCode(subTracks[0].Name));
                    bFound = true;
                }
            }
            if (!bFound && this.SelectedItem != null && this.SelectedStreamIndex > 0)
            {
                SetLanguage(MainForm.Instance.Settings.DefaultLanguage1);
            }

            // get delay & track name
            delay.Value = 0;
            if (this.SelectedItem != null && this.SelectedStreamIndex > 0 && this.SelectedItem.Tag is OneClickStream)
            {
                delay.Value  = ((OneClickStream)this.SelectedItem.Tag).Delay;
                subName.Text = ((OneClickStream)this.SelectedItem.Tag).Name;
            }
            if (PrettyFormatting.getDelayAndCheck(input.SelectedText) != null)
            {
                delay.Value = PrettyFormatting.getDelayAndCheck(input.SelectedText) ?? 0;
            }

            if (showDefaultStream)
            {
                chkDefaultStream.Checked = this.SelectedStream.DefaultStream;
            }

            if (showForceStream)
            {
                chkForceStream.Checked = this.SelectedStream.ForcedStream;
            }

            raiseEvent();
        }
Beispiel #2
0
        /// <summary>
        /// extracts the subtitle tracks in multiple files if needed
        /// </summary>
        private void writeSubtitles()
        {
            string strInputFile = job.Output;

            if (!base.bFirstPass)
            {
                strInputFile = Path.Combine(Path.GetDirectoryName(strInputFile), Path.GetFileNameWithoutExtension(strInputFile) + "_forced.idx");
                string   strSUBFile = Path.ChangeExtension(strInputFile, ".sub");
                FileInfo f          = null;
                if (File.Exists(strSUBFile))
                {
                    f = new FileInfo(strSUBFile);
                }
                if (f == null || f.Length == 0)
                {
                    log.LogEvent("no forced subtitles found");
                    job.FilesToDelete.Add(strInputFile);
                    job.FilesToDelete.Add(strSUBFile);
                    return;
                }
            }

            if (job.SingleFileExport || !File.Exists(strInputFile))
            {
                return;
            }

            // multiple output files have to be generated based on the single input file
            su.Status = "Generating files...";

            string        line;
            string        strLanguage   = string.Empty;
            bool          bHeader       = true; // same header for all output files
            bool          bWait         = false;
            bool          bContentFound = false;
            StringBuilder sbHeader      = new StringBuilder();
            StringBuilder sbIndex       = new StringBuilder();
            StringBuilder sbIndexTemp   = new StringBuilder();
            int           index         = 0;

            using (StreamReader file = new StreamReader(strInputFile))
            {
                while ((line = file.ReadLine()) != null)
                {
                    if (bHeader)
                    {
                        if (line.StartsWith("langidx:"))
                        {
                            // first subtitle track detected
                            bHeader = false;
                            bWait   = true;
                        }
                        else
                        {
                            sbHeader.AppendLine(line);
                        }
                    }
                    else if (bWait)
                    {
                        sbIndexTemp.AppendLine(line);
                        if (line.StartsWith("id: "))
                        {
                            // new track detected
                            index       = Int32.Parse(line.Substring(line.LastIndexOf(' ')));
                            strLanguage = line.Substring(line.IndexOf(' ') + 1, line.LastIndexOf(',') - line.IndexOf(' ') - 1);
                            strLanguage = LanguageSelectionContainer.LookupISOCode(strLanguage);

                            // create full output text
                            sbIndex.Clear();
                            sbIndex.Append(sbHeader.ToString());
                            sbIndex.AppendLine("langidx: " + index);
                            sbIndex.Append(sbIndexTemp.ToString());
                            bWait         = false;
                            bContentFound = false;
                        }
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(line))
                        {
                            bWait = true;

                            // check if the track found in the input file is selected to be demuxed
                            bool bFound = false;
                            if (!job.IndexAllTracks)
                            {
                                foreach (int id in job.TrackIDs)
                                {
                                    if (index == id)
                                    {
                                        bFound = true;
                                    }
                                }
                            }

                            // export if found or if all tracks should be demuxed
                            if ((bFound && bFirstPass) || (bFound && !bFirstPass && bContentFound) || (job.IndexAllTracks && bContentFound))
                            {
                                // create output file
                                string outputFile = Path.Combine(Path.GetDirectoryName(job.Output),
                                                                 Path.GetFileNameWithoutExtension(job.Output)) + "_" + index + "_" + strLanguage + (!base.bFirstPass ? "_forced" : string.Empty) + ".idx";
                                using (StreamWriter output = new StreamWriter(outputFile))
                                    output.WriteLine(sbIndex.ToString());

                                outputFile = Path.ChangeExtension(outputFile, ".sub");
                                File.Copy(Path.ChangeExtension(strInputFile, ".sub"), outputFile, true);

                                log.LogEvent("Subtitle file created: " + Path.GetFileName(outputFile));
                            }

                            sbIndexTemp.Clear();
                            sbIndexTemp.AppendLine(line);
                        }
                        else
                        {
                            if (line.StartsWith("timestamp:"))
                            {
                                bContentFound = true;
                            }
                            sbIndex.AppendLine(line);
                        }
                    }
                }
            }
        }