/// <summary> /// Generate snapshots for all episodes. /// </summary> public bool genSnapshots(WorkerVars workerVars, DialogProgress dialogProgress) { int progessCount = 0; int episodeCount = 0; int totalEpisodes = workerVars.CombinedAll.Count; int totalLines = UtilsSubs.getTotalLineCount(workerVars.CombinedAll); DateTime lastTime = UtilsSubs.getLastTime(workerVars.CombinedAll); UtilsName name = new UtilsName(Settings.Instance.DeckName, totalEpisodes, totalLines, lastTime, Settings.Instance.VideoClips.Size.Width, Settings.Instance.VideoClips.Size.Height); // For each episode foreach (List <InfoCombined> combArray in workerVars.CombinedAll) { episodeCount++; // For each line in episode, generate a snapshot foreach (InfoCombined t in combArray) { progessCount++; string progressText = $"Generating snapshot: {progessCount.ToString()} of {totalLines.ToString()}"; int progress = Convert.ToInt32(progessCount * (100.0 / totalLines)); // Update the progress dialog DialogProgress.updateProgressInvoke(dialogProgress, progress, progressText); InfoCombined comb = t; DateTime startTime = comb.Subs1.StartTime; DateTime endTime = comb.Subs1.EndTime; DateTime midTime = UtilsSubs.getMidpointTime(startTime, endTime); string videoFileName = Settings.Instance.VideoClips.Files[episodeCount - 1]; // Create output filename string nameStr = name.createName(ConstantSettings.SnapshotFilenameFormat, (int)episodeCount + Settings.Instance.EpisodeStartNumber - 1, progessCount, startTime, endTime, comb.Subs1.Text, comb.Subs2.Text); string outFile = $"{workerVars.MediaDir}{Path.DirectorySeparatorChar}{nameStr}"; // {2} // Generate snapshot UtilsSnapshot.takeSnapshotFromVideo(videoFileName, midTime, Settings.Instance.Snapshots.Size, Settings.Instance.Snapshots.Crop, outFile); // Did the user press the cancel button? if (dialogProgress.Cancel) { return(false); } } } return(true); }
/// <summary> /// Update the image preview. /// </summary> private void updateImagePreview(InfoCombined selectedComb) { if (selectedComb == null) { return; } // Update the snapshot if (Settings.Instance.VideoClips.Files.Length > 0 && checkBoxSnapshotPreview.Checked) { string videoFileName = Settings.Instance.VideoClips.Files[comboBoxEpisode.SelectedIndex]; DateTime midTime = UtilsSubs.getMidpointTime(selectedComb.Subs1.StartTime, selectedComb.Subs1.EndTime); string outFile = previewWorkerVars.MediaDir + Path.DirectorySeparatorChar + ConstantSettings.TempImageFilename; try { File.Delete(outFile); } catch { // File is locked return; } UtilsSnapshot.takeSnapshotFromVideo(videoFileName, midTime, Settings.Instance.Snapshots.Size, Settings.Instance.Snapshots.Crop, outFile); if (File.Exists(outFile)) { Image image = UtilsSnapshot.getImageFromFile(outFile); image = UtilsSnapshot.fitImageToSize(image, new Size(pictureBoxImage.Width, pictureBoxImage.Height)); pictureBoxImage.Image = image; } } }
/// <summary> /// Format a snapshot. /// </summary> private string formatSnapshot(InfoCombined comb, int episodeIndex) { DateTime startTime = comb.Subs1.StartTime; DateTime endTime = comb.Subs1.EndTime; DateTime midTime = UtilsSubs.getMidpointTime(comb.Subs1.StartTime, comb.Subs1.EndTime); string outText = ""; string prefixStr = name.createName(ConstantSettings.SrsSnapshotFilenamePrefix, episodeIndex + Settings.Instance.EpisodeStartNumber, progessCount, startTime, endTime, comb.Subs1.Text, comb.Subs2.Text); string nameStr = name.createName(ConstantSettings.SnapshotFilenameFormat, episodeIndex + Settings.Instance.EpisodeStartNumber, progessCount, startTime, endTime, comb.Subs1.Text, comb.Subs2.Text); string suffixStr = name.createName(ConstantSettings.SrsSnapshotFilenameSuffix, episodeIndex + Settings.Instance.EpisodeStartNumber, progessCount, startTime, endTime, comb.Subs1.Text, comb.Subs2.Text); outText = $"{prefixStr}{nameStr}{suffixStr}"; // {2} return(outText); }
/// <summary> /// Format tokens related to numbers that can have leading zeroes. Takes into account optional leading zeroes. /// </summary> private string formatNumberTokens(Match match) { int numZeroes = 0; bool numZeroesGiven = false; string token = ""; string zeroString = ""; string formatString = ""; string finalString = ""; int value = 0; DateTime diffTime = UtilsSubs.getDurationTime(startTime, endTime); DateTime midTime = UtilsSubs.getMidpointTime(startTime, endTime); // Get number of leading zeroes (if any) if (match.Groups[2].Success) { numZeroes = Int32.Parse(match.Groups[2].ToString()); numZeroesGiven = true; } // Get the token if (match.Groups[3].Success) { token = match.Groups[3].ToString(); } if (numZeroesGiven) { // Zero is special, it means use the minimum necassary number of leading zeroes based on some maximum (like the total number of lines) if (numZeroes == 0) { switch (token) { // Start times (use the end times) case "s_hour": numZeroes = 1; break; case "s_min": numZeroes = getMaxNecassaryLeadingZeroes(lastTime.TimeOfDay.Minutes); // 2; break; case "s_sec": case "s_hsec": numZeroes = 2; break; case "s_msec": numZeroes = 3; break; case "s_total_hour": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalHours); // 1 break; case "s_total_min": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalMinutes); // 3 break; case "s_total_sec": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalSeconds); // 4 break; case "s_total_hsec": numZeroes = getMaxNecassaryLeadingZeroes( (int)lastTime.TimeOfDay.TotalMilliseconds / 10); // 6 break; // End times case "s_total_msec": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalMilliseconds); // 7 break; case "e_hour": numZeroes = 1; break; case "e_min": numZeroes = getMaxNecassaryLeadingZeroes(lastTime.TimeOfDay.Minutes); // 2; break; case "e_sec": case "e_hsec": numZeroes = 2; break; case "e_msec": numZeroes = 3; break; case "e_total_hour": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalHours); // 1 break; case "e_total_min": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalMinutes); // 3 break; case "e_total_sec": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalSeconds); // 4 break; case "e_total_hsec": numZeroes = getMaxNecassaryLeadingZeroes( (int)lastTime.TimeOfDay.TotalMilliseconds / 10); // 6 break; // Duration times (use the end times) case "e_total_msec": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalMilliseconds); // 7 break; case "d_hour": numZeroes = 1; break; case "d_min": numZeroes = getMaxNecassaryLeadingZeroes(lastTime.TimeOfDay.Minutes); // 2; break; case "d_sec": case "d_hsec": numZeroes = 2; break; case "d_msec": numZeroes = 3; break; case "d_total_hour": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalHours); // 1 break; case "d_total_min": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalMinutes); // 3 break; case "d_total_sec": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalSeconds); // 4 break; case "d_total_hsec": numZeroes = getMaxNecassaryLeadingZeroes( (int)lastTime.TimeOfDay.TotalMilliseconds / 10); // 6 break; // Middle times (use the end times) case "d_total_msec": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalMilliseconds); // 7 break; case "m_hour": numZeroes = 1; break; case "m_min": numZeroes = getMaxNecassaryLeadingZeroes(lastTime.TimeOfDay.Minutes); // 2; break; case "m_sec": case "m_hsec": numZeroes = 2; break; case "m_msec": numZeroes = 3; break; case "m_total_hour": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalHours); // 1 break; case "m_total_min": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalMinutes); // 3 break; case "m_total_sec": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalSeconds); // 4 break; case "m_total_hsec": numZeroes = getMaxNecassaryLeadingZeroes( (int)lastTime.TimeOfDay.TotalMilliseconds / 10); // 6 break; // The rest case "m_total_msec": numZeroes = getMaxNecassaryLeadingZeroes((int)lastTime.TimeOfDay.TotalMilliseconds); // 7 break; case "episode_num": numZeroes = getMaxNecassaryLeadingZeroes(totalNumEpisodes); break; case "sequence_num": case "total_line_num": numZeroes = getMaxNecassaryLeadingZeroes(TotalNumLines); break; case "vobsub_stream_num": numZeroes = 1; break; } } // Limit the number of zeroes if (numZeroes > 9) { numZeroes = 9; } // Create a format string that can include leading zeroes if (numZeroes > 0) { zeroString += ":"; } for (int i = 0; i < numZeroes; i++) { zeroString += "0"; } } formatString = "{0" + zeroString + "}"; switch (token) { // Start times case "s_hour": value = startTime.TimeOfDay.Hours; break; case "s_min": value = startTime.TimeOfDay.Minutes; break; case "s_sec": value = startTime.TimeOfDay.Seconds; break; case "s_hsec": value = startTime.TimeOfDay.Milliseconds / 10; break; case "s_msec": value = startTime.TimeOfDay.Milliseconds; break; case "s_total_hour": value = (int)startTime.TimeOfDay.TotalHours; break; case "s_total_min": value = (int)startTime.TimeOfDay.TotalMinutes; break; case "s_total_sec": value = (int)startTime.TimeOfDay.TotalSeconds; break; case "s_total_hsec": value = (int)startTime.TimeOfDay.TotalMilliseconds / 10; break; // End times case "s_total_msec": value = (int)startTime.TimeOfDay.TotalMilliseconds; break; case "e_hour": value = endTime.TimeOfDay.Hours; break; case "e_min": value = endTime.TimeOfDay.Minutes; break; case "e_sec": value = endTime.TimeOfDay.Seconds; break; case "e_hsec": value = endTime.TimeOfDay.Milliseconds / 10; break; case "e_msec": value = endTime.TimeOfDay.Milliseconds; break; case "e_total_hour": value = (int)endTime.TimeOfDay.TotalHours; break; case "e_total_min": value = (int)endTime.TimeOfDay.TotalMinutes; break; case "e_total_sec": value = (int)endTime.TimeOfDay.TotalSeconds; break; case "e_total_hsec": value = (int)endTime.TimeOfDay.TotalMilliseconds / 10; break; // Duration times case "e_total_msec": value = (int)endTime.TimeOfDay.TotalMilliseconds; break; case "d_hour": value = diffTime.TimeOfDay.Hours; break; case "d_min": value = diffTime.TimeOfDay.Minutes; break; case "d_sec": value = diffTime.TimeOfDay.Seconds; break; case "d_hsec": value = diffTime.TimeOfDay.Milliseconds / 10; break; case "d_msec": value = diffTime.TimeOfDay.Milliseconds; break; case "d_total_hour": value = (int)diffTime.TimeOfDay.TotalHours; break; case "d_total_min": value = (int)diffTime.TimeOfDay.TotalMinutes; break; case "d_total_sec": value = (int)diffTime.TimeOfDay.TotalSeconds; break; case "d_total_hsec": value = (int)diffTime.TimeOfDay.TotalMilliseconds / 10; break; // Middle times case "d_total_msec": value = (int)diffTime.TimeOfDay.TotalMilliseconds; break; case "m_hour": value = midTime.TimeOfDay.Hours; break; case "m_min": value = midTime.TimeOfDay.Minutes; break; case "m_sec": value = midTime.TimeOfDay.Seconds; break; case "m_hsec": value = midTime.TimeOfDay.Milliseconds / 10; break; case "m_msec": value = midTime.TimeOfDay.Milliseconds; break; case "m_total_hour": value = (int)midTime.TimeOfDay.TotalHours; break; case "m_total_min": value = (int)midTime.TimeOfDay.TotalMinutes; break; case "m_total_sec": value = (int)midTime.TimeOfDay.TotalSeconds; break; case "m_total_hsec": value = (int)midTime.TimeOfDay.TotalMilliseconds / 10; break; // The rest case "m_total_msec": value = (int)midTime.TimeOfDay.TotalMilliseconds; break; case "episode_num": value = episodeNum; break; case "sequence_num": value = sequenceNum; break; case "total_line_num": value = TotalNumLines; break; case "vobsub_stream_num": value = vobsubStreamNum; break; } finalString = String.Format(formatString, value); return(finalString); }