public List <Stream> GetStreams(IFile file) { string dirname = Path.GetDirectoryName(file.FullName); string fname = Path.GetFileNameWithoutExtension(file.Name); if (string.IsNullOrEmpty(dirname) || string.IsNullOrEmpty(fname)) { return(null); } string basename = Path.Combine(dirname, fname); IObject r = file.FileSystem.Resolve(basename + ".idx"); if (r.Status != Status.Ok || r is IDirectory) { return(null); } FileSystemResult <System.IO.Stream> res = ((IFile)r).OpenRead(); if (res.Status != Status.Ok) { return(null); } StreamReader reader = new StreamReader(res.Result); string bing = reader.ReadToEnd(); if (!bing.Contains("VobSub index file")) { return(null); } Regex ex = new Regex("\\nid: ([A-Za-z]{2})"); MatchCollection ma = ex.Matches(bing); int x = 0; List <Stream> ss = new List <Stream>(); foreach (Match m in ma) { if (m.Success) { string language = null; string val = m.Groups[1].Value.ToLower(); if (SubtitleHelper.Iso639_3_TO_Iso639_1.ContainsKey(val)) { language = SubtitleHelper.Iso639_3_TO_Iso639_1[val]; } else if (SubtitleHelper.Iso639_1_TO_Languages.ContainsKey(val)) { language = val; } else if (SubtitleHelper.Languages_TO_ISO639_1_Lower.ContainsKey(val)) { language = SubtitleHelper.Languages_TO_ISO639_1_Lower[val]; } if (language != null) { Stream s = new Stream { Format = "vobsub", StreamType = 3, SubIndex = x, File = basename + ".idx", LanguageCode = SubtitleHelper.Iso639_1_TO_Iso639_3[language], Language = SubtitleHelper.Iso639_1_TO_Languages[language] }; ss.Add(s); } } x++; } return(ss); }
public List <Stream> GetStreams(IFile file) { string ext = Path.GetExtension(file.Name); if (string.IsNullOrEmpty(ext)) { return(null); } ext = ext.Replace(".", string.Empty).ToLower(); string name = Path.GetFileNameWithoutExtension(file.Name); if (string.IsNullOrEmpty(name)) { return(null); } Regex lm = new Regex(".+\\.([^\\.]+)$", RegexOptions.Singleline); MatchCollection col = lm.Matches(name); string language = "xx"; foreach (Match m in col) { if (m.Success) { string val = m.Groups[1].Value.ToLower(); if (SubtitleHelper.Iso639_3_TO_Iso639_1.ContainsKey(val)) { language = SubtitleHelper.Iso639_3_TO_Iso639_1[val]; break; } if (SubtitleHelper.Iso639_1_TO_Languages.ContainsKey(val)) { language = val; break; } if (SubtitleHelper.Languages_TO_ISO639_1_Lower.ContainsKey(val)) { language = SubtitleHelper.Languages_TO_ISO639_1_Lower[val]; break; } } } string format = null; List <Stream> sts = new List <Stream>(); if ((ext == "txt") || (ext == "sub")) { FileSystemResult <System.IO.Stream> res = file.OpenRead(); if (res.Status != Status.Ok) { return(sts); } List <string> lines = new List <string>(); StreamReader reader = new StreamReader(res.Result); while (!reader.EndOfStream) { lines.Add(reader.ReadLine()); } string firstline = null; foreach (string ws in lines) { string k = ws.Trim(); if (!string.IsNullOrEmpty(k)) { firstline = k; break; } } if (firstline != null) { lm = new Regex("^\\{[0-9]+\\}\\{[0-9]*\\}", RegexOptions.Singleline); Match m = lm.Match(firstline); if (m.Success) { format = "microdvd"; } else { lm = new Regex("^[0-9]{1,2}:[0-9]{2}:[0-9]{2}[:=,]", RegexOptions.Singleline); m = lm.Match(firstline); if (m.Success) { format = "txt"; } else { if (firstline.Contains("[SUBTITLE]")) { format = "subviewer"; } } } } } ext = ext.Replace("ass", "ssa"); if (format == null) { format = ext; } Stream s = new Stream { Format = format, StreamType = 3, File = file.FullName, LanguageCode = SubtitleHelper.Iso639_1_TO_Iso639_3[language], Language = SubtitleHelper.Iso639_1_TO_Languages[language] }; sts.Add(s); return(sts); }
public void AddVideo(Shoko.Models.PlexAndKodi.Stream dict) { videos.Add(videos.Count + 1, dict); }
public void AddSubtitle(Shoko.Models.PlexAndKodi.Stream dict) { subtitles.Add(subtitles.Count + 1, dict); }
public void AddAudio(Shoko.Models.PlexAndKodi.Stream dict) { audios.Add(audios.Count + 1, dict); }