/// <summary> /// 将当前字幕转化为参数类型的字幕 /// </summary> /// <param name="type">要转化的字幕类型</param> /// <param name="outPath">输出路径</param> /// <returns></returns> public virtual ReadSubtitles convertTo(uint type = SubtitlesType.Type_SRT, string outPath = "") { if (type == SubtitlesType.Type_Current) { if (this is ReadASS) { type = SubtitlesType.Type_ASS; } else { type = SubtitlesType.Type_SRT; } } ReadSubtitles rs = null; switch (type) { case 1: //srt rs = new ReadSRT(); rs.subtitlesUnits = new List <SubtitlesUnit>(); for (int i = 0; i < subtitlesUnits.Count; i++) { rs.subtitlesUnits.Add(new SRTUnit(subtitlesUnits[i])); } break; case 2: //ASS rs = new ReadASS(); (rs as ReadASS).StyleList.Add(new Styles()); (rs as ReadASS).ScriptInfomation = new ScriptInfo(); //rs.subtitlesUnits = new List<SubtitlesUnit>(); for (int i = 0; i < subtitlesUnits.Count; i++) { rs.subtitlesUnits.Add(new ASSUnit(subtitlesUnits[i])); } break; } if (outPath != "") { rs.writeSubtitles(outPath); } return(rs); }
/// <summary> /// 从指定路径读取字幕文件 /// </summary> /// <param name="path"></param> /// <returns></returns> public static ReadSubtitles ReadSubtitlesFromPath(string path) { if (!File.Exists(path)) { return(null); } ReadSubtitles rs = null; switch (Path.GetExtension(path).ToLower()) { case ".srt": rs = new ReadSRT(); break; case ".ass": rs = new ReadASS(); break; } if (rs != null) { rs.readSubtitles(path); } return(rs); }