summaryrefslogtreecommitdiffstats
path: root/scripts/manicure.rb
blob: d806f84b7a9061e98f7bffd4ed2530e33b7b3072 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
#! /usr/bin/ruby
# manincure.rb version 0.66

# This file is part of the HandBrake source code.
# Homepage: <http://handbrake.m0k.org/>.
# It may be used under the terms of the GNU General Public License.

# This script parses HandBrake's Mac presets into hashes, which can be displayed in various formats for use by the CLI and various wrappers.

# For handling command line arguments to the script
require 'optparse'
require 'ostruct'

# These arrays contain all the other presets and hashes that are going to be used.
# Yeah, they're global variables. In an object-oriented scripting language.
# Real smooth, huh?
$presetMasterList = []
$hashMasterList = []

# This class is pretty much everything. It contains multitudes.
class PresetClass
  
  # A width of 40 gives nice, compact output.
  @@columnWidth=40
  
  # Running initialization runs everything.
  # Calling it will also call the parser
  # and display output.
  def initialize(options)
    
    @options = options

    # Grab input from the user's presets .plist
    rawPresets = readPresetPlist
    
    # Store all the presets in here
    presetStew = []

    # Each item in the array is one line from the .plist
    presetStew = rawPresets.split("\n")
    
    # Now get rid of white space
    presetStew = cleanStew(presetStew)
    
    # This stores the offsets between presets.
    presetBreaks = findPresetBreaks(presetStew)

    # Now it's time to use that info to store each
    # preset individually, in the master list.
    i = 0
    while i <= presetBreaks.size    
      if i == 0 #first preset
        # Grab the stew, up to the 1st offset.
        $presetMasterList[i] = presetStew.slice(0..presetBreaks[i].to_i)
      elsif i < presetBreaks.size #middle presets
        # Grab the stew from the last offset to the current..
        $presetMasterList[i] = presetStew.slice(presetBreaks[i-1].to_i..presetBreaks[i].to_i)
      else #final preset
        # Grab the stew, starting at the last offset, all the way to the end.
        $presetMasterList[i] = presetStew.slice(presetBreaks[i-1].to_i..presetStew.length)
      end
      i += 1
    end
    
    # Parse the presets into hashes
    buildPresetHash
    
    # Print to screen.
    displayCommandStrings
  end

  def readPresetPlist # Grab the .plist and store it in presets
    
    # Grab the user's home path
    homeLocation = `echo $HOME`.chomp
    
    # Use that to build a path to the presets .plist
    inputFile = homeLocation+'/Library/Application\ Support/HandBrake/UserPresets.plist'
    
    # Builds a command that inputs the .plist, but not before stripping all the XML gobbledygook.
    parseCommand = 'cat '+inputFile+' | sed -e \'s/<[a-z]*>//\' -e \'s/<\/[a-z]*>//\'  -e \'/<[?!]/d\' '
    
    puts "\n\n"
    
    # Run the command, return the raw presets
    rawPresets = `#{parseCommand}`
  end

  def cleanStew(presetStew) #remove tabbed white space
    presetStew.each do |oneline|
      oneline.strip!
    end
  end

  def findPresetBreaks(presetStew) #figure out where each preset starts and ends
    i = 0
    j = 0
    presetBreaks =[]
    presetStew.each do |presetLine|
      if presetLine =~ /AudioBitRate/ # This is the first line of a new preset.
        presetBreaks[j] = i-1         # So mark down how long the last one was.
        j += 1
      end
    i += 1
    end
    return presetBreaks
  end

  def buildPresetHash #fill up $hashMasterList with hashes of all key/value pairs
    j = 0
    
    # Iterate through all presets, treating each in turn as singleServing
    $presetMasterList.each do |singleServing|

      # Each key and value are on sequential lines.
      # Iterating through by twos, use that to build a hash.
      # Each key, on line i, paired with its value, on line i+1  
      tempHash = Hash.new
      i = 1
      while i < singleServing.length
        tempHash[singleServing[i]] = singleServing[i+1]
        i += 2
      end
      
      # Now store that hash in the master list.
      $hashMasterList[j]=tempHash
      
      j += 1  
    end   
  end

  def displayCommandStrings # prints everything to screen
    
    # Iterate through the hashes.    
    $hashMasterList.each do |hash|
    
      # Check to make there are valid contents
      if hash.key?("PresetName")
        
        if @options.header == true
          # First throw up a header to make each preset distinct
          displayHeader(hash)
        end
        
        if @options.cliraw == true
          # Show the preset's full CLI string equivalent
          generateCLIString(hash)
        end
        
        if @options.cliparse == true
          generateCLIParse(hash)
        end
        
        if @options.api == true
          # Show the preset as code for test/test.c, HandBrakeCLI
          generateAPIcalls(hash)
        end
        
        if @options.apilist == true
          # Show the preset as print statements, for CLI wrappers to parse.
          generateAPIList(hash) 
        end
      end
    end    
  end
  
  def displayHeader(hash) # A distinct banner to separate each preset
    
    # Print a line of asterisks
    puts "*" * @@columnWidth
    
    # Print the name, centered
    puts '* '+hash["PresetName"].to_s.center(@@columnWidth-4)+' *'
    
    # Print a line of dashes
    puts '~' * @@columnWidth
    
    # Print the description, centered and word-wrapped
    puts hash["PresetDescription"].to_s.center(@@columnWidth).gsub(/\n/," ").scan(/\S.{0,#{@@columnWidth-2}}\S(?=\s|$)|\S+/)
    
    # Print another line of dashes
    puts '~' * @@columnWidth
    
    # Print the formats the preset uses
    puts "#{hash["FileCodecs"]}".center(@@columnWidth)
    
    # Note if the preset isn't built-in
    if hash["Type"].to_i == 1
      puts "Custom Preset".center(@@columnWidth)
    end

    # Note if the preset is marked as default.
    if hash["Default"].to_i == 1
      puts "This is your default preset.".center(@@columnWidth)
    end
    
    # End with a line of tildes.  
    puts "~" * @@columnWidth
    
  end
  
  def generateCLIString(hash) # Makes a full CLI equivalent of a preset
    commandString = ""
    commandString << './HandBrakeCLI -i DVD -o ~/Movies/movie.'
    
    #Filename suffix
    case hash["FileFormat"]
    when /MP4/
      commandString << "mp4 "
    when /AVI/
      commandString << "avi "
    when /OGM/
      commandString << "ogm "
    when /MKV/
      commandString << "mkv "
    end
    
    #Video encoder
    if hash["VideoEncoder"] != "FFmpeg"
      commandString << " -e "
      if hash["VideoEncoder"] == "x264 (h.264 Main)"
        commandString << "x264"
      elsif hash["VideoEncoder"] == "x264 (h.264 iPod)"
        commandString << "x264b30"
      else
        commandString << hash["VideoEncoder"].to_s.downcase
      end
    end

    #VideoRateControl
    case hash["VideoQualityType"].to_i
    when 0
      commandString << " -S " << hash["VideoTargetSize"]
    when 1
      commandString << " -b " << hash["VideoAvgBitrate"]
    when 2
      commandString << " -q " << hash["VideoQualitySlider"] << " -Q"
    end

    #FPS
    if hash["VideoFramerate"] != "Same as source"
      if hash["VideoFramerate"] == "23.976 (NTSC Film)"
        commandString << " -r " << "23.976"
      elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
        commandString << " -r " << "29.97"
      else
        commandString << " -r " << hash["VideoFramerate"]
      end
    end

    #Audio encoder (only specifiy bitrate and samplerate when not doing AC-3 pass-thru)
    commandString << " -E "
    case hash["FileCodecs"]
    when /AC-3/
      commandString << "ac3"
    when /AAC/
      commandString << "faac" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
    when /Vorbis/
      commandString << "vorbis" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
    when /MP3/
      commandString << "lame" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
    end
    
    #Container
    commandString << " -f "
    case hash["FileFormat"]
    when /MP4/
      commandString << "mp4"
    when /AVI/
      commandString << "avi"
    when /OGM/
      commandString << "ogm"
    when /MKV/
      commandString << "mkv"
    end
    
    #Cropping
    if !hash["PictureAutoCrop"].to_i
      commandString << " --crop "
      commandString << hash["PictureTopCrop"]
      commandString << ":"
      commandString << hash["PictureBottomCrop"]
      commandString << ":"
      commandString << hash["PictureLeftCrop"]
      commandString << ":"
      commandString << hash["PictureRightCrop"]
    end
    
    #Dimensions
    if hash["PictureWidth"].to_i != 0
      commandString << " -w "
      commandString << hash["PictureWidth"]
    end
    if hash["PictureHeight"].to_i != 0
      commandString << " -l "
      commandString << hash["PictureHeight"]
    end
    
    #Subtitles
    if hash["Subtitles"] != "None"
      commandString << " -s "
      commandString << hash["Subtitles"]
    end
      
    #Booleans
    if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
    if hash["PictureDeinterlace"].to_i == 1 then commandString << " -d" end
    if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
    if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
    if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
    if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end

    #x264 Options
    if hash["x264Option"] != ""
      commandString << " -x "
      commandString << hash["x264Option"]
    end
    
    # That's it, print to screen now
    puts commandString
    
    #puts "*" * @@columnWidth

    puts  "\n"
  end

  def generateCLIParse(hash) # Makes a CLI equivalent of all user presets, for wrappers to parse
    commandString = ""
    commandString << '+ ' << hash["PresetName"] << ":"
        
    #Video encoder
    if hash["VideoEncoder"] != "FFmpeg"
      commandString << " -e "
      if hash["VideoEncoder"] == "x264 (h.264 Main)"
        commandString << "x264"
      elsif hash["VideoEncoder"] == "x264 (h.264 iPod)"
        commandString << "x264b30"
      else
        commandString << hash["VideoEncoder"].to_s.downcase
      end
    end

    #VideoRateControl
    case hash["VideoQualityType"].to_i
    when 0
      commandString << " -S " << hash["VideoTargetSize"]
    when 1
      commandString << " -b " << hash["VideoAvgBitrate"]
    when 2
      commandString << " -q " << hash["VideoQualitySlider"] << " -Q"
    end

    #FPS
    if hash["VideoFramerate"] != "Same as source"
      if hash["VideoFramerate"] == "23.976 (NTSC Film)"
        commandString << " -r " << "23.976"
      elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
        commandString << " -r " << "29.97"
      else
        commandString << " -r " << hash["VideoFramerate"]
      end
    end
    
    #Audio encoder (only include bitrate and samplerate when not doing AC3 passthru)
    commandString << " -E "
    case hash["FileCodecs"]
    when /AC-3/
      commandString << "ac3"
    when /AAC/
      commandString << "faac" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
    when /Vorbis/
      commandString << "vorbis" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
    when /MP3/
      commandString << "lame" << " -B " << hash["AudioBitRate"] << " -R " << hash["AudioSampleRate"]
    end
    
    #Container
    commandString << " -f "
    case hash["FileFormat"]
    when /MP4/
      commandString << "mp4"
    when /AVI/
      commandString << "avi"
    when /OGM/
      commandString << "ogm"
    when /MKV/
      commandString << "mkv"
    end
    
    #Cropping
    if !hash["PictureAutoCrop"].to_i
      commandString << " --crop "
      commandString << hash["PictureTopCrop"]
      commandString << ":"
      commandString << hash["PictureBottomCrop"]
      commandString << ":"
      commandString << hash["PictureLeftCrop"]
      commandString << ":"
      commandString << hash["PictureRightCrop"]
    end
    
    #Dimensions
    if hash["PictureWidth"].to_i != 0
      commandString << " -w "
      commandString << hash["PictureWidth"]
    end
    if hash["PictureHeight"].to_i != 0
      commandString << " -l "
      commandString << hash["PictureHeight"]
    end
    
    #Subtitles
    if hash["Subtitles"] != "None"
      commandString << " -s "
      commandString << hash["Subtitles"]
    end
      
    #Booleans
    if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
    if hash["PictureDeinterlace"].to_i == 1 then commandString << " -d" end
    if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
    if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
    if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
    if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end

    #x264 Options
    if hash["x264Option"] != ""
      commandString << " -x "
      commandString << hash["x264Option"]
    end
    
    # That's it, print to screen now
    puts commandString
    
    #puts "*" * @@columnWidth

    puts  "\n"
  end

  def generateAPIcalls(hash) # Makes a C version of the preset ready for coding into the CLI
    
    commandString = "if (!strcmp(preset_name, \"" << hash["PresetName"] << "\"))\n{\n\t"
    
    #Filename suffix
    case hash["FileFormat"]
    when /MP4/
      commandString << "mux = " << "HB_MUX_MP4;\n\t"
    when /AVI/
      commandString << "mux = " << "HB_MUX_AVI;\n\t"
    when /OGM/
      commandString << "mux = " << "HB_MUX_OGM;\n\t"
    when /MKV/
      commandString << "mux = " << "HB_MUX_MKV;\n\t"
    end
    
    #Video encoder
    if hash["VideoEncoder"] != "FFmpeg"
      commandString << "vcodec = "
      if hash["VideoEncoder"] == "x264 (h.264 Main)"
        commandString << "HB_VCODEC_X264;\n\t"
      elsif hash["VideoEncoder"] == "x264 (h.264 iPod)"
        commandString << "HB_VCODEC_X264;\njob->h264_level = 30;\n\t"
      elsif hash["VideoEncoder"].to_s.downcase == "xvid"
        commandString << "HB_VCODEC_XVID;\n\t"        
      end
    end

    #VideoRateControl
    case hash["VideoQualityType"].to_i
    when 0
      commandString << "size = " << hash["VideoTargetSize"] << ";\n\t"
    when 1
      commandString << "job->vbitrate = " << hash["VideoAvgBitrate"] << ";\n\t"
    when 2
      commandString << "job->vquality = " << hash["VideoQualitySlider"] << ";\n\t"
      commandString << "job->crf = 1;\n\t"
    end

    #FPS
    if hash["VideoFramerate"] != "Same as source"
      if hash["VideoFramerate"] == "23.976 (NTSC Film)"
        commandString << "job->vrate_base = " << "1126125;\n\t"
      elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
        commandString << "job->vrate_base = " << "900900;\n\t"
      # Gotta add the rest of the framerates for completion's sake.
      end
    end
    
    # Only include samplerate and bitrate when not performing AC3 passthru
    if (hash["FileCodecs"].include? "AC-3") == false
      #Audio bitrate
      commandString << "job->abitrate = " << hash["AudioBitRate"] << ";\n\t"
    
      #Audio samplerate
      commandString << "job->arate = "
      case hash["AudioSampleRate"]
      when /48/
        commandString << "48000"
      when /44.1/
        commandString << "44100"
      when /32/
        commandString << "32000"
      when /24/
        commandString << "24000"
      when /22.05/
        commandString << "22050"
      end
      commandString << ";\n\t"
    end
      
    #Audio encoder
    commandString << "acodec = "
    case hash["FileCodecs"]
    when /AAC/
      commandString << "HB_ACODEC_FAAC;\n\t"
    when /AC-3/
      commandString << "HB_ACODEC_AC3;\n\t"
    when /Vorbis/
      commandString << "HB_ACODEC_VORBIS;\n\t"
    when /MP3/
      commandString << "HB_ACODEC_LAME;\n\t"
    end
    
    #Cropping
    if !hash["PictureAutoCrop"].to_i
      commandString << "job->crop[0] = " << hash["PictureTopCrop"] << ";\n\t"
      commandString << "job->crop[1] = " << hash["PictureBottomCrop"] << ";\n\t"
      commandString << "job->crop[2] = " << hash["PictureLeftCrop"] << ";\n\t"
      commandString << "job->crop[4] - " << hash["PictureRightCrop"] << ";\n\t"
    end
    
    #Dimensions
    if hash["PictureWidth"].to_i != 0
      commandString << "job->width = "
      commandString << hash["PictureWidth"] << ";\n\t"
    end
    if hash["PictureHeight"].to_i != 0
      commandString << "job->height = "
      commandString << hash["PictureHeight"] << ";\n\t"
    end
    
    #Subtitles
    if hash["Subtitles"] != "None"
      commandString << "job->subtitle = "
      commandString << ( hash["Subtitles"].to_i - 1).to_s << ";\n\t"
    end
    
    #x264 Options
    if hash["x264Option"] != ""
      commandString << "x264opts = strdup(\""
      commandString << hash["x264Option"] << "\");\n\t"
    end
    
    #Booleans
    if hash["ChapterMarkers"].to_i == 1 then commandString << "job->chapter_markers = 1;\n\t" end
    if hash["PictureDeinterlace"].to_i == 1 then commandString << "job->deinterlace = 1;\n\t" end
    if hash["PicturePAR"].to_i == 1 then commandString << "pixelratio = 1;\n\t" end
    if hash["VideoGrayScale"].to_i == 1 then commandString << "job->grayscale = 1;\n\t" end
    if hash["VideoTwoPass"].to_i == 1 then commandString << "twoPass = 1;\n\t" end
    if hash["VideoTurboTwoPass"].to_i == 1 then commandString << "turbo_opts_enabled = 1;\n" end
    
    commandString << "}"
    
    # That's it, print to screen now
    puts commandString
    #puts "*" * @@columnWidth
    puts  "\n"
  end

  def generateAPIList(hash) # Makes a list of the CLI options a built-in CLI preset uses, for wrappers to parse
    commandString = ""
    commandString << "printf(\"\\n+ " << hash["PresetName"] << ": "
        
    #Video encoder
    if hash["VideoEncoder"] != "FFmpeg"
      commandString << " -e "
      if hash["VideoEncoder"] == "x264 (h.264 Main)"
        commandString << "x264"
      elsif hash["VideoEncoder"] == "x264 (h.264 iPod)"
        commandString << "x264b30"
      else
        commandString << hash["VideoEncoder"].to_s.downcase
      end
    end

    #VideoRateControl
    case hash["VideoQualityType"].to_i
    when 0
      commandString << " -S " << hash["VideoTargetSize"]
    when 1
      commandString << " -b " << hash["VideoAvgBitrate"]
    when 2
      commandString << " -q " << hash["VideoQualitySlider"] << " -Q "
    end

    #FPS
    if hash["VideoFramerate"] != "Same as source"
      if hash["VideoFramerate"] == "23.976 (NTSC Film)"
        commandString << " -r " << "23.976"
      elsif hash["VideoFramerate"] == "29.97 (NTSC Video)"
        commandString << " -r " << "29.97"
      else
        commandString << " -r " << hash["VideoFramerate"]
      end
    end
    
    # Only include samplerate and bitrate when not performing AC-3 passthru
    if (hash["FileCodecs"].include? "AC-3") == false
      #Audio bitrate
      commandString << " -B " << hash["AudioBitRate"]
      #Audio samplerate
      commandString << " -R " << hash["AudioSampleRate"]
    end
    
    #Audio encoder
    commandString << " -E "
    case hash["FileCodecs"]
    when /AAC/
      commandString << "faac"
    when /AC-3/
      commandString << "ac3"
    when /Vorbis/
      commandString << "vorbis"
    when /MP3/
      commandString << "lame"
    end
    
    #Container
    commandString << " -f "
    case hash["FileFormat"]
    when /MP4/
      commandString << "mp4"
    when /AVI/
      commandString << "avi"
    when /OGM/
      commandString << "ogm"
    when /MKV/
      commandString << "mkv"
    end
    
    #Cropping
    if !hash["PictureAutoCrop"].to_i
      commandString << " --crop "
      commandString << hash["PictureTopCrop"]
      commandString << ":"
      commandString << hash["PictureBottomCrop"]
      commandString << ":"
      commandString << hash["PictureLeftCrop"]
      commandString << ":"
      commandString << hash["PictureRightCrop"]
    end
    
    #Dimensions
    if hash["PictureWidth"].to_i != 0
      commandString << " -w "
      commandString << hash["PictureWidth"]
    end
    if hash["PictureHeight"].to_i != 0
      commandString << " -l "
      commandString << hash["PictureHeight"]
    end
    
    #Subtitles
    if hash["Subtitles"] != "None"
      commandString << " -s "
      commandString << hash["Subtitles"]
    end
        
    #Booleans
    if hash["ChapterMarkers"].to_i == 1 then commandString << " -m" end
    if hash["PictureDeinterlace"].to_i == 1 then commandString << " -d" end
    if hash["PicturePAR"].to_i == 1 then commandString << " -p" end
    if hash["VideoGrayScale"].to_i == 1 then commandString << " -g" end
    if hash["VideoTwoPass"].to_i == 1 then commandString << " -2" end
    if hash["VideoTurboTwoPass"].to_i == 1 then commandString << " -T" end
    
      #x264 Options
      if hash["x264Option"] != ""
        commandString << " -x "
        commandString << hash["x264Option"]
      end
    
    commandString << "\\n\");"
    
    # That's it, print to screen now
    puts commandString
    puts  "\n"
  end
end

# CLI options: (code based on http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/index.html )
# --[no-]cli-raw, -r gives raw CLI for wiki
# --cli-parse, -p gives CLI strings for wrappers
# --api, -a gives preset code for test.c
# --api-list, -A gives CLI strings for --preset-list display
# --[no-]header, -h turns off banner display
options = OpenStruct.new
options.cliraw = false
options.cliparse = false
options.api = false
options.apilist = false
options.header = false

opts = OptionParser.new do |opts|
  opts.banner = "Usage: manicure.rb [options]"
  
  opts.separator ""
  opts.separator "Options:"
  
  opts.on("-r", "--cli-raw", "Gives example strings for the HB wiki") do |r|
    options.cliraw = r
    option_set = true
  end
  
  opts.on("-p", "--cli-parse", "Gives presets as wrapper-parseable CLI", " option strings") do |p|
    options.cliparse = p
  end
  
  opts.on("-a", "--api", "Gives preset code for test.c") do |api|
    options.api = api
  end
  
  opts.on("-A", "--api-list", "Gives code for test.c's --preset-list", " options") do |A|
    options.apilist = A
  end
  
  opts.on("-H", "--Header", "Display a banner before each preset") do |H|
    options.header = H
  end
  
  opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
  end
end.parse!

# Only run if one of the useful CLI flags have been passed
if options.cliraw == true || options.cliparse == true || options.api == true || options.apilist == true
  # This line is the ignition.
  PresetClass.new(options)
else
  # Direct the user to the help
  puts "\n\tUsage: manicure.rb [options]"
  puts "\tSee help with -h or --help"
end