OSDN Git Service

Updates manicure for the new default CRF setting in the CLI, so it doesn't add a -Q.
[handbrake-jp/handbrake-jp-git.git] / scripts / manicure.rb
1 #! /usr/bin/ruby
2 # manincure.rb version 0.66
3
4 # This file is part of the HandBrake source code.
5 # Homepage: <http://handbrake.m0k.org/>.
6 # It may be used under the terms of the GNU General Public License.
7
8 # This script parses HandBrake's Mac presets into hashes, which can be displayed in various formats for use by the CLI and various wrappers.
9
10 # For handling command line arguments to the script
11 require 'optparse'
12 require 'ostruct'
13
14 # These arrays contain all the other presets and hashes that are going to be used.
15 # Yeah, they're global variables. In an object-oriented scripting language.
16 # Real smooth, huh?
17 $presetMasterList = []
18 $hashMasterList = []
19
20 # This class is pretty much everything. It contains multitudes.
21 class PresetClass
22   
23   # A width of 40 gives nice, compact output.
24   @@columnWidth=40
25   
26   # Running initialization runs everything.
27   # Calling it will also call the parser
28   # and display output.
29   def initialize(options)
30     
31     @options = options
32
33     # Grab input from the user's presets .plist
34     rawPresets = readPresetPlist
35     
36     # Store all the presets in here
37     presetStew = []
38
39     # Each item in the array is one line from the .plist
40     presetStew = rawPresets.split("\n")
41     
42     # Now get rid of white space
43     presetStew = cleanStew(presetStew)
44     
45     # This stores the offsets between presets.
46     presetBreaks = findPresetBreaks(presetStew)
47
48     # Now it's time to use that info to store each
49     # preset individually, in the master list.
50     i = 0
51     while i <= presetBreaks.size    
52       if i == 0 #first preset
53         # Grab the stew, up to the 1st offset.
54         $presetMasterList[i] = presetStew.slice(0..presetBreaks[i].to_i)
55       elsif i < presetBreaks.size #middle presets
56         # Grab the stew from the last offset to the current..
57         $presetMasterList[i] = presetStew.slice(presetBreaks[i-1].to_i..presetBreaks[i].to_i)
58       else #final preset
59         # Grab the stew, starting at the last offset, all the way to the end.
60         $presetMasterList[i] = presetStew.slice(presetBreaks[i-1].to_i..presetStew.length)
61       end
62       i += 1
63     end
64     
65     # Parse the presets into hashes
66     buildPresetHash
67     
68     # Print to screen.
69     displayCommandStrings
70   end
71
72   def readPresetPlist # Grab the .plist and store it in presets
73     
74     # Grab the user's home path
75     homeLocation = `echo $HOME`.chomp
76     
77     # Use that to build a path to the presets .plist
78     inputFile = homeLocation+'/Library/Application\ Support/HandBrake/UserPresets.plist'
79     
80     # Builds a command that inputs the .plist, but not before stripping all the XML gobbledygook.
81     parseCommand = 'cat '+inputFile+' | sed -e \'s/<[a-z]*>//\' -e \'s/<\/[a-z]*>//\'  -e \'/<[?!]/d\' '
82     
83     puts "\n\n"
84     
85     # Run the command, return the raw presets
86     rawPresets = `#{parseCommand}`
87   end
88
89   def cleanStew(presetStew) #remove tabbed white space
90     presetStew.each do |oneline|
91       oneline.strip!
92     end
93   end
94
95   def findPresetBreaks(presetStew) #figure out where each preset starts and ends
96     i = 0
97     j = 0
98     presetBreaks =[]
99     presetStew.each do |presetLine|
100       if presetLine =~ /AudioBitRate/ # This is the first line of a new preset.
101         presetBreaks[j] = i-1         # So mark down how long the last one was.
102         j += 1
103       end
104     i += 1
105     end
106     return presetBreaks
107   end
108
109   def buildPresetHash #fill up $hashMasterList with hashes of all key/value pairs
110     j = 0
111     
112     # Iterate through all presets, treating each in turn as singleServing
113     $presetMasterList.each do |singleServing|
114
115       # Each key and value are on sequential lines.
116       # Iterating through by twos, use that to build a hash.
117       # Each key, on line i, paired with its value, on line i+1  
118       tempHash = Hash.new
119       i = 1
120       while i < singleServing.length
121         tempHash[singleServing[i]] = singleServing[i+1]
122         i += 2
123       end
124       
125       # Now store that hash in the master list.
126       $hashMasterList[j]=tempHash
127       
128       j += 1  
129     end   
130   end
131
132   def displayCommandStrings # prints everything to screen
133     
134     # Iterate through the hashes.    
135     $hashMasterList.each do |hash|
136     
137       # Check to make there are valid contents
138       if hash.key?("PresetName")
139         
140         if @options.header == true
141           # First throw up a header to make each preset distinct
142           displayHeader(hash)
143         end
144         
145         if @options.cliraw == true
146           # Show the preset's full CLI string equivalent
147           generateCLIString(hash)
148         end
149         
150         if @options.cliparse == true
151           generateCLIParse(hash)
152         end
153         
154         if @options.api == true
155           # Show the preset as code for test/test.c, HandBrakeCLI
156           generateAPIcalls(hash)
157         end
158         
159         if @options.apilist == true
160           # Show the preset as print statements, for CLI wrappers to parse.
161           generateAPIList(hash) 
162         end
163       end
164     end    
165   end
166   
167   def displayHeader(hash) # A distinct banner to separate each preset
168     
169     # Print a line of asterisks
170     puts "*" * @@columnWidth
171     
172     # Print the name, centered
173     puts '* '+hash["PresetName"].to_s.center(@@columnWidth-4)+' *'
174     
175     # Print a line of dashes
176     puts '~' * @@columnWidth
177     
178     # Print the description, centered and word-wrapped
179     puts hash["PresetDescription"].to_s.center(@@columnWidth).gsub(/\n/," ").scan(/\S.{0,#{@@columnWidth-2}}\S(?=\s|$)|\S+/)
180     
181     # Print another line of dashes
182     puts '~' * @@columnWidth
183     
184     # Print the formats the preset uses
185     puts "#{hash["FileCodecs"]}".center(@@columnWidth)
186     
187     # Note if the preset isn't built-in
188     if hash["Type"].to_i == 1
189       puts "Custom Preset".center(@@columnWidth)
190     end
191
192     # Note if the preset is marked as default.
193     if hash["Default"].to_i == 1
194       puts "This is your default preset.".center(@@columnWidth)
195     end
196     
197     # End with a line of tildes.  
198     puts "~" * @@columnWidth
199     
200   end
201   
202   def generateCLIString(hash) # Makes a full CLI equivalent of a preset
203     commandString = ""
204     commandString << './HandBrakeCLI -i DVD -o ~/Movies/movie.'
205     
206     #Filename suffix
207     case hash["FileFormat"]
208     when /MP4/
209       commandString << "mp4 "
210     when /AVI/
211       commandString << "avi "
212     when /OGM/
213       commandString << "ogm "
214     when /MKV/
215       commandString << "mkv "
216     end
217     
218     #Video encoder
219     if hash["VideoEncoder"] != "FFmpeg"
220       commandString << " -e "
221       if hash["VideoEncoder"] == "x264 (h.264 Main)"
222         commandString << "x264"
223       elsif hash["VideoEncoder"] == "x264 (h.264 iPod)"
224         commandString << "x264b30"
225       else
226         commandString << hash["VideoEncoder"].to_s.downcase
227       end
228     end
229
230     #VideoRateControl
231     case hash["VideoQualityType"].to_i
232     when 0
233       commandString << " -S " << hash["VideoTargetSize"]
234     when 1
235       commandString << " -b " << hash["VideoAvgBitrate"]
236     when 2
237       commandString << " -q " << hash["VideoQualitySlider"]
238     end
239
240     #FPS
241     if hash["VideoFramerate"] != "Same as source"
242       if hash["VideoFramerate"] == "23.976 (NTSC Film)"
243         commandString << " -r " << "23.976"
244       elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
245         commandString << " -r " << "29.97"
246       else
247         commandString << " -r " << hash["VideoFramerate"]
248       end
249     end
250
251     #Audio encoder (only specifiy bitrate and samplerate when not doing AC-3 pass-thru)
252     commandString << " -E "
253     case hash["FileCodecs"]
254     when /AC-3/
255       commandString << "ac3"
256     when /AAC/
257       commandString << "faac" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
258     when /Vorbis/
259       commandString << "vorbis" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
260     when /MP3/
261       commandString << "lame" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
262     end
263     
264     #Container
265     commandString << " -f "
266     case hash["FileFormat"]
267     when /MP4/
268       commandString << "mp4"
269     when /AVI/
270       commandString << "avi"
271     when /OGM/
272       commandString << "ogm"
273     when /MKV/
274       commandString << "mkv"
275     end
276     
277     #Cropping
278     if !hash["PictureAutoCrop"].to_i
279       commandString << " --crop "
280       commandString << hash["PictureTopCrop"]
281       commandString << ":"
282       commandString << hash["PictureBottomCrop"]
283       commandString << ":"
284       commandString << hash["PictureLeftCrop"]
285       commandString << ":"
286       commandString << hash["PictureRightCrop"]
287     end
288     
289     #Dimensions
290     if hash["PictureWidth"].to_i != 0
291       commandString << " -w "
292       commandString << hash["PictureWidth"]
293     end
294     if hash["PictureHeight"].to_i != 0
295       commandString << " -l "
296       commandString << hash["PictureHeight"]
297     end
298     
299     #Subtitles
300     if hash["Subtitles"] != "None"
301       commandString << " -s "
302       commandString << hash["Subtitles"]
303     end
304
305     #Video Filters
306     if hash["UsesPictureFilters"].to_i == 1
307       
308       case hash["PictureDeinterlace"].to_i
309       when 1
310         commandString << " --deinterlace=\"fast\""
311       when 2
312         commandString << " --deinterlace=\slow\""
313       when 3
314         commandString << " --deinterlace=\"slower\""
315       when 4
316         commandString << " --deinterlace=\"slowest\""
317       end
318       
319       case hash["PictureDenoise"].to_i
320       when 1
321         commandString << " --denoise=\"weak\""
322       when 2
323         commandString << " --denoise=\"medium\""
324       when 3
325         commandString << " --denoise=\"strong\""
326       end
327       
328       if hash["PictureDetelecine"].to_i == 1 then commandString << " --detelecine" end
329       if hash["PictureDeblock"].to_i == 1 then commandString << " --deblock" end
330       if hash["VFR"].to_i == 1 then commandString << " --vfr" end
331     end
332
333     #Booleans
334     if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
335     if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
336     if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
337     if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
338     if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end
339
340     #x264 Options
341     if hash["x264Option"] != ""
342       commandString << " -x "
343       commandString << hash["x264Option"]
344     end
345     
346     # That's it, print to screen now
347     puts commandString
348     
349     #puts "*" * @@columnWidth
350
351     puts  "\n"
352   end
353
354   def generateCLIParse(hash) # Makes a CLI equivalent of all user presets, for wrappers to parse
355     commandString = ""
356     commandString << '+ ' << hash["PresetName"] << ":"
357         
358     #Video encoder
359     if hash["VideoEncoder"] != "FFmpeg"
360       commandString << " -e "
361       if hash["VideoEncoder"] == "x264 (h.264 Main)"
362         commandString << "x264"
363       elsif hash["VideoEncoder"] == "x264 (h.264 iPod)"
364         commandString << "x264b30"
365       else
366         commandString << hash["VideoEncoder"].to_s.downcase
367       end
368     end
369
370     #VideoRateControl
371     case hash["VideoQualityType"].to_i
372     when 0
373       commandString << " -S " << hash["VideoTargetSize"]
374     when 1
375       commandString << " -b " << hash["VideoAvgBitrate"]
376     when 2
377       commandString << " -q " << hash["VideoQualitySlider"]
378     end
379
380     #FPS
381     if hash["VideoFramerate"] != "Same as source"
382       if hash["VideoFramerate"] == "23.976 (NTSC Film)"
383         commandString << " -r " << "23.976"
384       elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
385         commandString << " -r " << "29.97"
386       else
387         commandString << " -r " << hash["VideoFramerate"]
388       end
389     end
390     
391     #Audio encoder (only include bitrate and samplerate when not doing AC3 passthru)
392     commandString << " -E "
393     case hash["FileCodecs"]
394     when /AC-3/
395       commandString << "ac3"
396     when /AAC/
397       commandString << "faac" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
398     when /Vorbis/
399       commandString << "vorbis" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
400     when /MP3/
401       commandString << "lame" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
402     end
403     
404     #Container
405     commandString << " -f "
406     case hash["FileFormat"]
407     when /MP4/
408       commandString << "mp4"
409     when /AVI/
410       commandString << "avi"
411     when /OGM/
412       commandString << "ogm"
413     when /MKV/
414       commandString << "mkv"
415     end
416     
417     #Cropping
418     if !hash["PictureAutoCrop"].to_i
419       commandString << " --crop "
420       commandString << hash["PictureTopCrop"]
421       commandString << ":"
422       commandString << hash["PictureBottomCrop"]
423       commandString << ":"
424       commandString << hash["PictureLeftCrop"]
425       commandString << ":"
426       commandString << hash["PictureRightCrop"]
427     end
428     
429     #Dimensions
430     if hash["PictureWidth"].to_i != 0
431       commandString << " -w "
432       commandString << hash["PictureWidth"]
433     end
434     if hash["PictureHeight"].to_i != 0
435       commandString << " -l "
436       commandString << hash["PictureHeight"]
437     end
438     
439     #Subtitles
440     if hash["Subtitles"] != "None"
441       commandString << " -s "
442       commandString << hash["Subtitles"]
443     end
444     
445     #Video Filters
446     if hash["UsesPictureFilters"].to_i == 1
447       
448       case hash["PictureDeinterlace"].to_i
449       when 1
450         commandString << " --deinterlace=\"fast\""
451       when 2
452         commandString << " --deinterlace=\slow\""
453       when 3
454         commandString << " --deinterlace=\"slower\""
455       when 4
456         commandString << " --deinterlace=\"slowest\""
457       end
458       
459       case hash["PictureDenoise"].to_i
460       when 1
461         commandString << " --denoise=\"weak\""
462       when 2
463         commandString << " --denoise=\"medium\""
464       when 3
465         commandString << " --denoise=\"strong\""
466       end
467       
468       if hash["PictureDetelecine"].to_i == 1 then commandString << " --detelecine" end
469       if hash["PictureDeblock"].to_i == 1 then commandString << " --deblock" end
470       if hash["VFR"].to_i == 1 then commandString << " --vfr" end
471     end
472
473     #Booleans
474     if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
475     if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
476     if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
477     if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
478     if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end
479
480     #x264 Options
481     if hash["x264Option"] != ""
482       commandString << " -x "
483       commandString << hash["x264Option"]
484     end
485     
486     # That's it, print to screen now
487     puts commandString
488     
489     #puts "*" * @@columnWidth
490
491     puts  "\n"
492   end
493
494   def generateAPIcalls(hash) # Makes a C version of the preset ready for coding into the CLI
495     
496     commandString = "if (!strcmp(preset_name, \"" << hash["PresetName"] << "\"))\n{\n    "
497     
498     #Filename suffix
499     case hash["FileFormat"]
500     when /MP4/
501       commandString << "mux = " << "HB_MUX_MP4;\n    "
502     when /AVI/
503       commandString << "mux = " << "HB_MUX_AVI;\n    "
504     when /OGM/
505       commandString << "mux = " << "HB_MUX_OGM;\n    "
506     when /MKV/
507       commandString << "mux = " << "HB_MUX_MKV;\n    "
508     end
509     
510     #Video encoder
511     if hash["VideoEncoder"] != "FFmpeg"
512       commandString << "vcodec = "
513       if hash["VideoEncoder"] == "x264 (h.264 Main)"
514         commandString << "HB_VCODEC_X264;\n    "
515       elsif hash["VideoEncoder"] == "x264 (h.264 iPod)"
516         commandString << "HB_VCODEC_X264;\njob->h264_level = 30;\n    "
517       elsif hash["VideoEncoder"].to_s.downcase == "xvid"
518         commandString << "HB_VCODEC_XVID;\n    "        
519       end
520     end
521
522     #VideoRateControl
523     case hash["VideoQualityType"].to_i
524     when 0
525       commandString << "size = " << hash["VideoTargetSize"] << ";\n    "
526     when 1
527       commandString << "job->vbitrate = " << hash["VideoAvgBitrate"] << ";\n    "
528     when 2
529       commandString << "job->vquality = " << hash["VideoQualitySlider"] << ";\n    "
530       commandString << "job->crf = 1;\n    "
531     end
532
533     #FPS
534     if hash["VideoFramerate"] != "Same as source"
535       if hash["VideoFramerate"] == "23.976 (NTSC Film)"
536         commandString << "job->vrate_base = " << "1126125;\n    "
537       elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
538         commandString << "job->vrate_base = " << "900900;\n    "
539       # Gotta add the rest of the framerates for completion's sake.
540       end
541     end
542     
543     # Only include samplerate and bitrate when not performing AC3 passthru
544     if (hash["FileCodecs"].include? "AC-3") == false
545       #Audio bitrate
546       commandString << "job->abitrate = " << hash["AudioBitRate"] << ";\n    "
547     
548       #Audio samplerate
549       commandString << "job->arate = "
550       case hash["AudioSampleRate"]
551       when /48/
552         commandString << "48000"
553       when /44.1/
554         commandString << "44100"
555       when /32/
556         commandString << "32000"
557       when /24/
558         commandString << "24000"
559       when /22.05/
560         commandString << "22050"
561       end
562       commandString << ";\n    "
563     end
564       
565     #Audio encoder
566     commandString << "acodec = "
567     case hash["FileCodecs"]
568     when /AAC/
569       commandString << "HB_ACODEC_FAAC;\n    "
570     when /AC-3/
571       commandString << "HB_ACODEC_AC3;\n    "
572     when /Vorbis/
573       commandString << "HB_ACODEC_VORBIS;\n    "
574     when /MP3/
575       commandString << "HB_ACODEC_LAME;\n    "
576     end
577     
578     #Cropping
579     if !hash["PictureAutoCrop"].to_i
580       commandString << "job->crop[0] = " << hash["PictureTopCrop"] << ";\n    "
581       commandString << "job->crop[1] = " << hash["PictureBottomCrop"] << ";\n    "
582       commandString << "job->crop[2] = " << hash["PictureLeftCrop"] << ";\n    "
583       commandString << "job->crop[4] - " << hash["PictureRightCrop"] << ";\n    "
584     end
585     
586     #Dimensions
587     if hash["PictureWidth"].to_i != 0
588       commandString << "job->width = "
589       commandString << hash["PictureWidth"] << ";\n    "
590     end
591     if hash["PictureHeight"].to_i != 0
592       commandString << "job->height = "
593       commandString << hash["PictureHeight"] << ";\n    "
594     end
595     
596     #Subtitles
597     if hash["Subtitles"] != "None"
598       commandString << "job->subtitle = "
599       commandString << ( hash["Subtitles"].to_i - 1).to_s << ";\n    "
600     end
601     
602     #x264 Options
603     if hash["x264Option"] != ""
604       commandString << "x264opts = strdup(\""
605       commandString << hash["x264Option"] << "\");\n    "
606     end
607     
608     #Video Filters
609     if hash["UsesPictureFilters"].to_i == 1
610       
611       case hash["PictureDeinterlace"].to_i
612       when 1
613         commandString << "deinterlace = 1;\n    "
614         commandString << "deinterlace_opt = \"-1\";\n    "
615       when 2
616         commandString << "deinterlace = 1;\n    "
617         commandString << "deinterlace_opt = \"0\";\n    "
618       when 3
619         commandString << "deinterlace = 1;\n    "
620         commandString << "deinterlace_opt = \"2:-1:1\";\n    "
621       when 4
622         commandString << "deinterlace = 1;\n    "
623         commandString << "deinterlace_opt = \"1:-1:1\";\n    "
624       end
625       
626       case hash["PictureDenoise"].to_i
627       when 1
628         commandString << "denoise = 1;\n    "
629         commandString << "denoise_opt = \"2:1:2:3\";\n    "
630       when 2
631         commandString << "denoise = 1;\n    "
632         commandString << "denoise_opt = \"3:2:2:3\";\n    "
633       when 3
634         commandString << "denoise = 1;\n    "
635         commandString << "denoise_opt = \"7:7:5:5\";\n    "
636       end
637       
638       if hash["PictureDetelecine"].to_i == 1 then commandString << "detelecine = 1;\n    " end
639       if hash["PictureDeblock"].to_i == 1 then commandString << "deblock = 1;\n    " end
640       if hash["VFR"].to_i == 1 then commandString << "vfr = 1;\n    " end
641     end
642     
643     #Booleans
644     if hash["ChapterMarkers"].to_i == 1 then commandString << "job->chapter_markers = 1;\n    " end
645     if hash["PicturePAR"].to_i == 1 then commandString << "pixelratio = 1;\n    " end
646     if hash["VideoGrayScale"].to_i == 1 then commandString << "job->grayscale = 1;\n    " end
647     if hash["VideoTwoPass"].to_i == 1 then commandString << "twoPass = 1;\n    " end
648     if hash["VideoTurboTwoPass"].to_i == 1 then commandString << "turbo_opts_enabled = 1;\n" end
649     
650     commandString << "}"
651     
652     # That's it, print to screen now
653     puts commandString
654     #puts "*" * @@columnWidth
655     puts  "\n"
656   end
657
658   def generateAPIList(hash) # Makes a list of the CLI options a built-in CLI preset uses, for wrappers to parse
659     commandString = ""
660     commandString << "    printf(\"\\n+ " << hash["PresetName"] << ": "
661         
662     #Video encoder
663     if hash["VideoEncoder"] != "FFmpeg"
664       commandString << " -e "
665       if hash["VideoEncoder"] == "x264 (h.264 Main)"
666         commandString << "x264"
667       elsif hash["VideoEncoder"] == "x264 (h.264 iPod)"
668         commandString << "x264b30"
669       else
670         commandString << hash["VideoEncoder"].to_s.downcase
671       end
672     end
673
674     #VideoRateControl
675     case hash["VideoQualityType"].to_i
676     when 0
677       commandString << " -S " << hash["VideoTargetSize"]
678     when 1
679       commandString << " -b " << hash["VideoAvgBitrate"]
680     when 2
681       commandString << " -q " << hash["VideoQualitySlider"]
682     end
683
684     #FPS
685     if hash["VideoFramerate"] != "Same as source"
686       if hash["VideoFramerate"] == "23.976 (NTSC Film)"
687         commandString << " -r " << "23.976"
688       elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
689         commandString << " -r " << "29.97"
690       else
691         commandString << " -r " << hash["VideoFramerate"]
692       end
693     end
694     
695     # Only include samplerate and bitrate when not performing AC-3 passthru
696     if (hash["FileCodecs"].include? "AC-3") == false
697       #Audio bitrate
698       commandString << " -B " << hash["AudioBitRate"]
699       #Audio samplerate
700       commandString << " -R " << hash["AudioSampleRate"]
701     end
702     
703     #Audio encoder
704     commandString << " -E "
705     case hash["FileCodecs"]
706     when /AAC/
707       commandString << "faac"
708     when /AC-3/
709       commandString << "ac3"
710     when /Vorbis/
711       commandString << "vorbis"
712     when /MP3/
713       commandString << "lame"
714     end
715     
716     #Container
717     commandString << " -f "
718     case hash["FileFormat"]
719     when /MP4/
720       commandString << "mp4"
721     when /AVI/
722       commandString << "avi"
723     when /OGM/
724       commandString << "ogm"
725     when /MKV/
726       commandString << "mkv"
727     end
728     
729     #Cropping
730     if !hash["PictureAutoCrop"].to_i
731       commandString << " --crop "
732       commandString << hash["PictureTopCrop"]
733       commandString << ":"
734       commandString << hash["PictureBottomCrop"]
735       commandString << ":"
736       commandString << hash["PictureLeftCrop"]
737       commandString << ":"
738       commandString << hash["PictureRightCrop"]
739     end
740     
741     #Dimensions
742     if hash["PictureWidth"].to_i != 0
743       commandString << " -w "
744       commandString << hash["PictureWidth"]
745     end
746     if hash["PictureHeight"].to_i != 0
747       commandString << " -l "
748       commandString << hash["PictureHeight"]
749     end
750     
751     #Subtitles
752     if hash["Subtitles"] != "None"
753       commandString << " -s "
754       commandString << hash["Subtitles"]
755     end
756     
757     #Video Filters
758     if hash["UsesPictureFilters"].to_i == 1
759       
760       case hash["PictureDeinterlace"].to_i
761       when 1
762         commandString << " --deinterlace=\\\"fast\\\""
763       when 2
764         commandString << " --deinterlace=\\\slow\\\""
765       when 3
766         commandString << " --deinterlace=\\\"slower\\\""
767       when 4
768         commandString << " --deinterlace=\\\"slowest\\\""
769       end
770       
771       case hash["PictureDenoise"].to_i
772       when 1
773         commandString << " --denoise=\\\"weak\\\""
774       when 2
775         commandString << " --denoise=\\\"medium\\\""
776       when 3
777         commandString << " --denoise=\\\"strong\\\""
778       end
779       
780       if hash["PictureDetelecine"].to_i == 1 then commandString << " --detelecine" end
781       if hash["PictureDeblock"].to_i == 1 then commandString << " --deblock" end
782       if hash["VFR"].to_i == 1 then commandString << " --vfr" end
783     end
784     
785     #Booleans
786     if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
787     if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
788     if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
789     if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
790     if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end
791     
792       #x264 Options
793       if hash["x264Option"] != ""
794         commandString << " -x "
795         commandString << hash["x264Option"]
796       end
797     
798     commandString << "\\n\");"
799     
800     # That's it, print to screen now
801     puts commandString
802     puts  "\n"
803   end
804 end
805
806 # CLI options: (code based on http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/index.html )
807 # --[no-]cli-raw, -r gives raw CLI for wiki
808 # --cli-parse, -p gives CLI strings for wrappers
809 # --api, -a gives preset code for test.c
810 # --api-list, -A gives CLI strings for --preset-list display
811 # --[no-]header, -h turns off banner display
812 options = OpenStruct.new
813 options.cliraw = false
814 options.cliparse = false
815 options.api = false
816 options.apilist = false
817 options.header = false
818
819 opts = OptionParser.new do |opts|
820   opts.banner = "Usage: manicure.rb [options]"
821   
822   opts.separator ""
823   opts.separator "Options:"
824   
825   opts.on("-r", "--cli-raw", "Gives example strings for the HB wiki") do |r|
826     options.cliraw = r
827     option_set = true
828   end
829   
830   opts.on("-p", "--cli-parse", "Gives presets as wrapper-parseable CLI", " option strings") do |p|
831     options.cliparse = p
832   end
833   
834   opts.on("-a", "--api", "Gives preset code for test.c") do |api|
835     options.api = api
836   end
837   
838   opts.on("-A", "--api-list", "Gives code for test.c's --preset-list", " options") do |A|
839     options.apilist = A
840   end
841   
842   opts.on("-H", "--Header", "Display a banner before each preset") do |H|
843     options.header = H
844   end
845   
846   opts.on_tail("-h", "--help", "Show this message") do
847       puts opts
848       exit
849   end
850 end.parse!
851
852 # Only run if one of the useful CLI flags have been passed
853 if options.cliraw == true || options.cliparse == true || options.api == true || options.apilist == true
854   # This line is the ignition.
855   PresetClass.new(options)
856 else
857   # Direct the user to the help
858   puts "\n\tUsage: manicure.rb [options]"
859   puts "\tSee help with -h or --help"
860 end