Felix Krull  committed b2d0237

Expose GStreamer command-line options (without it taking over all the options).

  • Participants
  • Parent commits 4afa4c1

Comments (0)

Files changed (4)

File rgain/

 from rgain import GainData, GSTError, util
+# Make sure gobject threads don't crash
 GST_TAG_REFERENCE_LEVEL = "replaygain-reference-level"
 def to_utf8(string):
     def __init__(self, files, force=False, ref_lvl=89):
-        # Make sure gobject threads don't crash
-        gobject.threads_init()
         self.files = files
         self.force = force
         self.ref_lvl = ref_lvl

File rgain/script/

 from optparse import OptionParser
 import traceback
+import pygst
 import rgain.rgio
 stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding()
         return self.exc_info[0] not in [IOError, rgain.rgio.AudioFormatError,
+def init_gstreamer():
+    """Properly initialise GStreamer for the command-line interfaces.
+    Specifically, GStreamer options are parsed and processed by GStreamer, but
+    it is also kept from taking over the main help output (by pretending -h
+    or --help wasn't passed, if necessary). --help-gst should be documented in
+    the main help output as a switch to display GStreamer options."""
+    # Strip any --help options from the command line.
+    stripped_options = []
+    for opt in ["-h", "--help"]:
+        if opt in sys.argv:
+            sys.argv.remove(opt)
+            stripped_options.append(opt)
+    # Then, pass any remaining options to GStreamer.
+    import gst
+    # Finally, restore any help options so optparse can eat them.
+    for opt in stripped_options:
+        sys.argv.append(opt)
 def common_options():
     opts = OptionParser(version="%prog 1.1.1")
                     "the README or man page for more information.",
                     dest="mp3_format", action="store", type="choice",
+    # This option only exists to show up in the help output; if it's actually
+    # specified, GStreamer should eat it.
+    opts.add_option("--help-gst", help="Show GStreamer options.",
+                    dest="help_gst", action="store_true")
     opts.set_defaults(force=False, dry_run=False, ref_level=89,

File rgain/script/

 from mutagen.id3 import TXXX
 from rgain import rgio
-from rgain.script import ou, un, Error, common_options
+from rgain.script import ou, un, Error, common_options, init_gstreamer
 from rgain.script.replaygain import do_gain
 def collectiongain():
+    init_gstreamer()
     optparser = collectiongain_options()
     opts, args = optparser.parse_args()
     if len(args) != 1:

File rgain/script/

 import gobject
 from rgain import rgio, util
-from rgain.script import ou, un, Error, common_options
+from rgain.script import ou, un, Error, common_options, init_gstreamer
 # calculate the gain for the given files
 def replaygain():
+    init_gstreamer()
     optparser = rgain_options()
     opts, args = optparser.parse_args()
     if not args: