0

I've been wracking my head around this for a while.

6
  • mpg123 tunes/* 2>&1 | tail -n +6 ?
    – ibuprofen
    Commented Aug 25, 2021 at 0:44
  • Would you mind to explain how the "obvious things" don't work for this particular case?
    – AdminBee
    Commented Aug 31, 2021 at 13:00
  • They corrupt the output, such that when closing the program, it prints an additional line to the beginning of the input, which I find very annoying.
    – NNNN
    Commented Sep 1, 2021 at 7:03
  • In any case, since the program is open source I tried to recompile it without the welcome message, but that led to me completely messing up my installation, so I can't really test the above message right now.
    – NNNN
    Commented Sep 1, 2021 at 7:05
  • Wow, I haven't used mpg123 since probably around 1999 or 2000.
    – Kaz
    Commented Sep 8, 2021 at 21:23

1 Answer 1

0

Turns out that pipe buffering was causing problems with mpg123's -C option. This can be solved by using the --line-buffered option in grep, or -u in sed.

In the end, the set of flags I ended up using was:

mpg123 -Z -C --title */* 2>&1 | grep --line-buffered -Ev "High Performance|written and copyright by|without any warranty but with best wishes|Terminal control enabled|MPEG 1.0|Decoding of" | sed -uE 's/Playing MPEG stream [0-9]+ of [0-9]+: //' | sed -uE "s/Directory: //" | sed -uE "s/\.\.\.//" | sed -uE '/^\s*$/d'

I'm going through the options step by step. Some of them answer the broader question of having a convenient mpg123 setup.

  • -Z is eternal random shuffle
  • -C allows for control commands
  • --title changes the terminal's title to the title of the current song
  • */* looks for files in current subdirectories. If the files are in a given directory, '*' would suffice.
  • 2>&1 redirects from standard error (to which mpg123 prints) to standard output, which can be manipulated using pipes
  • --line-buffered in grep and the -u flag on sed avoid buffering, which was what was causing me problems.
  • Other flags are just regex toggles and non-central to the question.

I then aliased this command for ease of use. alias pmr="clear; mpg123 -Z -C --title */* 2>&1 | grep --line-buffered -Ev 'High Performance|written and copyright by|without any warranty but with best wishes|Terminal control enabled|MPEG 1.0|Decoding of' | sed -uE 's/Playing MPEG stream [0-9]+ of [0-9]+: //' | sed -uE 's/Directory: //' | sed -uE 's/\.\.\.//' | sed -uE '/^\s*$/d'" ## pmr := play music recursively

tail has -f as a flag to avoid buffering, but it kept giving me problems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .