Beispiel #1
0
        public List <Stream> Process(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);
            HashSet <string> extensions = new HashSet <string>(SubtitleHelper.Extensions.Keys);

            extensions.Remove("idx");
            List <Stream> streams = new List <Stream>();

            foreach (string n in extensions)
            {
                string newname = basename + "." + n;
                if (File.Exists(newname))
                {
                    List <Stream> ss = GetStreams(newname);
                    if ((ss != null) && (ss.Count > 0))
                    {
                        streams.AddRange(ss);
                    }
                }
            }
            return(streams);
        }
        /// <summary>
        /// Write transcript for the clip if it available.
        /// </summary>
        /// <param name="clipId">Clip Id</param>
        /// <param name="clipPath">Path of current clip</param>
        public void WriteTranscriptFile(Clip clipId, string clipPath)
        {
            // Get all transcript to list
            List <ClipTranscript> clipTranscripts = clipId.Subtitle;

            if (clipTranscripts.Count > 0)
            {
                // Create transcript path with the same name of the clip
                string transcriptPath = Path.Combine(Path.GetDirectoryName(clipPath),
                                                     Path.GetFileNameWithoutExtension(clipPath) + ".srt");
                if (!File.Exists(transcriptPath))
                {
                    using (FileStream transcriptStream = File.OpenWrite(transcriptPath))
                    {
                        using (StreamWriter writer = new StreamWriter(transcriptStream))
                        {
                            // Write it to file with stream writer
                            int i = 1;
                            foreach (var clipTranscript in clipTranscripts)
                            {
                                var start = TimeSpan.FromMilliseconds(clipTranscript.StartTime).ToString(@"hh\:mm\:ss\,fff");
                                var end   = TimeSpan.FromMilliseconds(clipTranscript.EndTime).ToString(@"hh\:mm\:ss\,fff");
                                writer.WriteLine(i++);
                                writer.WriteLine(start + " --> " + end);
                                writer.WriteLine(clipTranscript.Text);
                                writer.WriteLine();
                            }
                        }
                    }
                    bgwDecrypt.ReportProgress(1, new { Text = $"Transcript of {Path.GetFileName(clipPath)} generated.", Color = Color.Purple, newLine = false });
                }
            }
        }
Beispiel #3
0
        public List <Stream> Process(SVR_VideoLocal_Place vplace)
        {
            string dirname = Path.GetDirectoryName(vplace.FullServerPath);
            string fname   = Path.GetFileNameWithoutExtension(vplace.FilePath);

            if (string.IsNullOrEmpty(dirname) || string.IsNullOrEmpty(fname))
            {
                return(null);
            }
            string           basename   = Path.Combine(dirname, fname);
            HashSet <string> extensions = new HashSet <string>(SubtitleHelper.Extensions.Keys);

            extensions.Remove("idx");
            List <Stream> streams = new List <Stream>();

            foreach (string n in extensions)
            {
                string newname = basename + "." + n;
                FileSystemResult <IObject> r = vplace.ImportFolder.FileSystem.Resolve(newname);
                if (r != null && r.IsOk && r.Result is IFile)
                {
                    List <Stream> ss = GetStreams((IFile)r.Result);
                    if ((ss != null) && (ss.Count > 0))
                    {
                        streams.AddRange(ss);
                    }
                }
            }
            return(streams);
        }
        public static void RenameFileExtension(string iPath, string src, string dest)
        {
            if (!Directory.Exists(iPath))
            {
                return;
            }

            // rename subDir
            string[] dirPaths = Directory.GetDirectories(iPath);
            for (int i = 0; i < dirPaths.Length; i++)
            {
                RenameFileExtension(dirPaths[i], src, dest);
            }

            // rename files
            string[] filePaths = Directory.GetFiles(iPath);
            for (int i = 0; i < filePaths.Length; ++i)
            {
                string extension = Path.GetExtension(filePaths[i]);
                if (extension == src)
                {
                    string dir      = Path.GetDirectoryName(filePaths[i]);
                    string name     = Path.GetFileNameWithoutExtension(filePaths[i]);
                    string destFile = dir + name + dest;

                    MoveWithReplace(filePaths[i], destFile);
                }
            }
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public List <Stream> Process(SVR_VideoLocal_Place vplace)
        {
            string dirname = Path.GetDirectoryName(vplace.FullServerPath);
            string fname   = Path.GetFileNameWithoutExtension(vplace.FilePath);

            if (string.IsNullOrEmpty(dirname) || string.IsNullOrEmpty(fname))
            {
                return(null);
            }
            string        basename = Path.Combine(dirname, fname);
            List <Stream> streams  = new List <Stream>();

            if (File.Exists(basename + ".idx") && File.Exists(basename + ".sub"))
            {
                FileSystemResult <IObject> r = vplace.ImportFolder.FileSystem.Resolve(basename + ".sub");
                if (r != null && r.IsOk && r.Result is IFile)
                {
                    List <Stream> ss = GetStreams((IFile)r.Result);
                    if ((ss != null) && (ss.Count > 0))
                    {
                        streams.AddRange(ss);
                    }
                }
            }
            return(streams);
        }
Beispiel #7
0
        public static void ProcessIsos()
        {
            var files = Directory.EnumerateFiles(Paths.OutputPath, "*.iso", SearchOption.AllDirectories).Concat(Directory.EnumerateFiles(Paths.OutputPath, "*.bin", SearchOption.AllDirectories));

            //var files = Directory.EnumerateFiles(Paths.OutputPath, "*.bin", SearchOption.AllDirectories);
            foreach (var file in files)
            {
                Console.WriteLine("Mounting {0} => D:", file);
                if (StartProcess(@"C:\Program Files\PowerISO\piso.exe", $"mount \"{file}\" D:") >= 0)
                {
                    var destPath = Path.GetDirectoryName(file) + @"\" + Path.GetFileNameWithoutExtension(file) + @"\";
                    CopyFiles("D:", destPath, false);
                }
            }
        }
Beispiel #8
0
        public static List <string> GetPossibleSubtitleFiles(string fileName)
        {
            List <string> subtileFiles = new List <string>();

            subtileFiles.Add(Path.Combine(Path.GetDirectoryName(fileName),
                                          Path.GetFileNameWithoutExtension(fileName) + ".srt"));
            subtileFiles.Add(Path.Combine(Path.GetDirectoryName(fileName),
                                          Path.GetFileNameWithoutExtension(fileName) + ".ass"));
            subtileFiles.Add(Path.Combine(Path.GetDirectoryName(fileName),
                                          Path.GetFileNameWithoutExtension(fileName) + ".ssa"));
            subtileFiles.Add(Path.Combine(Path.GetDirectoryName(fileName),
                                          Path.GetFileNameWithoutExtension(fileName) + ".idx"));
            subtileFiles.Add(Path.Combine(Path.GetDirectoryName(fileName),
                                          Path.GetFileNameWithoutExtension(fileName) + ".sub"));

            return(subtileFiles);
        }
Beispiel #9
0
        public List <Stream> Process(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);
            List <Stream> streams  = new List <Stream>();

            if (File.Exists(basename + ".idx") && File.Exists(basename + ".sub"))
            {
                List <Stream> ss = GetStreams(basename + ".sub");
                if ((ss != null) && (ss.Count > 0))
                {
                    streams.AddRange(ss);
                }
            }
            return(streams);
        }
Beispiel #10
0
        public void TestGetFileNameWithoutExtension()
        {
            var filename = Path.Combine(longPathDirectory, "filename.ext");

            Assert.AreEqual("filename", Path.GetFileNameWithoutExtension(filename));
        }
Beispiel #11
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);
        }
Beispiel #12
0
        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 == null || !res.IsOk)
                {
                    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);
        }
Beispiel #13
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
                        {
                            Format       = "vobsub",
                            StreamType   = "3",
                            SubIndex     = x.ToString(),
                            File         = basename + ".idx",
                            LanguageCode = SubtitleHelper.Iso639_1_TO_Iso639_3[language],
                            Language     = SubtitleHelper.Iso639_1_TO_Languages[language]
                        };
                        ss.Add(s);
                    }
                }
                x++;
            }
            return(ss);
        }
Beispiel #14
0
 public static string GetFileNameWithoutExtension(string path)
 {
     return(Path.GetFileNameWithoutExtension(path));
 }