예제 #1
0
        public List <Stream> GetStreams(string filename)
        {
            string dirname = Path.GetDirectoryName(filename);
            string fname   = Path.GetFileNameWithoutExtension(filename);

            if (string.IsNullOrEmpty(dirname) || string.IsNullOrEmpty(fname))
            {
                return(null);
            }
            string basename = Path.Combine(dirname, fname);

            if (!File.Exists(basename + ".idx"))
            {
                return(null);
            }
            string bing = File.ReadAllText(basename + ".idx");

            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();
                        s.Format       = "vobsub";
                        s.StreamType   = "3";
                        s.SubIndex     = x.ToString();
                        s.File         = basename + ".idx";
                        s.LanguageCode = SubtitleHelper.Iso639_1_TO_Iso639_3[language];
                        s.Language     = SubtitleHelper.Iso639_1_TO_Languages[language];
                        ss.Add(s);
                    }
                }
                x++;
            }
            return(ss);
        }
예제 #2
0
 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);
     FileSystemResult<IObject> r = file.FileSystem.Resolve(basename + ".idx");
     if (r == null || !r.IsOk || r.Result is IDirectory)
         return null;
     FileSystemResult<System.IO.Stream> res = ((IFile)r.Result).OpenRead();
     if (res == null || !res.IsOk)
         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();
                 s.Format = "vobsub";
                 s.StreamType = "3";
                 s.SubIndex = x.ToString();
                 s.File = basename + ".idx";
                 s.LanguageCode = SubtitleHelper.Iso639_1_TO_Iso639_3[language];
                 s.Language = SubtitleHelper.Iso639_1_TO_Languages[language];
                 ss.Add(s);
             }
         }
         x++;
     }
     return ss;
 }
예제 #3
0
        public List <Stream> GetStreams(string filename)
        {
            string ext = Path.GetExtension(filename);

            if (string.IsNullOrEmpty(ext))
            {
                return(null);
            }
            ext = ext.Replace(".", string.Empty).ToLower();
            string name = Path.GetFileNameWithoutExtension(filename);

            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;

            if ((ext == "txt") || (ext == "sub"))
            {
                string[] lines     = File.ReadAllLines(filename);
                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();

            s.Format       = format;
            s.StreamType   = "3";
            s.File         = filename;
            s.LanguageCode = SubtitleHelper.Iso639_1_TO_Iso639_3[language];
            s.Language     = SubtitleHelper.Iso639_1_TO_Languages[language];
            List <Stream> sts = new List <Stream>();

            sts.Add(s);
            return(sts);
        }
예제 #4
0
 public void AddSubtitle(JMMContracts.PlexAndKodi.Stream dict)
 {
     subtitles.Add(subtitles.Count + 1, dict);
 }
예제 #5
0
 public void AddVideo(JMMContracts.PlexAndKodi.Stream dict)
 {
     videos.Add(videos.Count + 1, dict);
 }
예제 #6
0
 public void AddAudio(JMMContracts.PlexAndKodi.Stream dict)
 {
     audios.Add(audios.Count + 1, dict);
 }
예제 #7
0
        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);
            FileSystemResult <IObject> r = file.FileSystem.Resolve(basename + ".idx");

            if (r == null || !r.IsOk || r.Result is IDirectory)
            {
                return(null);
            }
            FileSystemResult <System.IO.Stream> res = ((IFile)r.Result).OpenRead();

            if (res == null || !res.IsOk)
            {
                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();
                        s.Format       = "vobsub";
                        s.StreamType   = "3";
                        s.SubIndex     = x.ToString();
                        s.File         = basename + ".idx";
                        s.LanguageCode = SubtitleHelper.Iso639_1_TO_Iso639_3[language];
                        s.Language     = SubtitleHelper.Iso639_1_TO_Languages[language];
                        ss.Add(s);
                    }
                }
                x++;
            }
            return(ss);
        }