private void OpenSubtitle(string fileName, Encoding encoding, string videoFileName, string originalFileName)
        {
            if (File.Exists(fileName))
            {
                bool videoFileLoaded = false;
                var file = new FileInfo(fileName);
                var ext = file.Extension.ToLowerInvariant();

                // save last first visible index + first selected index from listview
                if (!string.IsNullOrEmpty(this._fileName))
                {
                    Configuration.Settings.RecentFiles.Add(this._fileName, this.FirstVisibleIndex, this.FirstSelectedIndex, this.VideoFileName, originalFileName);
                }

                this.openFileDialog1.InitialDirectory = file.DirectoryName;

                if (ext == ".sub" && this.IsVobSubFile(fileName, false))
                {
                    if (MessageBox.Show(this, this._language.ImportThisVobSubSubtitle, this._title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        this.ImportAndOcrVobSubSubtitleNew(fileName, this._loading);
                    }

                    return;
                }

                if (ext == ".sup")
                {
                    if (FileUtil.IsBluRaySup(fileName))
                    {
                        this.ImportAndOcrBluRaySup(fileName, this._loading);
                        return;
                    }
                    else if (FileUtil.IsSpDvdSup(fileName))
                    {
                        this.ImportAndOcrSpDvdSup(fileName, this._loading);
                        return;
                    }
                }

                if (ext == ".mkv" || ext == ".mks")
                {
                    this.ImportSubtitleFromMatroskaFile(fileName);
                    return;
                }

                if (ext == ".divx" || ext == ".avi")
                {
                    if (this.ImportSubtitleFromDivX(fileName))
                    {
                        return;
                    }
                }

                if ((ext == ".ts" || ext == ".rec" || ext == ".mpeg" || ext == ".mpg") && file.Length > 10000 && FileUtil.IsTransportStream(fileName))
                {
                    this.ImportSubtitleFromTransportStream(fileName);
                    return;
                }

                if ((ext == ".m2ts") && file.Length > 10000 && FileUtil.IsM2TransportStream(fileName))
                {
                    bool isTextSt = false;
                    if (file.Length < 2000000)
                    {
                        var textSt = new TextST();
                        isTextSt = textSt.IsMine(null, fileName);
                    }

                    if (!isTextSt)
                    {
                        this.ImportSubtitleFromTransportStream(fileName);
                        return;
                    }
                }

                if ((ext == ".mp4" || ext == ".m4v" || ext == ".3gp") && file.Length > 10000)
                {
                    if (this.ImportSubtitleFromMp4(fileName))
                    {
                        this.OpenVideo(fileName);
                    }

                    return;
                }

                if (ext == ".mxf")
                {
                    if (FileUtil.IsMaterialExchangeFormat(fileName))
                    {
                        var parser = new MxfParser(fileName);
                        if (parser.IsValid)
                        {
                            var subtitles = parser.GetSubtitles();
                            if (subtitles.Count > 0)
                            {
                                this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                                encoding = this.GetCurrentEncoding();
                                var list = new List<string>(subtitles[0].Replace(Environment.NewLine, "\r").Replace("\n", "\r").Split('\r'));
                                this._subtitle = new Subtitle();
                                var mxfFormat = this._subtitle.ReloadLoadSubtitle(list, null);
                                this.SetCurrentFormat(mxfFormat);
                                this._fileName = Path.GetFileNameWithoutExtension(fileName);
                                this.SetTitle();
                                this.ShowStatus(string.Format(this._language.LoadedSubtitleX, this._fileName));
                                this._sourceViewChange = false;
                                this._changeSubtitleToString = SerializeSubtitle(this._subtitle);
                                this.ResetHistory();
                                this.SetUndockedWindowsTitle();
                                this._converted = true;
                                this.ShowStatus(string.Format(this._language.LoadedSubtitleX, this._fileName) + " - " + string.Format(this._language.ConvertedToX, mxfFormat.FriendlyName));

                                this.ShowSource();
                                this.SubtitleListview1.Fill(this._subtitle, this._subtitleAlternate);
                                this._subtitleListViewIndex = -1;
                                this.SubtitleListview1.FirstVisibleIndex = -1;
                                this.SubtitleListview1.SelectIndexAndEnsureVisible(0);

                                return;
                            }

                            MessageBox.Show("No subtitles found!");
                            return;
                        }
                    }
                }

                if (file.Length > 1024 * 1024 * 10)
                {
                    // max 10 mb
                    // retry Blu-ray sup (file with wrong extension)
                    if (FileUtil.IsBluRaySup(fileName))
                    {
                        this.ImportAndOcrBluRaySup(fileName, this._loading);
                        return;
                    }

                    // retry vobsub (file with wrong extension)
                    if (this.IsVobSubFile(fileName, false))
                    {
                        if (MessageBox.Show(this, this._language.ImportThisVobSubSubtitle, this._title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            this.ImportAndOcrVobSubSubtitleNew(fileName, this._loading);
                        }

                        return;
                    }

                    var text = string.Format(this._language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + this._language.ContinueAnyway, fileName);
                    if (MessageBox.Show(this, text, this.Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                    {
                        return;
                    }
                }

                if (this._subtitle.HistoryItems.Count > 0 || this._subtitle.Paragraphs.Count > 0)
                {
                    this.MakeHistoryForUndo(string.Format(this._language.BeforeLoadOf, Path.GetFileName(fileName)));
                }

                bool change = this._changeSubtitleToString != SerializeSubtitle(this._subtitle);
                if (change)
                {
                    change = this._lastDoNotPrompt != SerializeSubtitle(this._subtitle);
                }

                SubtitleFormat format = this._subtitle.LoadSubtitle(fileName, out encoding, encoding);
                if (!change)
                {
                    this._changeSubtitleToString = SerializeSubtitle(this._subtitle);
                }

                this.ShowHideTextBasedFeatures(format);

                bool justConverted = false;
                if (format == null)
                {
                    var ebu = new Ebu();
                    if (ebu.IsMine(null, fileName))
                    {
                        ebu.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = ebu;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pac = new Pac();
                    if (pac.IsMine(null, fileName))
                    {
                        pac.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = pac;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (ext == ".m2ts")
                {
                    var textST = new TextST();
                    if (textST.IsMine(null, fileName))
                    {
                        textST.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = textST;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pns = new Pns();
                    if (pns.IsMine(null, fileName))
                    {
                        pns.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = pns;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var cavena890 = new Cavena890();
                    if (cavena890.IsMine(null, fileName))
                    {
                        cavena890.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = cavena890;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var spt = new Spt();
                    if (spt.IsMine(null, fileName))
                    {
                        spt.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = spt;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null && ext == ".wsb")
                {
                    var wsb = new Wsb();
                    var list = new List<string>(File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)));
                    if (wsb.IsMine(list, fileName))
                    {
                        wsb.LoadSubtitle(this._subtitle, list, fileName);
                        this._oldSubtitleFormat = wsb;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var cheetahCaption = new CheetahCaption();
                    if (cheetahCaption.IsMine(null, fileName))
                    {
                        cheetahCaption.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = cheetahCaption;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var capMakerPlus = new CapMakerPlus();
                    if (capMakerPlus.IsMine(null, fileName))
                    {
                        capMakerPlus.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = capMakerPlus;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var captionsInc = new CaptionsInc();
                    if (captionsInc.IsMine(null, fileName))
                    {
                        captionsInc.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = captionsInc;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var ultech130 = new Ultech130();
                    if (ultech130.IsMine(null, fileName))
                    {
                        ultech130.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = ultech130;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var nciCaption = new NciCaption();
                    if (nciCaption.IsMine(null, fileName))
                    {
                        nciCaption.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = nciCaption;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var tsb4 = new TSB4();
                    if (tsb4.IsMine(null, fileName))
                    {
                        tsb4.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = tsb4;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var avidStl = new AvidStl();
                    if (avidStl.IsMine(null, fileName))
                    {
                        avidStl.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = avidStl;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var chk = new Chk();
                    if (chk.IsMine(null, fileName))
                    {
                        chk.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = chk;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var ayato = new Ayato();
                    if (ayato.IsMine(null, fileName))
                    {
                        ayato.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = ayato;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pacUnicode = new PacUnicode();
                    if (pacUnicode.IsMine(null, fileName))
                    {
                        pacUnicode.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = pacUnicode;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var bdnXml = new BdnXml();
                        var list = new List<string>(File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)));
                        if (bdnXml.IsMine(list, fileName))
                        {
                            if (this.ContinueNewOrExit())
                            {
                                this.ImportAndOcrBdnXml(fileName, bdnXml, list);
                            }

                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var fcpImage = new FinalCutProImage();
                        var list = new List<string>(File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)));
                        if (fcpImage.IsMine(list, fileName))
                        {
                            if (this.ContinueNewOrExit())
                            {
                                this.ImportAndOcrDost(fileName, fcpImage, list);
                            }

                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    var elr = new ELRStudioClosedCaption();
                    if (elr.IsMine(null, fileName))
                    {
                        elr.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = elr;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var asc = new TimeLineAscii();
                    if (asc.IsMine(null, fileName))
                    {
                        asc.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = asc;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var asc = new TimeLineFootageAscii();
                    if (asc.IsMine(null, fileName))
                    {
                        asc.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = asc;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var mtv = new TimeLineMvt();
                    if (mtv.IsMine(null, fileName))
                    {
                        mtv.LoadSubtitle(this._subtitle, null, fileName);
                        this._oldSubtitleFormat = mtv;
                        this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = this.GetCurrentEncoding();
                        justConverted = true;
                        format = this.GetCurrentSubtitleFormat();
                    }
                }

                if (ext == ".dost")
                {
                    try
                    {
                        var dost = new Dost();
                        var list = new List<string>(File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)));
                        if (dost.IsMine(list, fileName))
                        {
                            if (this.ContinueNewOrExit())
                            {
                                this.ImportAndOcrDost(fileName, dost, list);
                            }

                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == Scenarist.NameOfFormat)
                {
                    try
                    {
                        var son = new Son();
                        var list = new List<string>(File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)));
                        if (son.IsMine(list, fileName))
                        {
                            if (this.ContinueNewOrExit())
                            {
                                this.ImportAndOcrSon(fileName, son, list);
                            }

                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == SubRip.NameOfFormat)
                {
                    if (this._subtitle.Paragraphs.Count > 1)
                    {
                        int imageCount = 0;
                        foreach (var p in this._subtitle.Paragraphs)
                        {
                            string s = p.Text.ToLowerInvariant();
                            if (s.EndsWith(".bmp", StringComparison.Ordinal) || s.EndsWith(".png", StringComparison.Ordinal) || s.EndsWith(".jpg", StringComparison.Ordinal) || s.EndsWith(".tif", StringComparison.Ordinal))
                            {
                                imageCount++;
                            }
                        }

                        if (imageCount > 2 && imageCount >= this._subtitle.Paragraphs.Count - 2)
                        {
                            if (this.ContinueNewOrExit())
                            {
                                this.ImportAndOcrSrt(this._subtitle);
                            }

                            return;
                        }
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var satBoxPng = new SatBoxPng();
                        var list = new List<string>(File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)));
                        if (satBoxPng.IsMine(list, fileName))
                        {
                            var subtitle = new Subtitle();
                            satBoxPng.LoadSubtitle(subtitle, list, fileName);
                            if (this.ContinueNewOrExit())
                            {
                                this.ImportAndOcrSrt(subtitle);
                            }

                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == Scenarist.NameOfFormat)
                {
                    try
                    {
                        var sst = new SonicScenaristBitmaps();
                        var list = new List<string>(File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)));
                        if (sst.IsMine(list, fileName))
                        {
                            if (this.ContinueNewOrExit())
                            {
                                this.ImportAndOcrSst(fileName, sst, list);
                            }

                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var htmlSamiArray = new HtmlSamiArray();
                        var list = new List<string>(File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)));
                        if (htmlSamiArray.IsMine(list, fileName))
                        {
                            htmlSamiArray.LoadSubtitle(this._subtitle, list, fileName);
                            this._oldSubtitleFormat = htmlSamiArray;
                            this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                            this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                            encoding = this.GetCurrentEncoding();
                            justConverted = true;
                            format = this.GetCurrentSubtitleFormat();
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                // retry vobsub (file with wrong extension)
                if (format == null && file.Length > 500 && this.IsVobSubFile(fileName, false))
                {
                    if (MessageBox.Show(this, this._language.ImportThisVobSubSubtitle, this._title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        this.ImportAndOcrVobSubSubtitleNew(fileName, this._loading);
                    }

                    return;
                }

                // retry Blu-ray (file with wrong extension)
                if (format == null && file.Length > 500 && FileUtil.IsBluRaySup(fileName))
                {
                    this.ImportAndOcrBluRaySup(fileName, this._loading);
                    return;
                }

                // retry SP DVD (file with wrong extension)
                if (format == null && file.Length > 500 && FileUtil.IsSpDvdSup(fileName))
                {
                    this.ImportAndOcrSpDvdSup(fileName, this._loading);
                    return;
                }

                // retry Matroska (file with wrong extension)
                if (format == null && !string.IsNullOrWhiteSpace(fileName))
                {
                    var matroska = new MatroskaFile(fileName);
                    if (matroska.IsValid)
                    {
                        var subtitleList = matroska.GetTracks(true);
                        if (subtitleList.Count > 0)
                        {
                            this.ImportSubtitleFromMatroskaFile(fileName);
                            return;
                        }
                    }
                }

                // check for idx file
                if (format == null && file.Length > 100 && ext == ".idx")
                {
                    MessageBox.Show(this._language.ErrorLoadIdx);
                    return;
                }

                // check for .rar file
                if (format == null && file.Length > 100 && FileUtil.IsRar(fileName))
                {
                    MessageBox.Show(this._language.ErrorLoadRar);
                    return;
                }

                // check for .zip file
                if (format == null && file.Length > 100 && FileUtil.IsZip(fileName))
                {
                    MessageBox.Show(this._language.ErrorLoadZip);
                    return;
                }

                // check for .png file
                if (format == null && file.Length > 100 && FileUtil.IsPng(fileName))
                {
                    MessageBox.Show(this._language.ErrorLoadPng);
                    return;
                }

                // check for .jpg file
                if (format == null && file.Length > 100 && FileUtil.IsJpg(fileName))
                {
                    MessageBox.Show(this._language.ErrorLoadJpg);
                    return;
                }

                // check for .srr file
                if (format == null && file.Length > 100 && ext == ".srr" && FileUtil.IsSrr(fileName))
                {
                    MessageBox.Show(this._language.ErrorLoadSrr);
                    return;
                }

                // check for Torrent file
                if (format == null && file.Length > 50 && FileUtil.IsTorrentFile(fileName))
                {
                    MessageBox.Show(this._language.ErrorLoadTorrent);
                    return;
                }

                // check for all binary zeroes (I've heard about this a few times... perhaps related to crashes?)
                if (format == null && file.Length > 50 && FileUtil.IsSubtitleFileAllBinaryZeroes(fileName))
                {
                    MessageBox.Show(this._language.ErrorLoadBinaryZeroes);
                    return;
                }

                if (format == null && file.Length < 100 * 1000000 && TransportStreamParser.IsDvbSup(fileName))
                {
                    this.ImportSubtitleFromDvbSupFile(fileName);
                    return;
                }

                if (format == null && file.Length < 500000)
                {
                    // Try to use a generic subtitle format parser (guessing subtitle format)
                    try
                    {
                        var enc = Utilities.GetEncodingFromFile(fileName);
                        var s = File.ReadAllText(fileName, enc);

                        // check for RTF file
                        if (ext == ".rtf" && s.TrimStart().StartsWith("{\\rtf", StringComparison.Ordinal))
                        {
                            using (var rtb = new RichTextBox { Rtf = s })
                            {
                                s = rtb.Text;
                            }
                        }

                        var uknownFormatImporter = new UknownFormatImporter { UseFrames = true };
                        var genericParseSubtitle = uknownFormatImporter.AutoGuessImport(s.SplitToLines());
                        if (genericParseSubtitle.Paragraphs.Count > 1)
                        {
                            this._subtitle = genericParseSubtitle;
                            this.SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                            this.SetEncoding(Configuration.Settings.General.DefaultEncoding);
                            encoding = this.GetCurrentEncoding();
                            justConverted = true;
                            format = this.GetCurrentSubtitleFormat();
                            this.ShowStatus("Guessed subtitle format via generic subtitle parser!");
                        }
                    }
                    catch
                    {
                    }
                }

                this._fileDateTime = File.GetLastWriteTime(fileName);

                if (format != null && format.IsFrameBased)
                {
                    this._subtitle.CalculateTimeCodesFromFrameNumbers(this.CurrentFrameRate);
                }
                else
                {
                    this._subtitle.CalculateFrameNumbersFromTimeCodes(this.CurrentFrameRate);
                }

                if (format != null)
                {
                    if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
                    {
                        this._subtitle.RemoveEmptyLines();
                    }

                    foreach (var p in this._subtitle.Paragraphs)
                    {
                        // Replace U+0456 (CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I) by U+0069 (LATIN SMALL LETTER I)
                        p.Text = p.Text.Replace("<і>", "<i>").Replace("</і>", "</i>");
                    }

                    this._subtitleListViewIndex = -1;
                    this.SetCurrentFormat(format);
                    this._subtitleAlternateFileName = null;
                    if (this.LoadAlternateSubtitleFile(originalFileName))
                    {
                        this._subtitleAlternateFileName = originalFileName;
                    }

                    // Seungki begin
                    this._splitDualSami = false;
                    if (Configuration.Settings.SubtitleSettings.SamiDisplayTwoClassesAsTwoSubtitles && format.GetType() == typeof(Sami) && Sami.GetStylesFromHeader(this._subtitle.Header).Count == 2)
                    {
                        var classes = Sami.GetStylesFromHeader(this._subtitle.Header);
                        var s1 = new Subtitle(this._subtitle);
                        var s2 = new Subtitle(this._subtitle);
                        s1.Paragraphs.Clear();
                        s2.Paragraphs.Clear();
                        foreach (var p in this._subtitle.Paragraphs)
                        {
                            if (p.Extra != null && p.Extra.Equals(classes[0], StringComparison.OrdinalIgnoreCase))
                            {
                                s1.Paragraphs.Add(p);
                            }
                            else
                            {
                                s2.Paragraphs.Add(p);
                            }
                        }

                        if (s1.Paragraphs.Count == 0 || s2.Paragraphs.Count == 0)
                        {
                            return;
                        }

                        this._subtitle = s1;
                        this._subtitleAlternate = s2;
                        this._subtitleAlternateFileName = this._fileName;
                        this.SubtitleListview1.HideExtraColumn();
                        this.SubtitleListview1.ShowAlternateTextColumn(classes[1]);
                        this._splitDualSami = true;
                    }

                    // Seungki end
                    this.textBoxSource.Text = this._subtitle.ToText(format);
                    this.SubtitleListview1.Fill(this._subtitle, this._subtitleAlternate);
                    if (this.SubtitleListview1.Items.Count > 0)
                    {
                        this.SubtitleListview1.Items[0].Selected = true;
                    }

                    this._findHelper = null;
                    this._spellCheckForm = null;

                    if (this._resetVideo)
                    {
                        this.VideoFileName = null;
                        this._videoInfo = null;
                        this._videoAudioTrackNumber = -1;
                        this.labelVideoInfo.Text = this._languageGeneral.NoVideoLoaded;
                        this.audioVisualizer.WavePeaks = null;
                        this.audioVisualizer.ResetSpectrogram();
                        this.audioVisualizer.Invalidate();
                    }

                    if (Configuration.Settings.General.ShowVideoPlayer || Configuration.Settings.General.ShowAudioVisualizer)
                    {
                        if (!Configuration.Settings.General.DisableVideoAutoLoading)
                        {
                            if (!string.IsNullOrEmpty(videoFileName) && File.Exists(videoFileName))
                            {
                                this.OpenVideo(videoFileName);
                            }
                            else if (!string.IsNullOrEmpty(fileName) && (this.toolStripButtonToggleVideo.Checked || this.toolStripButtonToggleWaveform.Checked))
                            {
                                this.TryToFindAndOpenVideoFile(Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)));
                            }
                        }
                    }

                    videoFileLoaded = this.VideoFileName != null;

                    if (Configuration.Settings.RecentFiles.Files.Count > 0 && Configuration.Settings.RecentFiles.Files[0].FileName == fileName)
                    {
                    }
                    else
                    {
                        Configuration.Settings.RecentFiles.Add(fileName, this.VideoFileName, this._subtitleAlternateFileName);
                        Configuration.Settings.Save();
                        this.UpdateRecentFilesUI();
                    }

                    this._fileName = fileName;
                    this.SetTitle();
                    this.ShowStatus(string.Format(this._language.LoadedSubtitleX, this._fileName));
                    this._sourceViewChange = false;
                    this._changeSubtitleToString = SerializeSubtitle(this._subtitle);
                    this._converted = false;
                    this.ResetHistory();

                    this.SetUndockedWindowsTitle();

                    if (justConverted)
                    {
                        this._converted = true;
                        this.ShowStatus(string.Format(this._language.LoadedSubtitleX, this._fileName) + " - " + string.Format(this._language.ConvertedToX, format.FriendlyName));
                    }

                    if (Configuration.Settings.General.AutoConvertToUtf8)
                    {
                        encoding = Encoding.UTF8;
                    }

                    this.SetEncoding(encoding);

                    if (format.GetType() == typeof(SubStationAlpha))
                    {
                        string errors = AdvancedSubStationAlpha.CheckForErrors(this._subtitle.Header);
                        if (!string.IsNullOrEmpty(errors))
                        {
                            MessageBox.Show(this, errors, this.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        errors = (format as SubStationAlpha).Errors;
                        if (!string.IsNullOrEmpty(errors))
                        {
                            MessageBox.Show(this, errors, this.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else if (format.GetType() == typeof(AdvancedSubStationAlpha))
                    {
                        string errors = AdvancedSubStationAlpha.CheckForErrors(this._subtitle.Header);
                        if (!string.IsNullOrEmpty(errors))
                        {
                            MessageBox.Show(this, errors, this.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }

                        errors = (format as AdvancedSubStationAlpha).Errors;
                        if (!string.IsNullOrEmpty(errors))
                        {
                            MessageBox.Show(errors, this.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else if (format.GetType() == typeof(SubRip))
                    {
                        string errors = (format as SubRip).Errors;
                        if (!string.IsNullOrEmpty(errors))
                        {
                            MessageBox.Show(this, errors, this.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else if (format.GetType() == typeof(MicroDvd))
                    {
                        string errors = (format as MicroDvd).Errors;
                        if (!string.IsNullOrEmpty(errors))
                        {
                            MessageBox.Show(this, errors, this.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    if (file.Length < 50)
                    {
                        this._findHelper = null;
                        this._spellCheckForm = null;
                        this.VideoFileName = null;
                        this._videoInfo = null;
                        this._videoAudioTrackNumber = -1;
                        this.labelVideoInfo.Text = this._languageGeneral.NoVideoLoaded;
                        this.audioVisualizer.WavePeaks = null;
                        this.audioVisualizer.ResetSpectrogram();
                        this.audioVisualizer.Invalidate();

                        Configuration.Settings.RecentFiles.Add(fileName, this.FirstVisibleIndex, this.FirstSelectedIndex, this.VideoFileName, this._subtitleAlternateFileName);
                        Configuration.Settings.Save();
                        this.UpdateRecentFilesUI();
                        this._fileName = fileName;
                        this.SetTitle();
                        this.ShowStatus(string.Format(this._language.LoadedEmptyOrShort, this._fileName));
                        this._sourceViewChange = false;
                        this._converted = false;

                        MessageBox.Show(this._language.FileIsEmptyOrShort);
                    }
                    else
                    {
                        if (ext == ".xml")
                        {
                            var sb = new StringBuilder();
                            foreach (var line in File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName)))
                            {
                                sb.AppendLine(line);
                            }

                            var xmlAsString = sb.ToString().Trim();

                            if (xmlAsString.Contains("http://www.w3.org/ns/ttml") && xmlAsString.Contains("<?xml version=") || xmlAsString.Contains("http://www.w3.org/") && xmlAsString.Contains("/ttaf1"))
                            {
                                var xml = new XmlDocument();
                                try
                                {
                                    xml.LoadXml(xmlAsString);
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("Timed text is not valid: " + ex.Message);
                                    return;
                                }
                            }
                        }

                        this.ShowUnknownSubtitle();
                        return;
                    }
                }

                if (!videoFileLoaded && this.mediaPlayer.VideoPlayer != null)
                {
                    this.mediaPlayer.VideoPlayer.DisposeVideoPlayer();
                    this.mediaPlayer.VideoPlayer = null;
                    this.timer1.Stop();
                }

                this.ResetShowEarlierOrLater();
            }
            else
            {
                MessageBox.Show(string.Format(this._language.FileNotFound, fileName));
            }
        }
        private void TryToFindAndOpenVideoFile(string fileNameNoExtension)
        {
            string movieFileName = null;

            foreach (var extension in Utilities.GetMovieFileExtensions())
            {
                var fileName = fileNameNoExtension + extension;
                if (File.Exists(fileName))
                {
                    bool skipLoad = false;
                    if (extension == ".m2ts" && new FileInfo(fileName).Length < 2000000)
                    {
                        var textSt = new TextST();
                        skipLoad = textSt.IsMine(null, fileName); // don't load TextST files as video/audio file
                    }

                    if (!skipLoad)
                    {
                        movieFileName = fileName;
                        break;
                    }
                }
            }

            if (movieFileName != null)
            {
                this.OpenVideo(movieFileName);
            }
            else
            {
                var index = fileNameNoExtension.LastIndexOf('.');
                if (index > 0)
                {
                    this.TryToFindAndOpenVideoFile(fileNameNoExtension.Remove(index));
                }
            }
        }
        private void ButtonImportClick(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                _textST = new TextST();
                _subtitle = new Subtitle();
                _fileName = openFileDialog1.FileName;
                _textST.LoadSubtitle(_subtitle, null, _fileName);
                groupBoxTextST.Text = "TextST structure: " + Path.GetFileName(_fileName);

                subtitleListView1.Fill(_subtitle);

                treeView1.Nodes.Clear();
                _root = new TreeNode("TextST");
                treeView1.Nodes.Add(_root);
                if (_textST.StyleSegment != null)
                {
                    var styleNode = new TreeNode(string.Format("Style segment", _textST.StyleSegment));
                    _root.Nodes.Add(styleNode);

                    var regionStylesNode = new TreeNode(string.Format("Region styles ({0})", _textST.StyleSegment.RegionStyles.Count));
                    styleNode.Nodes.Add(regionStylesNode);
                    foreach (TextST.RegionStyle regionStyle in _textST.StyleSegment.RegionStyles)
                    {
                        var regionStyleNode = new TreeNode("Region style") { Tag = regionStyle };
                        regionStylesNode.Nodes.Add(regionStyleNode);
                    }

                    var userStylesNode = new TreeNode(string.Format("User styles ({0})", _textST.StyleSegment.UserStyles.Count));
                    styleNode.Nodes.Add(userStylesNode);
                    foreach (TextST.UserStyle userStyle in _textST.StyleSegment.UserStyles)
                    {
                        var regionStyleNode = new TreeNode("User style") { Tag = userStyle };
                        userStylesNode.Nodes.Add(regionStyleNode);
                    }

                    var palettesNode = new TreeNode(string.Format("Palettes ({0})", _textST.StyleSegment.Palettes.Count)) { Tag = _textST.StyleSegment.Palettes };
                    styleNode.Nodes.Add(palettesNode);
                    foreach (TextST.Palette palette in _textST.StyleSegment.Palettes)
                    {
                        var paletteNode = new TreeNode("Palette") { Tag = palette };
                        palettesNode.Nodes.Add(paletteNode);
                    }
                }

                if (_textST.PresentationSegments != null)
                {
                    var presentationSegmentsNode = new TreeNode(string.Format("Presentation segments ({0})", _textST.PresentationSegments.Count));
                    _root.Nodes.Add(presentationSegmentsNode);
                    int count = 0;
                    foreach (TextST.DialogPresentationSegment segment in _textST.PresentationSegments)
                    {
                        count++;
                        var presentationSegmentNode = new TreeNode(string.Format("Segment {0}: {1} -- > {2}", count,
                            new TimeCode(segment.StartPtsMilliseconds), new TimeCode(segment.EndPtsMilliseconds))) { Tag = segment };
                        presentationSegmentsNode.Nodes.Add(presentationSegmentNode);
                    }
                }
                treeView1.ExpandAll();
                treeView1.SelectedNode = _root;
            }
        }