internal static void ReadMeta(IFileInfo fileInfo) { var b64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(fileInfo.FullName)); if (!File.Exists("settings.zip")) { return; } using (var zip = System.IO.Compression.ZipFile.OpenRead("settings.zip")) { foreach (var item in zip.Entries) { if (item.FullName.StartsWith("meta")) { if (item.FullName.EndsWith(b64)) { using (var stream = item.Open()) { var r = new StreamReader(stream); var mi = Stuff.GetMetaInfoOfFile(fileInfo); if (mi == null) { Stuff.MetaInfos.Add(new FileMetaInfo() { File = fileInfo }); } mi = Stuff.GetMetaInfoOfFile(fileInfo); if (mi.Infos.Any(z => z is SubtitlesMetaInfo)) { mi.Infos.RemoveAll(z => z is SubtitlesMetaInfo); } var sub = SubtitlesMetaInfo.FromSRT(r.ReadToEnd()); sub.Parent = mi; mi.Infos.Add(sub); } } } } } }
public static SubtitlesMetaInfo FromSRT(string text) { SubtitlesMetaInfo ret = new SubtitlesMetaInfo(); var split = text.Split(new string[] { Environment.NewLine + Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToArray(); foreach (var item in split) { var spl = item.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToArray(); var id = int.Parse(spl[0]); var spl2 = spl[1].Split(new string[] { "-->", " " }, StringSplitOptions.RemoveEmptyEntries).ToArray(); var start = TimeSpan.Parse(spl2[0]); var end = TimeSpan.Parse(spl2[1]); var spl3 = spl.Skip(2).ToArray(); var text1 = spl3.Aggregate("", (x, y) => x + y); ret.Items.Add(new SubtitleItem() { Text = text1, Start = start, End = end, Id = id }); } return(ret); }