Exemplo n.º 1
0
        public void DecryptAllVideos(string folderPath, Module module, string outputPath)
        {
            // Get all clips of this module from database
            List <Clip> listClips = module.Clips;

            if (listClips.Count > 0)
            {
                foreach (Clip clip in listClips)
                {
                    // Get current path of the encrypted video
                    string currPath = Path.Combine(folderPath, clip.ClipName + ".psv");
                    if (File.Exists(currPath))
                    {
                        // Create new path with output folder
                        string newPath = Path.Combine(outputPath,
                                                      clip.ClipIndex + ". " + clip.ClipTitle + ".mp4");



                        // If length too long, rename it
                        if (newPath.Length > 240)
                        {
                            newPath = Path.Combine(outputPath,
                                                   clip.ClipIndex + ".mp4");
                        }

                        // Init video and get it from istream
                        IStream iStream;
                        var     playingFileStream = new VirtualFileStream(currPath);
                        playingFileStream.Clone(out iStream);

                        string fileName = Path.GetFileName(currPath);

                        //this.AddText($"Start to Decrypt File \"{fileName}\"", Color.Yellow);
                        bgwDecrypt.ReportProgress(1, new { Text = $"Start to Decrypt File \"{fileName}\"", Color = Color.Yellow, newLine = false });

                        this.DecryptVideo(iStream, newPath);
                        if (chkCreateSub.Checked)
                        {
                            // Generate transcript file if user ask
                            this.WriteTranscriptFile(clip, newPath);
                        }

                        //this.AddText($"Decryption File \"{Path.GetFileName(newPath)}\" successfully", Color.Green, true);
                        bgwDecrypt.ReportProgress(1, new { Text = $"Decryption File \"{Path.GetFileName(newPath)}\" successfully", Color = Color.Green, newLine = true });
                        playingFileStream.Dispose();
                    }
                    else
                    {
                        //this.AddText($"File \"{Path.GetFileName(currPath)}\"  cannot be found ", Color.Gray, true);
                        bgwDecrypt.ReportProgress(1, new { Text = $"File \"{Path.GetFileName(currPath)}\"  cannot be found", Color = Color.Gray, newLine = true });
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decrypt all videos in current module folder.
        /// </summary>
        /// <param name="folderPath">Current module folder</param>
        /// <param name="moduleId">Module Id</param>
        /// <param name="outputPath">Destination of output video</param>
        public void DecryptAllVideos(string folderPath, Module module, string outputPath)
        {
            // Get all clips of this module from database
            List <Clip> listClips = module.Clips;

            if (listClips.Count > 0)
            {
                foreach (Clip clip in listClips)
                {
                    // Get current path of the encrypted video
                    string currPath = Path.Combine(folderPath, clip.ClipName + ".psv");
                    if (File.Exists(currPath))
                    {
                        // Create new path with output folder
                        string newPath = Path.Combine(outputPath,
                                                      clip.ClipIndex + ". " + clip.ClipTitle + ".mp4");



                        // If length too long, rename it
                        if (newPath.Length > 240)
                        {
                            newPath = Path.Combine(outputPath,
                                                   clip.ClipIndex + ".mp4");
                        }

                        // Init video and get it from istream
                        IStream iStream;
                        var     playingFileStream = new VirtualFileStream(currPath);
                        playingFileStream.Clone(out iStream);

                        string fileName = Path.GetFileName(currPath);

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("Start to Decrypt File \"{0}\"", fileName);
                        Console.ForegroundColor = color_default;

                        DecryptVideo(iStream, newPath);
                        if (Options.CreateTranscript)
                        {
                            // Generate transcript file if user ask
                            WriteTranscriptFile(clip, newPath);
                        }
                        //Semaphore.Wait();
                        //TaskList.Add(Task.Run(() =>
                        //{
                        //    // Write the decrypted video from istream to new file mp4
                        //    DecryptVideo(iStream, newPath);
                        //    if (Options.CreateTranscript)
                        //    {
                        //        // Generate transcript file if user ask
                        //        WriteTranscriptFile(clip, newPath);
                        //    }
                        //    lock (SemaphoreLock)
                        //    {
                        //        Semaphore.Release();
                        //    }
                        //}));

                        WriteToConsole($"Decryption File \"{Path.GetFileName(newPath)}\" successfully ", ConsoleColor.Green, true);
                        playingFileStream.Dispose();
                    }
                    else
                    {
                        WriteToConsole($"File \"{Path.GetFileName(currPath)}\"  cannot be found ", ConsoleColor.Gray, true);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void DecryptAllVideos(string folderPath, int moduleId, string outputPath, bool isCreateTranscript, bool ignoreException = true)
        {
            var clipsRepository = databaseSQLiteConnection.Connect().GetClipsRepository();
            var listClips       = clipsRepository.GetClipsFromDb(moduleId);

            databaseSQLiteConnection.Disconnect();

            if (listClips.Count > 0)
            {
                foreach (Clip clip in listClips)
                {
                    try
                    {
                        var currPath = Path.Combine(folderPath, clip.ClipName + ".psv");
                        if (File.Exists(currPath))
                        {
                            var newPath = Path.Combine(outputPath, clip.ClipIndex + ". " + clip.ClipTitle.CleanPath(this.InvalidPathCharacters) + ".mp4");

                            // If length too long, rename it
                            if (newPath.Length > 240)
                            {
                                newPath = Path.Combine(outputPath, clip.ClipIndex + ".mp4");
                            }

                            //newPath = newPath.EscapeIllegalCharacters();

                            playingFileStream = new VirtualFileStream(currPath);
                            playingFileStream.Clone(out iStream);

                            var fileName = Path.GetFileName(currPath);
                            Logger.Info($"Start to Decrypt File {fileName}");

                            Semaphore.Wait();
                            TaskList.Add(Task.Run(() =>
                            {
                                DecryptVideo(iStream, newPath);
                                if (isCreateTranscript)
                                {
                                    WriteTranscriptFile(clip.ClipId, newPath);
                                }
                                lock (SemaphoreLock)
                                {
                                    Semaphore.Release();
                                }
                            }));

                            Logger.Info($"Decryption File { Path.GetFileName(newPath) } successfully");
                        }
                        else
                        {
                            if (!ignoreException)
                            {
                                throw new Exception($"File { Path.GetFileName(currPath) } cannot be found.");
                            }
                            Logger.ErrorFormat($"File {Path.GetFileName(currPath)} cannot be found.");
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!ignoreException)
                        {
                            throw new Exception($"Cannot decrypt clip. {ex}");
                        }
                    }
                }
            }
        }