public override List <string> toLines(int index) { List <string> rtn = base.toLines(index); string temp = "Dialogue: "; for (int i = 0; i < Format.Length; i++) { if (i > 0) { temp += ","; } if (Format[i].Trim() == "Start") { temp += this.BeginStr; } else if (Format[i].Trim() == "End") { temp += this.EndStr; } else if (Format[i].Trim() == "Text") { temp += string.Join("\\N", Contents); } else { temp += ReadSubtitles.getPropertyValue(this, Format[i]); } } rtn.Add(temp); return(rtn); }
public Styles clone() { Styles rtn = new Styles(); for (int i = 0; i < Format.Length; i++) { ReadSubtitles.setPropertyValue(rtn, Format[i], ReadSubtitles.getPropertyValue(this, Format[i])); } return(rtn); }
/// <summary> /// 将参数中的两个字幕,按照时间进行合并,如果开始和结束时间相同,合并为同一个字幕元素,参数中前面的字幕在上方 /// </summary> /// <param name="path1">要合并的第一个字幕</param> /// <param name="path2">要合并的第二个字幕</param> /// <param name="toOneLine">合并字幕前是否将字幕放在同一行, 默认为true,表示合并</param> /// <param name="contect">合并字幕时的连接符</param> /// <returns></returns> public static ReadSubtitles MergeSubtitlesByTime(string path1, string path2, uint targetType = SubtitlesType.Type_Current, bool toOneLine = true, string contect = " ") { ReadSubtitles rs1 = ReadSubtitlesFromPath(path1); ReadSubtitles rs2 = ReadSubtitlesFromPath(path2); if (toOneLine) { rs1.toOneLine(contect); rs2.toOneLine(contect); } rs1.resortSrt(); rs2.resortSrt(); return(rs1.mergeSubtitlesByTime(rs2, targetType)); }
/// <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); }
public override string ToString() { string rtn = "Style: "; for (int i = 0; i < Format.Length; i++) { if (i > 0) { rtn += ","; } rtn += ReadSubtitles.getPropertyValue(this, Format[i]); } //rtn += Name; //rtn += "," + Fontname; //rtn += "," + Fontsize; //rtn += "," + PrimaryColour; //rtn += "," + SecondaryColour; //rtn += "," + OutlineColour; //rtn += "," + BackColour; //rtn += "," + Bold; //rtn += "," + Italic; //rtn += "," + Underline; //rtn += "," + StrikeOut; //rtn += "," + ScaleX; //rtn += "," + ScaleY; //rtn += "," + Spacing; //rtn += "," + Angle; //rtn += "," + BorderStyle; //rtn += "," + Outline; //rtn += "," + Shadow; //rtn += "," + Alignment; //rtn += "," + MarginL; //rtn += "," + MarginR; //rtn += "," + MarginV; //rtn += "," + Encoding; return(rtn); }
/// <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); }
/// <summary> /// 将当前字幕和参数中的字幕,按照时间进行合并,如果开始和结束时间相同,合并为同一个字幕元素,当前字幕在上方 /// </summary> /// <param name="subtitles">要参与合并的字幕</param> /// <param name="outPath">合并后字幕要输出的位置, 如果此值不为空,且为正确的路径,回自动写入合并后的字幕</param> /// <returns>合并后的字幕</returns> public ReadSubtitles mergeSubtitlesByTime(ReadSubtitles subtitles, uint type = SubtitlesType.Type_Current, string outPath = "") { ReadSRT rtn = new ReadSRT(); rtn.subtitlesUnits = new List <SubtitlesUnit>(); int lens1 = subtitlesUnits.Count; int lens2 = subtitles.subtitlesUnits.Count; rtn.fileInUrl = outPath == "" ? fileInUrl : outPath; SRTUnit tempUnit; int i = 0, j = 0; while (i < lens1 || j < lens2) { tempUnit = new SRTUnit(); if (i < lens1) { if (j < lens2) { if (subtitlesUnits[i].BeginTime == subtitles.subtitlesUnits[j].BeginTime && subtitlesUnits[i].EndTime == subtitles.subtitlesUnits[j].EndTime) { tempUnit.BeginTime = subtitlesUnits[i].BeginTime; tempUnit.EndTime = subtitlesUnits[i].EndTime; tempUnit.Contents.AddRange(subtitlesUnits[i].Contents); tempUnit.Contents.AddRange(subtitles.subtitlesUnits[j].Contents); i++; j++; } else if (subtitlesUnits[i].BeginTime < subtitles.subtitlesUnits[j].BeginTime) { tempUnit.BeginTime = subtitlesUnits[i].BeginTime; tempUnit.EndTime = subtitlesUnits[i].EndTime; tempUnit.Contents.AddRange(subtitlesUnits[i].Contents); i++; } else { tempUnit.BeginTime = subtitles.subtitlesUnits[j].BeginTime; tempUnit.EndTime = subtitles.subtitlesUnits[j].EndTime; tempUnit.Contents.AddRange(subtitles.subtitlesUnits[j].Contents); j++; } } else { tempUnit.BeginTime = subtitlesUnits[i].BeginTime; tempUnit.EndTime = subtitlesUnits[i].EndTime; tempUnit.Contents.AddRange(subtitlesUnits[i].Contents); i++; } } else { tempUnit.BeginTime = subtitles.subtitlesUnits[j].BeginTime; tempUnit.EndTime = subtitles.subtitlesUnits[j].EndTime; tempUnit.Contents.AddRange(subtitles.subtitlesUnits[j].Contents); j++; } rtn.subtitlesUnits.Add(tempUnit); } ReadSubtitles rs = this.convertTo(type); if (outPath != null && outPath.Length > 0) { rs.writeSubtitles(); } return(rs); }
/// <summary> /// 将参数路径中的字幕转化为参数类型的字幕 /// </summary> /// <param name="inPath">要转化的字幕路径</param> /// <param name="type">要转化的字幕类型</param> /// <param name="outPath">输出路径</param> /// <returns></returns> public static ReadSubtitles ConvertTo(string inPath, uint type = SubtitlesType.Type_SRT, string outPath = "") { ReadSubtitles rs = ReadSubtitles.ReadSubtitlesFromPath(inPath); return(rs == null ? null : rs.convertTo(type, outPath)); }