uriel1998 / mpdq

Automatic MPD "smart playlist" creator with minimal but hackable setup.
https://uriel1998.github.io/mpdq/
MIT License
23 stars 5 forks source link

Errors! unary operator error 495, sed errors. #9

Open iconoclasthero opened 6 months ago

iconoclasthero commented 6 months ago
$ mpdqcfg="$XDG_CONFIG_HOME/mpdq"
$ [[ -f "$mpdqcfg/mpdq.ini" ]] && echo "mpdq.ini exists" && [[ -f "$mpdqcfg/default.cfg" ]] && echo "default.cfg exists"
mpdq.ini exists
default.cfg exists

$ python3 --version; uname -a; ./mpdq --version
Python 3.10.12
Linux gigabyte 6.5.0-21-generic #21~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb  9 13:32:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

$ cat "$XDG_CONFIG_HOME/mpdq/mpdq.ini"|sed 's/mpdpass=.*/mpdpass=[-redacted-]/'; [[ -d /library/music ]] && echo "musicdir exists" ; which ffprobe; \mpc -p 6600 -h localhost stats; \mpc
[SERVER]
musicdir=/library/music
mpdserver=localhost
mpdport=6600
mpdpass=[-redacted-]
songlength=15
queuesize=10
# in hours
rotate_time=1
# in minutes
album_mins=30
artist_mins=30
# Genres to exclude from the above two checks
genres_exclude_album_check=Sound Clip,Classical
musicinfo=/usr/bin/ffprobe
musicdir exists
/usr/local/bin/ffprobe
/usr/bin/ffprobe
/bin/ffprobe
Artists:   5473
Albums:    3737
Songs:    62381

Play Time:    0 days, 0:32:59
Uptime:       0 days, 0:53:02
DB Updated:   Fri Mar  1 08:07:05 2024
DB Play Time: 195 days, 8:01:36
volume: n/a   repeat: off   random: off   single: off   consume: on 
 $ head $mpdqcfg/default.cfg
=1
(Ninguno)=1
2-Step, Downtempo, Electronic, Future Garage, House; Electronic Music; Electronica=1
A Capella Pop=1
A Cappella=1
A Cappella; Country Blues, Folk; Gospel Music=1
A Cappella; Western Classical Music=1
AOR Classic Rock=1
Acid House, Alternative Rock, Downtempo, Dub, Dub Techno; Alternative Rock=1
Acid House, Alternative Rock, Downtempo, Dub, Pop; Alternative Rock=1
$ ./mpdq -c "$mpdqcfg/mpdq.ini" --loud &>> /cache/mpdq.error &
$ cat /cache/mpdq.error 
Loading instruction file commands
sed: -e expression #1, char 0: no previous regular expression
Adding :
./mpdq: line 495: [: 1: unary operator expected
Adding :(Ninguno)
./mpdq: line 495: [: 1: unary operator expected
Adding :2-Step, Downtempo, Electronic, Future Garage, House; Electronic Music; Electronica
./mpdq: line 495: [: 1: unary operator expected
Adding :A Capella Pop
./mpdq: line 495: [: 1: unary operator expected
Adding :A Cappella
./mpdq: line 495: [: 1: unary operator expected
Adding :A Cappella; Country Blues, Folk; Gospel Music
./mpdq: line 495: [: 1: unary operator expected
Adding :A Cappella; Western Classical Music
./mpdq: line 495: [: 1: unary operator expected
Adding :AOR Classic Rock
./mpdq: line 495: [: 1: unary operator expected
⋮
Eliminating song log entries older than 1 hours.
Using instruction file at /home/bvargo/.config/mpdq/default.cfg
Search run 1 of 2475
Examining Hip Hop Music; Pop, Pop Rock, Rock
Default 1 :: Played 1 :: Weight 1
Used up Hip Hop Music; Pop, Pop Rock, Rock
Iteration!
Search run 2 of 2475
Examining Pop Music; Pop Rock, Soft Rock
Default 1 :: Played 2 :: Weight 1
Used up Pop Music; Pop Rock, Soft Rock
Iteration!
Search run 3 of 2475
Examining Funk, Pop, Rock, Rock And Roll, Soul
Default 1 :: Played 1 :: Weight 1
Used up Funk, Pop, Rock, Rock And Roll, Soul
Iteration!
⋮
Search run 32 of 2475
Examining Soul, R&B, funk, hip hop
Default 1 :: Played 1 :: Weight 1
Used up Soul, R&B, funk, hip hop
Iteration!
Search run 33 of 2475
Examining Rock / Pop
sed: -e expression #1, char 10: extra characters after command
sed: -e expression #1, char 10: extra characters after command
Default 1 :: Played 0 :: Weight 1
Adding song from Mark Knopfler by Mark Knopfler in the Rock / Pop genre.
[1]+  Done                    ./mpdq -c $XDG_CONFIG_HOME/mpdq/mpdq.ini --loud &>> /cache/mpdq.error
 cat mpdq.error |grep sed|head -40
sed: -e expression #1, char 0: no previous regular expression
sed: -e expression #1, char 19: extra characters after command
sed: -e expression #1, char 23: unknown command: `S'
sed: -e expression #1, char 22: extra characters after command
sed: -e expression #1, char 16: extra characters after command
sed: -e expression #1, char 31: unknown command: `S'
sed: -e expression #1, char 11: extra characters after command
sed: -e expression #1, char 9: extra characters after command
sed: -e expression #1, char 42: unknown command: `S'
sed: -e expression #1, char 29: unknown command: `S'
sed: -e expression #1, char 9: unknown command: `S'
sed: -e expression #1, char 20: unknown command: `S'
sed: -e expression #1, char 9: unknown command: `S'
sed: -e expression #1, char 14: unknown command: `B'
sed: -e expression #1, char 12: extra characters after command
sed: -e expression #1, char 12: extra characters after command
sed: -e expression #1, char 25: extra characters after command
sed: -e expression #1, char 22: extra characters after command
sed: -e expression #1, char 6: unknown command: `S'
sed: -e expression #1, char 7: unknown command: `S'
sed: -e expression #1, char 10: extra characters after command
sed: -e expression #1, char 10: extra characters after command
sed: -e expression #1, char 7: unknown command: `E'
sed: -e expression #1, char 8: extra characters after command
sed: -e expression #1, char 8: extra characters after command
sed: -e expression #1, char 9: unknown command: `S'
sed: -e expression #1, char 9: unknown command: `S'
sed: -e expression #1, char 9: unknown command: `B'
sed: -e expression #1, char 0: no previous regular expression
sed: -e expression #1, char 0: no previous regular expression
Used up 
sed: -e expression #1, char 0: no previous regular expression
sed: -e expression #1, char 0: no previous regular expression
Used up 
sed: -e expression #1, char 0: no previous regular expression
sed: -e expression #1, char 0: no previous regular expre
iconoclasthero commented 6 months ago

The unary operator error is related to the definition of the config file. I can get rid of it by hard coding the default.cfg file ca. line 473:

InstructionFile="/home/user/.config/mpdq/default.cfg"
$ head /cache/mpdq.errors
!4566 bvargo@gigabyte$ cat /cache/mpdq.error |more
/home/bvargo/.config/mpdq/default.cfg
Loading instruction file commands
sed: -e expression #1, char 0: no previous regular expression
Adding 1:
Adding 1:(Ninguno)
Adding 1:2-Step, Downtempo, Electronic, Future Garage, House; Electronic Music; Electronica
Adding 1:A Capella Pop
Adding 1:A Cappella
Adding 1:A Cappella; Country Blues, Folk; Gospel Music
Adding 1:A Cappella; Western Classical Music
Adding 1:AOR Classic Rock
Adding 1:Acid House, Alternative Rock, Downtempo, Dub, Dub Techno; Alternative Rock
Adding 1:Acid House, Alternative Rock, Downtempo, Dub, Pop; Alternative Rock
Adding 1:Acid House, Alternative Rock, Downtempo, Dub, Rock; Alternative Rock; Pop Music
Adding 1:Acid House, Alternative Rock, Electronic, House, Rock; Alternative Rock
Adding 1:Acid House, Alternative Rock, Electronic, Pop, Rock; Alternative Rock
Adding 1:Acid House, Alternative Rock, Indie Rock, Psychedelic Rock, Rock; Alternative Rock
Adding 1:Acid House, Garage Rock, Indie Rock, Pop Rock, Rock; Alternative Rock
Adding 1:Acid House; Acid House, Alternative Rock, Electronic, House, Rock; Alternative Dance; Alternativ
e Rock; Dance-Rock; Electronica; House Music; Indie Pop; Neo-Psychedelia; Psychedelic Rock
Adding 1:Acid House; Acid House, Electronic, Experimental, House, Rock; Alternative Dance; Alternative Ro
ck; Dance-Rock; Electronica; House Music; Indie Pop; Neo-Psychedelia; Psychedelic Rock
Adding 1:Acid House; Acid House, Electronic, House, Rock; Alternative Dance; Alternative Rock; Dance-Rock
; Electronica; House Music; Indie Pop; Neo-Psychedelia; Psychedelic Rock

Here's what the change looks like in context, I subbed in $HOME. The last line below is where your unary operator error is coming from which means that the instruction file is not being read to the CurrWeight or DefaultPriority isn't being set or...

$ cat mpdq2 |head -500|tail -35

if [ ! -f "${InstructionFile}" ];then
    if [ -f "${ConfigDir}/default.cfg" ];then
        InstructionFile="${ConfigDir}/default.cfg"
    fi
fi

InstructionFile="/home/bvargo/.config/mpdq/default.cfg"
echo "$InstructionFile"

if [ -f "${InstructionFile}" ];then
    DefaultPriority=$(${grep_bin} -e "Default=" "${InstructionFile}" | cut -d = -f 2-)
fi

loud "Loading instruction file commands"
# go through list of genres from mpc/mpd
while read -r line; do
    # is it in our instruction file?
    CG="${line}"
    InInstruction=$(sed -n /"${CG}"/p "${InstructionFile}" "${InstructionFile}" | wc -l)

    if [ ${InInstruction} -eq 0 ];then
        # if not, weight=default
        CurrWeight=${DefaultPriority}
    else
        # if so, weight=value from instruction file
        CurrWeight=$(sed -n /^"${CG}="/p "${InstructionFile}" | cut -d = -f 2-)
    fi
    i=1
    # adds genre name to the array a number of times equal to the weight, so the RNG
    # has more of a chance to select it.
    loud "Adding ${CurrWeight}:${CG}"
    while [ $i -le $CurrWeight ];do
iconoclasthero commented 6 months ago

Beyond the issues above, I have some questions to which I have not found sufficient answers to in the documentation or blog posts. Namely:

1) It appears that mpdq reads through my entire library every time it runs? Can this be cached?

2) When I look at the loud output, what is going on here where it terminates?

Search run 33 of 2475
Examining Rock / Pop
sed: -e expression #1, char 10: extra characters after command
sed: -e expression #1, char 10: extra characters after command
Default 1 :: Played 0 :: Weight 1
Adding song from Mark Knopfler by Mark Knopfler in the Rock / Pop genre.

Aside from the sed issues addressed before, it appears that it is supposed to run 2500 iterations and stops after 33 without any explanation. I can assume that is because of the queue size?

3) For better or worse, my genres were set by Picard from MBDB info (and thus should be rather standardized for parsing) the last time tags were written. I'm looking at the following and simply cannot figure out what this is actually saying... Does this mean that the genres aren't parsed by , or ; ? What good does it do me to have categories such as:

⋮
Funk; Funk, Gospel, Jam Band, Sacred Steel, Soul=1
Funk; Funk, Gospel, Jam Band, Sacred Steel, Soul; Southern Rock=1
Funk; Funk, Jam Band=1
Funk; Funk, Pop, R&B, Soul; Pop Rock; Psychedelic Soul; Rhythm And Blues; Rock Music; Soul Music=1
Funk; Funk, Psychedelic Soul, R&B, Soul; Pop Rock; Psychedelic Soul; Rhythm And Blues; Rock Music; Soul Music=1
Funk; Funk, Psychedelic Soul, Soul; Pop Rock; Psychedelic Soul; Rhythm And Blues; Rock Music; Soul Music=1
Funk; Funk, R&B, Soul; Jazz; Rock Music; Soul Music=1
Funk; Funk, R&B, Soul; Soul Music=1
Funk; Funk, Soul=1
⋮
iconoclasthero commented 6 months ago

While we're at it, how about a flag to include what file was just cataloged in that --loud output?

Edit: That comes from mpc list genre? I guess not.

iconoclasthero commented 6 months ago

I got the list of genres down

$ cat /cache/genres.txt |sort|uniq|wc -l ; ./genres; cat ./genres
2475
593
#!/bin/bash

[[ ! -f /cache/genres.txt ]] && mpc list genre > /cache/genres.txt

rm /cache/split.txt

exec 3<> /cache/genres.txt

while read -r line
  do
    i="$line"
   sed 's/[;,] /\n/g' <<< "$i" >> /cache/split.txt
done <&3

cat /cache/split.txt|sort|uniq|wc -l