/// <summary> /// Get subtitle parser to use for the provided subtitle file. /// </summary> public static SubsParser getSubtitleParserType(WorkerVars workerVars, string filename, int stream, int episode, int subsNum, Encoding subsEncoding) { SubsParser parser; string ext = filename.Substring(filename.LastIndexOf(".")); ext = ext.ToLower(); if (ext == ".ass" || ext == ".ssa") { parser = new SubsParserASS(workerVars, filename, subsEncoding, subsNum); } else if (ext == ".srt") { parser = new SubsParserSRT(filename, subsEncoding); } else if (ext == ".sub" || ext == ".idx") { parser = new SubsParserVOBSUB(workerVars, filename, stream, episode, subsNum); } else if (ext == ".lrc") { parser = new SubsParserLyrics(filename, subsEncoding); } else if (ext == ".trs") { parser = new SubsParserTranscriber(filename, subsEncoding); } else { parser = null; } return(parser); }
/// <summary> /// Get subtitle parser to use for the provided subtitle file. /// </summary> public static SubsParser getSubtitleParserType(WorkerVars workerVars, string filename, int stream, int episode, int subsNum, Encoding subsEncoding) { SubsParser parser; string ext = filename.Substring(filename.LastIndexOf(".")); ext = ext.ToLower(); switch (ext) { case ".ass": case ".ssa": parser = new SubsParserASS(workerVars, filename, subsEncoding, subsNum); break; case ".srt": parser = new SubsParserSRT(filename, subsEncoding); break; case ".sub": case ".idx": parser = new SubsParserVOBSUB(workerVars, filename, stream, episode, subsNum); break; case ".lrc": parser = new SubsParserLyrics(filename, subsEncoding); break; case ".trs": parser = new SubsParserTranscriber(filename, subsEncoding); break; case ".vtt": parser = new SubsParserVTT(filename, subsEncoding); break; default: parser = null; break; } return(parser); }
/// <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); } }