/// <summary> /// get caption path and create subtitle in the same plae as the decrypted video /// </summary> /// <param name="videoPath">Initial video path (.lynda file)</param> /// <param name="decryptedFilePath">Full decrypted video path</param> /// <returns>boolean value, true for succesful conversion</returns> private Boolean convertSub(string videoPath, string decryptedFilePath) { using (MD5 md5 = System.Security.Cryptography.MD5.Create()) { var videoId = Path.GetFileName(videoPath).Split('_')[0]; byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(videoId); byte[] hashBytes = md5.ComputeHash(inputBytes); // Convert the byte array to hexadecimal string StringBuilder sb = new StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("X2")); } var subFName = sb.ToString() + ".caption"; string captionFilePath = Path.Combine(Path.GetDirectoryName(videoPath), subFName); if (File.Exists(captionFilePath)) { var csConv = new CaptionToSrt(captionFilePath); var srtFile = Path.Combine(Path.GetDirectoryName(decryptedFilePath), Path.GetFileNameWithoutExtension(decryptedFilePath) + ".srt"); csConv.OutFile = srtFile; return(csConv.convertToSrt()); } else { return(false); } } }
/// <summary> /// get caption path and create subtitle in the same plae as the decrypted video /// </summary> /// <param name="videoPath">Initial video path (.lynda file)</param> /// <param name="decryptedFilePath">Full decrypted video path</param> /// <returns>boolean value, true for succesful conversion</returns> private Boolean ConvertSub(string videoPath, string decryptedFilePath, bool deleteSourceOnSuccess = false) { using (var md5 = MD5.Create()) { string videoId = Path.GetFileName(videoPath).Split('_')[0]; byte[] inputBytes = Encoding.ASCII.GetBytes(videoId); byte[] hashBytes = md5.ComputeHash(inputBytes); // Convert the byte array to hexadecimal string var sb = new StringBuilder(); for (int i = 0; i < hashBytes.Length; i++) { sb.Append(hashBytes[i].ToString("X2")); } string subFName = sb.ToString() + ".caption"; string captionFilePath = Path.Combine(Path.GetDirectoryName(videoPath), subFName); bool conversionSucceeded = false; if (File.Exists(captionFilePath)) { var csConv = new CaptionToSrt(captionFilePath); string srtFile = Path.Combine(Path.GetDirectoryName(decryptedFilePath), Path.GetFileNameWithoutExtension(decryptedFilePath) + ".srt"); csConv.OutFile = srtFile; conversionSucceeded = csConv.convertToSrt(); } if (conversionSucceeded && deleteSourceOnSuccess) { File.Delete(captionFilePath); } return(conversionSucceeded); } }