rvp Isn't a diff being done in Mpc::update-queue to prevent this?

That's what I would have thought but nope, it would add the entire music library again creating a dupliate of every track.
I'll post the output of the commands tonight. Cheers 👍

JuvenalUrbino I was hoping that you would see this as you'd already posted about setting up mpd/mpc 😃

JuvenalUrbino You don't need to invoke bash for that. #!/bin/sh will be just fine :3.

Good to know!

I'll try your solution later tonight when I'm home. I'm suprised that the author of this tool hadn't considered this issue to begin with....

JuvenalUrbino From your past posts, It seems to me you're quite good at it

😅 Thank you for the kind words. I suppose, for someone with zero formal education in this feild, I have managed to pick up a thing or two over the years. UnitedBSD has sort of become my unofficial university and all of you kind folk are my tutors 😆

I just came here one day and started asking questions, half expecting to be told to go read the manual!. Instead I was greeted with helpful advice and friendly encouragement. I really owe a debt of gratitude to the whole community 🙏

JuvenalUrbino

function Mpc::clear-queue {
    [ -n "$(mpc queued)" ] || mpc clear &>/dev/null
}

This didn't seem to make any difference. I tried both setting clear_queue=true & clear_queue=false

rvp

mpc playlist --format '%file%' | sort

This command returns a list of the full queue. Eg. the contents of sub folders in ~/Music/band/album/... etc

~ $ mpc playlist --format '%file%' | sort
konpeito/konpeito-01/konpeito-01-a.mp3
konpeito/konpeito-01/konpeito-01-b.mp3
konpeito/konpeito-02/konpeito-02-a.mp3
konpeito/konpeito-02/konpeito-02-b.mp3
konpeito/konpeito-03/konpeito-03-a.mp3
konpeito/konpeito-03/konpeito-03-b.mp3
konpeito/konpeito-04/konpeito-04-a.mp3
konpeito/konpeito-04/konpeito-04-b.mp3
konpeito/konpeito-05/konpeito-05-a.mp3
konpeito/konpeito-05/konpeito-05-b.mp3
konpeito/konpeito-06/konpeito-06-a.mp3
...
...
...
etc

rvp

mpc ls --format '%file%' | sort

This command returned only the folders/directories inside ~/Music that contained music. Eg. I have a couple of empty folders that were ignored.

~ $ mpc ls --format '%file%' | sort
konpeito
nofx
sounds
~ $ ls Music/
konpeito
nofx
sounds
the swellers  
ytmdl

    pfr This didn't seem to make any difference. I tried both setting clear_queue=true & clear_queue=false

    Sorry, I replied to quickly without looking at your question properly. I thought you wanted to avoid clearing queue if it wasn't empty. But that's not the case.
    As RVP said, Mpc::update-queue is there to prevent duplicates, and from what I can see, it should just work fine. Possibly some of the changes you introduced in your fork are preventing the function from being executed and fmui defaults to adding the whole database?

    Anyway, I'll install it myself to see.

    • pfr replied to this.
    • pfr likes this.

      So, it works for me, it doesn't add duplicates while filling the queue.
      I cloned the the parent repo from seebye and tried to fix the script without looking at your fork.
      These are the only changes I applied to fmui:

      --- fmui.orig	2022-03-17 17:42:47.768665021 +0100
      +++ fmui	2022-03-17 17:47:45.564474791 +0100
      @@ -15,7 +15,7 @@
       # along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
       
       set -a # export everything
      -readonly PROJECT_ROOT=$(dirname `readlink --canonicalize "${BASH_SOURCE[0]}"`)
      +readonly PROJECT_ROOT=$(dirname `stat -f "${BASH_SOURCE[0]}"`)
       
       source "$PROJECT_ROOT/essentials.sh"
       source "$PROJECT_ROOT/defaults.sh"
      @@ -75,8 +75,8 @@
                   cmd="${data:1}"
       
               if [[ "${data:0:1}" == '(' ]]; then
      -                cmd=`grep --only-matching --perl-regexp "$PATTERN_OUTER_BRACKETS" <<<"$data" |
      -                            head --lines 1`
      +                cmd=`perl -nle'print $& while m{$PATTERN_OUTER_BRACKETS}g' <<<"$data" |
      +                            head -n 1`
                       cmd="${cmd:1:-1}"
                   fi
      

      I don't have ueberzug installed however, so I can test displaying covers.

      I then went to clone your fork and tested it. It works nonetheless as expected and doesn't add duplicates upon startup.

      In both cases I used the ~/.config/fmui/config you provided above.

      Maybe the problem lies elsewhere?

      • pfr likes this.

      p.s. this developer really tried their best to make a relatively short script linux-only.

      JuvenalUrbino Sorry, I replied to quickly without looking at your question properly. I thought you wanted to avoid clearing queue if it wasn't empty. But that's not the case.

      Essentially this is what I'm trying to do!
      Because, if the queue is populated and a track is playing I don't want the the queue to be cleared when starting fmui again to select a new track.
      However, the alternative is to have it NOT fill the queue if it is already populated. But the former is the preferred behaviour because if I add new music to my music dir then I want fmui to add the new tracks when it starts.

      Anyway, I tried again by cloning the parent repo and applying only your changes and it still acts the same. The only difference I had to your edits was, I used pcregrep instead of perl (in fmui as well as mpc.sh)

      if [[ "${data:0:1}" == '(' ]]; then
              cmd=`pcregrep --only-matching "$PATTERN_OUTER_BRACKETS" <<<"$data" |
                          head -n 1`
              cmd="${cmd:1:-1}"
          fi

      Also... do you not get this error?

      ~/fmui $ ./fmui
      head: unknown option -- -
      usage: head [-n lines] [file ...]
      head: unknown option -- -
      usage: head [-n lines] [file ...]
      head: unknown option -- -
      usage: head [-n lines] [file ...]

      The only additional changes I made was --lines to -n for both head & tail in mpc.sh as well as mkdir --parent to mkdir -p to mitigate these errors and to get the correct info preview.
      See below before and after:

      Anyway, this has nothing to do with the queuing function (I wouldn't think). These are the only other changes I made.

      I still cannot get it to ignore the clear_queue=true setting in the config when the queue is already populated.

      • rvp replied to this.

        pfr In function Mpc::update-queue (file mpc.sh) can you change mpc ls ... -> mpc listall ...

        The head errors mean that you've not changed --lines somewhere. Apply the patch below--it has all the changes that I had to make:

        diff -urN fmui-master.orig/cover.sh fmui-master/cover.sh
        --- fmui-master.orig/cover.sh	2019-01-18 01:32:21.000000000 +0000
        +++ fmui-master/cover.sh	2022-03-19 05:38:26.510340604 +0000
        @@ -49,7 +49,7 @@
         function Video::extract_random_frame {
             local max_width="$1" path_video="$2" path_image="$3"
             local duration="`ffmpeg -i "$path_video" 2>&1 | grep 'Duration: ' | \
        -                        grep --only-matching --perl-regexp '(\d+):(\d+):(\d+)'`"
        +                        pcregrep --only-matching '(\d+):(\d+):(\d+)'`"
             local hour="${duration:0:2}" minute="${duration:3:2}" second="${duration:6:2}"
             local seconds=$(( second + minute * 60 + hour * 60 * 60 ))
             ffmpeg -y -ss $(( ( (RANDOM<<15) | RANDOM ) % seconds + 0 )) \
        @@ -59,7 +59,7 @@
         
         
         function Music::contains_album_cover {
        -    ffprobe "$@" 2>&1 | grep --ignore-case 'Album cover' &>/dev/null
        +    ffprobe "$@" 2>&1 | egrep -qi -e 'Album cover' -e 'Stream #.*: Video: (m?jpeg|webp|png|bmp)'
         }
         
         
        @@ -113,7 +113,7 @@
             local path_output="${DIR_CACHE}/${1}-${width}-${filename//[^0-9a-zA-Z]/}.jpg"
         
             [ ! $IS_FILE "$path_output" ] && {
        -        mkdir --parents "$DIR_CACHE"
        +        mkdir -p "$DIR_CACHE"
                 Cover::create_image "$width" "$path_file" "$path_output"
             }
         
        diff -urN fmui-master.orig/fmui fmui-master/fmui
        --- fmui-master.orig/fmui	2019-01-18 01:32:21.000000000 +0000
        +++ fmui-master/fmui	2022-03-19 05:20:26.950139337 +0000
        @@ -15,7 +15,7 @@
         # along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
         
         set -a # export everything
        -readonly PROJECT_ROOT=$(dirname `readlink --canonicalize "${BASH_SOURCE[0]}"`)
        +readonly PROJECT_ROOT=$(dirname `readlink -f "${BASH_SOURCE[0]}"`)
         
         source "$PROJECT_ROOT/essentials.sh"
         source "$PROJECT_ROOT/defaults.sh"
        @@ -75,8 +75,8 @@
                     cmd="${data:1}"
         
                     if [[ "${data:0:1}" == '(' ]]; then
        -                cmd=`grep --only-matching --perl-regexp "$PATTERN_OUTER_BRACKETS" <<<"$data" |
        -                            head --lines 1`
        +                cmd=`pcregrep --only-matching "$PATTERN_OUTER_BRACKETS" <<<"$data" |
        +                            head -n 1`
                         cmd="${cmd:1:-1}"
                     fi
         
        diff -urN fmui-master.orig/mpc.sh fmui-master/mpc.sh
        --- fmui-master.orig/mpc.sh	2019-01-18 01:32:21.000000000 +0000
        +++ fmui-master/mpc.sh	2022-03-19 05:23:31.566733121 +0000
        @@ -18,21 +18,21 @@
         
         
         function Mpc::get_raw_song_info {
        -    mpc | grep --perl-regexp ']\s*#'
        +    mpc | pcregrep ']\s*#'
         }
         
         
         function Mpc::get_song_progress {
             Mpc::get_raw_song_info | \
        -        grep --only-matching --perl-regexp '(?<=\()[0-9]+(?=%)'
        +        pcregrep --only-matching '(?<=\()[0-9]+(?=%)'
         }
         
         
         function Mpc::get_song_duration {
             local duration=`mpc current --format "%time%"`
             local seconds=$(( 
        -        $(( 10#`grep --only-matching --perl-regexp '([0-9]+)(?=:)' <<< "$duration"` * 60 )) +
        -        10#`grep --only-matching --perl-regexp '(?<=:)([0-9]+)' <<< "$duration"` ))
        +        $(( 10#`pcregrep --only-matching '([0-9]+)(?=:)' <<< "$duration"` * 60 )) +
        +        10#`pcregrep --only-matching '(?<=:)([0-9]+)' <<< "$duration"` ))
             echo -n "${seconds:-1}"
         }
         
        @@ -43,7 +43,7 @@
         
         
         function Mpc::get_options {
        -    mpc | grep "volume" | sed 's|:\([^ ]\)|: \1|' | head --lines 1
        +    mpc | grep "volume" | sed 's|:\([^ ]\)|: \1|' | head -n 1
         }
         
         
        @@ -53,14 +53,14 @@
         
         
         function Mpc::get_playlist_filename {
        -    mpc playlist --format '%file%' | head --lines "$1" | tail --lines 1
        +    mpc playlist --format '%file%' | head -n "$1" | tail -n 1
         }
         
         
         function Mpc::update-queue {
             # adds every song to the queue if it's not already part of it
             diff --unchanged-group-format="" --new-group-format="%>" \
        -        <(mpc playlist --format '%file%' | sort) <(mpc ls --format '%file%' | sort) | \
        +        <(mpc playlist --format '%file%' | sort) <(mpc listall --format '%file%' | sort) | \
                 mpc add &>/dev/null
         }

          rvp In function Mpc::update-queue (file mpc.sh) can you change mpc ls ... -> mpc listall ...

          🙏 🙏 🙏 🙏 Thank you. It looks like this has solved the issue.

          rvp The head errors mean that you've not changed --lines somewhere.

          I had actually tracked down all of these, I was more just asking the question to JU as his edits did not include these. However, he also may not have noticed them if he has had not enabled the ueberzug cover option, something I still need to get working. I Don't get any errors anymore, but I still don't get and cover art displaying and I do have a working ueberzug installation. Anyway, I have a feeling it may be to do with the format in which my coverart is stored, I haven't really looked into it yet as I was just hoping to get the core functionality correct first.

          I'll report back later about this though.

            pfr In cover.sh can you change function Music::contains_album_cover to this:

            function Music::contains_album_cover {
                ffprobe "$@" 2>&1 | grep -qi -e 'Album cover' \
                    -e 'Stream .* (m?jpeg|webp|png|bmp) .*attached pic'
            }

            That works for the files that I have. If your album art is embedded differently, just add more -e patterns after looking through the ffprobe output.

              rvp you sir, are my savior! I had to change Album cover to just cover as that's how most are stored for me.
              Success!

              But, you say I can define multiple patterns. How would that look? something like this:

              function Music::contains_album_cover {
                  ffprobe "$@" 2>&1 | grep -qi -e 'Album cover' \
                      -e 'Stream .* (m?jpeg|webp|png|bmp) .*attached pic' \
                      -e 'cover' \
                      -e 'Album art'
              }
              • rvp replied to this.

                pfr you sir, are my savior!

                No, that's @pin. (I just like puzzles.)

                pfr something like this:

                Precisely. But try making the cover pattern more specific: it could occur in other contexts as well (in descriptions, for example).

                • pfr replied to this.
                • pfr likes this.

                  rvp No, that's @pin. (I just like puzzles.)

                  You are right. Without @pin I'd probably have given up on NetBSD entirely.

                  rvp try making the cover pattern more specific

                  Similar to the line you added for stream?

                  -e 'cover.* (m?jpeg|webp|png|bmp)' \

                  This begs the question, is the stream line necessary? Is that a common way to store album artwork? I'm note sure about hte .*attached pic either.

                  Cheers again

                  • rvp replied to this.
                  • Jay likes this.

                    pfr Similar to the line you added for stream?

                    As long as a song called "Discover" or "Recovery" isn't confused for album art ("cover") ...
                    Post the output of ffprobe on some of your files.

                    • pfr replied to this.
                    • pfr likes this.

                      rvp

                      Here is the output from a few files:

                      ~/Music/nofx/Single Album $ ffprobe Your\ Last\ Resort.mp3
                      [...]
                      Input #0, mp3, from 'Your Last Resort.mp3':
                        Metadata:
                          title           : Your Last Resort
                          artist          : NOFX
                          track           : 10
                          album           : Single Album
                          genre           : Punk
                          encoder         : Lavf58.76.100
                          TYER            : 2021-02-26T12:00:00Z
                        Duration: 00:03:59.23, start: 0.025056, bitrate: 358 kb/s
                        Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 320 kb/s
                          Metadata:
                            encoder         : Lavc58.13
                        Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 204
                          Metadata:
                            title           : Front cover
                            comment         : Cover (front)
                      ~/Music/nofx/Single Album $ ffprobe 01.1-NOFX-Scarlett_Oheroin.mp3
                      [...]
                      Input #0, mp3, from '01.1-NOFX-Scarlett_Oheroin.mp3':
                        Metadata:
                          track           : 1/2
                          Rip date        : 2019-08-13
                          title           : Scarlett O'Heroin
                          album           : 7 Inch Of The Month Club #01
                          Source          : Vinyl Single
                          Ripping tool    : EAC
                          Release type    : Normal
                          genre           : Punk
                          publisher       : Fat Wreck Chords
                          artist          : NOFX
                          date            : 2019-08-05
                          id3v2_priv.http://www.cdtag.com: \x02\x01\x1f\x1a\xc1\x00
                        Duration: 00:02:58.91, start: 0.025057, bitrate: 287 kb/s
                        Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 287 kb/s
                          Metadata:
                            encoder         : LAME3.100
                          Side data:
                            replaygain: track gain - -4.000000, track peak - unknown, album gain - unknown, album peak - unknown,
                      ~/Music/nofx/NOFX - 7 Inch Of The Month Club (2005) $ ffprobe 01-NOFX-Insulted_by_Germans_Again.mp3
                      [...]
                      Input #0, mp3, from '01-NOFX-Insulted_by_Germans_Again.mp3':
                        Metadata:
                          encoder         : Lavf58.76.100
                        Duration: 00:02:38.06, start: 0.023021, bitrate: 138 kb/s
                        Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 138 kb/s
                          Metadata:
                            encoder         : Lavc58.13
                      ~/Music/konpeito/konpeito-06 $ ffprobe konpeito-06-a.mp3
                      [...]
                      Input #0, mp3, from 'konpeito-06-a.mp3':
                        Metadata:
                          artist          : KONPEITO
                          comment         : gemini://konpeito.media
                          genre           : Lo-Fi
                          album           : Spring, 2021
                          title           : Side A
                          track           : 1
                          date            : 2021
                        Duration: 00:28:58.01, start: 0.023021, bitrate: 322 kb/s
                        Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 320 kb/s
                          Metadata:
                            encoder         : LAME3.100
                        Stream #0:1: Video: png, rgba(pc), 1200x1200, 90k tbr, 90k tbn, 90k tbc (attached pic)
                          Metadata:
                            title           : artwork.png
                            comment         : Cover (front)
                      • rvp replied to this.

                        pfr This seems to work for both my files & your output (2 with covers):

                        egrep -qi -e 'Album cover' -e 'Stream #.*: Video: (m?jpeg|webp|png|bmp)'
                        • pfr replied to this.
                        • pfr likes this.

                          pfr Try this (untested) patch (apply by hand if reqd.):

                          diff -urN fmui-master.orig/cover.sh fmui-master/cover.sh
                          --- fmui-master.orig/cover.sh	2022-03-25 00:14:06.284020000 +0000
                          +++ fmui-master/cover.sh	2022-03-25 00:18:58.397217000 +0000
                          @@ -77,8 +77,18 @@
                                       Video::extract_random_frame "$max_width" "$path_file" "$path_output"
                                       ;;
                                   audio/*)
                          -            Music::contains_album_cover "$path_file" && \
                          +            if Music::contains_album_cover "$path_file"; then
                                           Music::extract_album_cover "$max_width" "$path_file" "$path_output"
                          +            else
                          +                local found=false
                          +                for f in "${path_file%.*}".{jpg,jpeg,png,webp,bmp} \
                          +                  "$(dirname "$path_file")"/{C,c}over.{jpg,jpeg,png,webp,bmp}; do
                          +                    test -r "$f" && { path_file="$f"; found=true; break; }
                          +                done
                          +                if $found; then
                          +                    Music::extract_album_cover "$max_width" "$path_file" "$path_output"
                          +                fi
                          +            fi
                                       ;;
                               esac
                           }
                          • pfr replied to this.
                          • pfr likes this.

                            rvp
                            I get this:

                            ~/.git/github/fmui $ ./fmui
                            /home/dave/.git/github/fmui/cover.sh: line 91: syntax error near unexpected token `fi'
                            /home/dave/.git/github/fmui/cover.sh: line 91: `                fi'
                            /home/dave/.git/github/fmui/./fmui: line 96: Cover::stop_ueberzug: command not found
                            /home/dave/.git/github/fmui/./fmui: line 98: Cover::start_ueberzug: command not found
                            /home/dave/.git/github/fmui/./fmui: line 91: Cover::stop_ueberzug: command not found

                            And no cover images are being displayed now,

                            73 function Cover::create_image {
                            74     local max_width="$1" path_file="$2" path_output="$3"
                            75
                            76     case "`File::get_mime_type "$path_file"`" in
                            77         video/*)
                            78             Video::extract_random_frame "$max_width" "$path_file" "$path_output"
                            79             ;;
                            80         audio/*)
                            81             if Music::contains_album_cover "$path_file"; then
                            82                Music::extract_album_cover "$max_width" "$path_file" "$path_output"
                            83             else
                            84                 local found=false
                            85                 for f in "${path_file%.*}".{jpg,jpeg,png,webp,bmp} \
                            86                   "$(dirname "$path_file")"/{C,c}over.{jpg,jpeg,png,webp,bmp}; do
                            87                     test -r "$f" && { path_file="$f"; found=true; break; }
                            88                 done
                            89                 if $found
                            90                     Music::extract_album_cover "$max_width" "$path_file" "$path_output"
                            91                 fi
                            92             fi
                            93             ;;
                            94     esac
                            95 }
                            • rvp replied to this.

                              pfr I goofed: on line 89 add: ; then

                              • pfr replied to this.
                              • pfr likes this.