2 using System.Collections.Generic;
\r
4 using System.Windows.Forms;
\r
5 using System.Globalization;
\r
7 using System.Drawing;
\r
9 namespace Handbrake.Functions
\r
14 * Checks for updates and returns "true" boolean if one exists.
\r
16 public Boolean updateCheck()
\r
20 Functions.RssReader rssRead = new Functions.RssReader();
\r
21 string build = rssRead.build();
\r
23 int latest = int.Parse(build);
\r
24 int current = Properties.Settings.Default.hb_build;
\r
25 int skip = Properties.Settings.Default.skipversion;
\r
33 Boolean update = (latest > current);
\r
37 catch (Exception exc)
\r
39 MessageBox.Show(exc.ToString());
\r
45 * Function which generates the filename and path automatically based on the Source Name, DVD title and DVD Chapters
\r
47 public void autoName(frmMain mainWindow)
\r
49 if (Properties.Settings.Default.autoNaming == "Checked")
\r
51 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
53 string source = mainWindow.text_source.Text;
\r
54 string[] sourceName = source.Split('\\');
\r
55 source = sourceName[sourceName.Length - 1].Replace(".iso", "").Replace(".mpg", "").Replace(".ts", "").Replace(".ps", "");
\r
57 string title = mainWindow.drp_dvdtitle.Text;
\r
58 string[] titlesplit = title.Split(' ');
\r
59 title = titlesplit[0];
\r
61 string cs = mainWindow.drop_chapterStart.Text;
\r
62 string cf = mainWindow.drop_chapterFinish.Text;
\r
64 if (title == "Automatic")
\r
75 if (!mainWindow.text_destination.Text.Contains("\\"))
\r
77 string filePath = "";
\r
78 if (Properties.Settings.Default.autoNamePath.Trim() != "")
\r
79 filePath = Properties.Settings.Default.autoNamePath + "\\";
\r
80 mainWindow.text_destination.Text = filePath + source + "_T" + title + "_C" + cs + dash + cf + ".mp4";
\r
84 string dest = mainWindow.text_destination.Text;
\r
86 string[] destName = dest.Split('\\');
\r
89 string[] extension = dest.Split('.');
\r
90 string ext = extension[extension.Length - 1];
\r
92 destName[destName.Length - 1] = source + "_T" + title + "_C" + cs + dash + cf + "." + ext;
\r
94 string fullDest = "";
\r
95 foreach (string part in destName)
\r
98 fullDest = fullDest + "\\" + part;
\r
100 fullDest = fullDest + part;
\r
103 mainWindow.text_destination.Text = fullDest;
\r
110 * This function takes in a Query which has been parsed by QueryParser and sets up the GUI.
\r
112 public void presetLoader(frmMain mainWindow, Functions.QueryParser presetQuery, string name)
\r
114 // ---------------------------
\r
116 // ---------------------------
\r
120 if (presetQuery.Source != "")
\r
121 mainWindow.text_source.Text = presetQuery.Source;
\r
123 if (presetQuery.DVDTitle != 0)
\r
124 mainWindow.drp_dvdtitle.Text = presetQuery.DVDTitle.ToString();
\r
126 if (presetQuery.DVDChapterStart != 0)
\r
127 mainWindow.drop_chapterStart.Text = presetQuery.DVDChapterStart.ToString();
\r
129 if (presetQuery.DVDChapterFinish != 0)
\r
130 mainWindow.drop_chapterFinish.Text = presetQuery.DVDChapterFinish.ToString();
\r
132 if (presetQuery.Format != "")
\r
134 string destination = mainWindow.text_destination.Text;
\r
135 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
136 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
137 destination = destination.Replace(".avi", "." + presetQuery.Format);
\r
138 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
139 destination = destination.Replace(".ogm", "." + presetQuery.Format);
\r
140 mainWindow.text_destination.Text = destination;
\r
146 #region destination
\r
148 if (presetQuery.Destination != "")
\r
149 mainWindow.text_destination.Text = presetQuery.Destination;
\r
151 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
152 mainWindow.drp_audioCodec.Text = presetQuery.AudioEncoder;
\r
156 // Picture Settings Tab
\r
158 mainWindow.drp_crop.Text = "Manual";
\r
159 mainWindow.text_top.Text = presetQuery.CropTop;
\r
160 mainWindow.text_bottom.Text = presetQuery.CropBottom;
\r
161 mainWindow.text_left.Text = presetQuery.CropLeft;
\r
162 mainWindow.text_right.Text = presetQuery.CropRight;
\r
164 mainWindow.drp_deInterlace_option.Text = presetQuery.DeInterlace;
\r
165 mainWindow.drp_deNoise.Text = presetQuery.DeNoise;
\r
167 if (presetQuery.DeTelecine == true)
\r
168 mainWindow.check_detelecine.CheckState = CheckState.Checked;
\r
170 mainWindow.check_detelecine.CheckState = CheckState.Unchecked;
\r
173 if (presetQuery.DeBlock == true)
\r
174 mainWindow.check_deblock.CheckState = CheckState.Checked;
\r
176 mainWindow.check_deblock.CheckState = CheckState.Unchecked;
\r
178 if (presetQuery.ChapterMarkers == true)
\r
179 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
181 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
183 if (presetQuery.Anamorphic == true)
\r
184 mainWindow.CheckPixelRatio.CheckState = CheckState.Checked;
\r
186 mainWindow.CheckPixelRatio.CheckState = CheckState.Unchecked;
\r
188 if (presetQuery.LooseAnamorphic == true)
\r
189 mainWindow.check_lAnamorphic.CheckState = CheckState.Checked;
\r
191 mainWindow.check_lAnamorphic.CheckState = CheckState.Unchecked;
\r
193 if (presetQuery.Width != 0)
\r
194 mainWindow.text_width.Text = presetQuery.Width.ToString();
\r
197 mainWindow.text_width.Text = "";
\r
198 mainWindow.text_width.BackColor = Color.White;
\r
201 if (presetQuery.Height != 0)
\r
202 mainWindow.text_height.Text = presetQuery.Height.ToString();
\r
205 mainWindow.text_height.Text = "";
\r
206 mainWindow.text_height.BackColor = Color.White;
\r
209 if (presetQuery.VFR == true)
\r
210 mainWindow.check_vfr.CheckState = CheckState.Checked;
\r
212 mainWindow.check_vfr.CheckState = CheckState.Unchecked;
\r
215 // Video Settings Tab
\r
217 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
218 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
219 mainWindow.slider_videoQuality.Value = presetQuery.VideoQuality;
\r
220 if (mainWindow.slider_videoQuality.Value != 0)
\r
222 int ql = presetQuery.VideoQuality;
\r
223 mainWindow.SliderValue.Text = ql.ToString() + "%";
\r
226 if (presetQuery.TwoPass == true)
\r
227 mainWindow.check_2PassEncode.CheckState = CheckState.Checked;
\r
229 mainWindow.check_2PassEncode.CheckState = CheckState.Unchecked;
\r
231 if (presetQuery.Grayscale == true)
\r
232 mainWindow.check_grayscale.CheckState = CheckState.Checked;
\r
234 mainWindow.check_grayscale.CheckState = CheckState.Unchecked;
\r
236 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
238 if (presetQuery.TurboFirstPass == true)
\r
239 mainWindow.check_turbo.CheckState = CheckState.Checked;
\r
241 mainWindow.check_turbo.CheckState = CheckState.Unchecked;
\r
243 if (presetQuery.LargeMP4 == true)
\r
244 mainWindow.check_largeFile.CheckState = CheckState.Checked;
\r
246 mainWindow.check_largeFile.CheckState = CheckState.Unchecked;
\r
248 if (presetQuery.IpodAtom == true)
\r
249 mainWindow.check_iPodAtom.CheckState = CheckState.Checked;
\r
251 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
253 if (presetQuery.OptimizeMP4 == true)
\r
254 mainWindow.check_optimiseMP4.CheckState = CheckState.Checked;
\r
256 mainWindow.check_optimiseMP4.CheckState = CheckState.Unchecked;
\r
260 // Audio Settings Tab
\r
262 mainWindow.drp_audioBitrate.Text = presetQuery.AudioBitrate;
\r
263 mainWindow.drp_audioSampleRate.Text = presetQuery.AudioSampleBitrate;
\r
264 mainWindow.drp_track1Audio.Text = presetQuery.AudioTrack1;
\r
265 mainWindow.drp_track2Audio.Text = presetQuery.AudioTrack2;
\r
266 mainWindow.drp_audioMixDown.Text = presetQuery.AudioTrackMix;
\r
267 mainWindow.drp_subtitle.Text = presetQuery.Subtitles;
\r
269 if (presetQuery.ForcedSubtitles == true)
\r
271 mainWindow.check_forced.CheckState = CheckState.Checked;
\r
272 mainWindow.check_forced.Enabled = true;
\r
275 mainWindow.check_forced.CheckState = CheckState.Unchecked;
\r
277 // Dynamic Range Compression (Should be a float but we use double for ease)
\r
278 double value = presetQuery.DRC;
\r
280 value = value - 10;
\r
281 mainWindow.slider_drc.Value = int.Parse(value.ToString());
\r
283 double actualValue = presetQuery.DRC / 10;
\r
284 mainWindow.lbl_drc.Text = actualValue.ToString();
\r
289 // H264 Tab & Preset Name
\r
291 mainWindow.rtf_h264advanced.Text = presetQuery.H264Query;
\r
293 // Set the preset name
\r
294 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r
299 * This takes all the widgets on frmMain
\r
301 public string GenerateTheQuery(frmMain mainWindow)
\r
306 string source = mainWindow.text_source.Text;
\r
307 string dvdTitle = mainWindow.drp_dvdtitle.Text;
\r
308 string chapterStart = mainWindow.drop_chapterStart.Text;
\r
309 string chapterFinish = mainWindow.drop_chapterFinish.Text;
\r
310 int totalChapters = mainWindow.drop_chapterFinish.Items.Count - 1;
\r
311 string dvdChapter = "";
\r
313 if ((source != "") || (source != "Click 'Browse' to continue"))
\r
314 source = " -i " + '"' + source + '"';
\r
316 if (dvdTitle == "Automatic")
\r
320 string[] titleInfo = dvdTitle.Split(' ');
\r
321 dvdTitle = " -t " + titleInfo[0];
\r
324 if (chapterFinish.Equals("Auto") && chapterStart.Equals("Auto"))
\r
326 else if (chapterFinish == chapterStart)
\r
327 dvdChapter = " -c " + chapterStart;
\r
329 dvdChapter = " -c " + chapterStart + "-" + chapterFinish;
\r
331 string querySource = source + dvdTitle + dvdChapter;
\r
335 #region Destination
\r
337 string destination = mainWindow.text_destination.Text;
\r
338 string videoEncoder = mainWindow.drp_videoEncoder.Text;
\r
339 string audioEncoder = mainWindow.drp_audioCodec.Text;
\r
340 string width = mainWindow.text_width.Text;
\r
341 string height = mainWindow.text_height.Text;
\r
343 if (destination != "")
\r
344 destination = " -o " + '"' + destination + '"'; //'"'+
\r
347 switch (videoEncoder)
\r
350 videoEncoder = " -e ffmpeg";
\r
353 videoEncoder = " -e xvid";
\r
356 videoEncoder = " -e x264";
\r
358 case "H.264 (iPod)":
\r
359 videoEncoder = " -e x264b30";
\r
362 videoEncoder = " -e x264";
\r
366 switch (audioEncoder)
\r
369 audioEncoder = " -E faac";
\r
372 audioEncoder = " -E lame";
\r
375 audioEncoder = " -E vorbis";
\r
378 audioEncoder = " -E ac3";
\r
381 audioEncoder = " -E faac";
\r
386 width = " -w " + width;
\r
389 if (height == "Auto")
\r
393 else if (height != "")
\r
395 height = " -l " + height;
\r
399 string queryDestination = destination + videoEncoder + audioEncoder + width + height;
\r
402 // Picture Settings Tab
\r
403 #region Picture Settings Tab
\r
405 string cropSetting = mainWindow.drp_crop.Text;
\r
406 string cropTop = mainWindow.text_top.Text;
\r
407 string cropBottom = mainWindow.text_bottom.Text;
\r
408 string cropLeft = mainWindow.text_left.Text;
\r
409 string cropRight = mainWindow.text_right.Text;
\r
410 string cropOut = "";
\r
411 string deInterlace_Option = mainWindow.drp_deInterlace_option.Text;
\r
412 string deinterlace = "";
\r
413 string grayscale = "";
\r
414 string pixelRatio = "";
\r
416 string deblock = "";
\r
417 string detelecine = "";
\r
418 string lanamorphic = "";
\r
422 if (cropSetting == "Automatic")
\r
424 else if (cropSetting == "No Crop")
\r
425 cropOut = " --crop 0:0:0:0 ";
\r
428 if (mainWindow.text_top.Text == "")
\r
430 if (mainWindow.text_bottom.Text == "")
\r
432 if (mainWindow.text_left.Text == "")
\r
434 if (mainWindow.text_right.Text == "")
\r
437 cropOut = " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;
\r
440 switch (deInterlace_Option)
\r
446 deinterlace = " --deinterlace=fast";
\r
449 deinterlace = " --deinterlace=slow";
\r
452 deinterlace = " --deinterlace=slower";
\r
455 deinterlace = " --deinterlace=slowest";
\r
462 if (mainWindow.check_grayscale.Checked)
\r
463 grayscale = " -g ";
\r
465 if (mainWindow.CheckPixelRatio.Checked)
\r
466 pixelRatio = " -p ";
\r
468 if (mainWindow.check_deblock.Checked)
\r
469 deblock = " --deblock";
\r
471 if (mainWindow.check_detelecine.Checked)
\r
472 detelecine = " --detelecine";
\r
474 if (mainWindow.check_vfr.Checked)
\r
477 if (mainWindow.check_lAnamorphic.Checked)
\r
478 lanamorphic = " -P ";
\r
480 string queryPictureSettings = cropOut + deinterlace + deblock + detelecine + vfr + grayscale + pixelRatio + lanamorphic;
\r
483 // Video Settings Tab
\r
484 #region Video Settings Tab
\r
486 string videoBitrate = mainWindow.text_bitrate.Text;
\r
487 string videoFilesize = mainWindow.text_filesize.Text;
\r
488 double videoQuality = mainWindow.slider_videoQuality.Value;
\r
489 string vidQSetting = "";
\r
490 string twoPassEncoding = "";
\r
491 string videoFramerate = mainWindow.drp_videoFramerate.Text;
\r
492 string turboH264 = "";
\r
493 string largeFile = "";
\r
494 string denoise = "";
\r
495 string ipodAtom = "";
\r
496 string optimizeMP4 = "";
\r
498 if (videoBitrate != "")
\r
499 videoBitrate = " -b " + videoBitrate;
\r
501 if (videoFilesize != "")
\r
502 videoFilesize = " -S " + videoFilesize;
\r
504 // Video Quality Setting
\r
506 if ((videoQuality == 0))
\r
510 videoQuality = videoQuality / 100;
\r
511 if (videoQuality == 1)
\r
513 vidQSetting = "1.0";
\r
515 vidQSetting = " -q " + videoQuality.ToString(new CultureInfo("en-US"));
\r
518 if (mainWindow.check_2PassEncode.Checked)
\r
519 twoPassEncoding = " -2 ";
\r
521 if (videoFramerate == "Automatic")
\r
522 videoFramerate = "";
\r
524 videoFramerate = " -r " + videoFramerate;
\r
526 if (mainWindow.check_turbo.Checked)
\r
527 turboH264 = " -T ";
\r
529 if (mainWindow.check_largeFile.Checked)
\r
530 largeFile = " -4 ";
\r
533 switch (mainWindow.drp_deNoise.Text)
\r
539 denoise = " --denoise=weak";
\r
542 denoise = " --denoise=medium";
\r
545 denoise = " --denoise=strong";
\r
552 if (mainWindow.check_iPodAtom.Checked)
\r
555 if (mainWindow.check_optimiseMP4.Checked)
\r
556 optimizeMP4 = " -O ";
\r
559 string queryVideoSettings = videoBitrate + videoFilesize + vidQSetting + twoPassEncoding + videoFramerate + turboH264 + ipodAtom + optimizeMP4 + largeFile + denoise;
\r
562 // Audio Settings Tab
\r
563 #region Audio Settings Tab
\r
565 string audioBitrate = mainWindow.drp_audioBitrate.Text;
\r
566 string audioSampleRate = mainWindow.drp_audioSampleRate.Text;
\r
567 string track1 = mainWindow.drp_track1Audio.Text;
\r
568 string track2 = mainWindow.drp_track2Audio.Text;
\r
569 string audioChannels = "";
\r
570 string Mixdown = mainWindow.drp_audioMixDown.Text;
\r
571 string SixChannelAudio = "";
\r
572 string subtitles = mainWindow.drp_subtitle.Text;
\r
573 string subScan = "";
\r
574 string forced = "";
\r
577 if (audioBitrate != "")
\r
578 audioBitrate = " -B " + audioBitrate;
\r
580 if (audioSampleRate != "")
\r
581 audioSampleRate = " -R " + audioSampleRate;
\r
584 if (track1 == "Automatic")
\r
585 audioChannels = "";
\r
586 else if (track1 == "")
\r
587 audioChannels = "";
\r
588 else if (track1 == "None")
\r
589 audioChannels = " -a none";
\r
593 tempSub = track1.Split(' ');
\r
594 audioChannels = " -a " + tempSub[0];
\r
598 if (audioChannels != "")
\r
600 if ((track2 != "") && (track2 != "None"))
\r
603 tempSub = track2.Split(' ');
\r
604 audioChannels = audioChannels + "," + tempSub[0];
\r
609 if ((track2 != "") && (track2 != "None"))
\r
612 tempSub = track2.Split(' ');
\r
613 audioChannels = " -a " + tempSub[0];
\r
628 Mixdown = "stereo";
\r
630 case "Dolby Surround":
\r
633 case "Dolby Pro Logic II":
\r
636 case "6 Channel Discrete":
\r
645 SixChannelAudio = " -6 " + Mixdown;
\r
647 SixChannelAudio = "";
\r
649 if (subtitles == "None")
\r
651 else if (subtitles == "")
\r
653 else if (subtitles == "Autoselect")
\r
661 tempSub = subtitles.Split(' ');
\r
662 subtitles = " -s " + tempSub[0];
\r
665 if (mainWindow.check_forced.Checked)
\r
668 //Dynamic Range Compression (expects a float but a double is used for ease)
\r
669 double value = mainWindow.slider_drc.Value / 10.0;
\r
671 drc = " -D " + value;
\r
673 string queryAudioSettings = audioBitrate + audioSampleRate + drc + audioChannels + SixChannelAudio + subScan + subtitles + forced;
\r
676 // Chapter Markers Tab
\r
677 #region Chapter Markers
\r
679 string ChapterMarkers = "";
\r
681 if (mainWindow.Check_ChapterMarkers.Checked)
\r
683 Boolean saveCSV = chapterCSVSave(mainWindow);
\r
684 if (saveCSV == false)
\r
686 MessageBox.Show("Unable to save Chapter Makrers file! \n Chapter marker names will NOT be saved in your encode \n\n", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
687 ChapterMarkers = " -m ";
\r
691 string path = Application.StartupPath.ToString();
\r
692 path = "\"" + path + "\\chapters.csv\" ";
\r
694 ChapterMarkers = " --markers=" + path;
\r
698 string chapter_markers = ChapterMarkers;
\r
704 string h264Advanced = mainWindow.rtf_h264advanced.Text;
\r
706 if ((h264Advanced == ""))
\r
709 h264Advanced = " -x " + h264Advanced;
\r
712 string h264Settings = h264Advanced;
\r
716 #region Processors / Other
\r
718 string processors = Properties.Settings.Default.Processors;
\r
719 // Number of Processors Handler
\r
721 if (processors == "Automatic")
\r
724 processors = " -C " + processors + " ";
\r
727 string queryAdvancedSettings = processors;
\r
729 string verbose = "";
\r
730 if (Properties.Settings.Default.verbose == "Checked")
\r
734 return querySource + queryDestination + queryPictureSettings + queryVideoSettings + h264Settings + queryAudioSettings + ChapterMarkers + queryAdvancedSettings + verbose;
\r
738 * Set's up the DataGridView on the Chapters tab (frmMain)
\r
740 public void chapterNaming(frmMain mainWindow)
\r
744 mainWindow.data_chpt.Rows.Clear();
\r
749 if (mainWindow.drop_chapterFinish.Text != "Auto")
\r
750 finish = int.Parse(mainWindow.drop_chapterFinish.Text);
\r
752 if (mainWindow.drop_chapterStart.Text != "Auto")
\r
753 start = int.Parse(mainWindow.drop_chapterStart.Text);
\r
755 rowCount = finish - (start - 1);
\r
757 while (i < rowCount)
\r
759 DataGridViewRow row = new DataGridViewRow();
\r
761 mainWindow.data_chpt.Rows.Insert(i, row);
\r
762 mainWindow.data_chpt.Rows[i].Cells[0].Value = (i + 1);
\r
763 mainWindow.data_chpt.Rows[i].Cells[1].Value = "Chapter " + (i + 1);
\r
767 catch (Exception exc)
\r
769 MessageBox.Show("chapterNaming() Error has occured: \n" + exc.ToString());
\r
774 * This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv in this applications
\r
775 * running directory.
\r
777 private Boolean chapterCSVSave(frmMain mainWindow)
\r
781 string appPath = Application.StartupPath.ToString();
\r
782 appPath = appPath + "\\";
\r
784 string path = appPath + "chapters.csv";
\r
786 StringBuilder csv = new StringBuilder();
\r
788 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)
\r
790 csv.Append(row.Cells[0].Value.ToString());
\r
792 csv.Append(row.Cells[1].Value.ToString());
\r
793 csv.Append(Environment.NewLine);
\r
795 StreamWriter file = new StreamWriter(path);
\r
796 file.Write(csv.ToString());
\r
802 catch (Exception exc)
\r
804 MessageBox.Show(exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
809 // End of Functions
\r