polybar / polybar-scripts

This is a community project. We write and collect scripts for polybar!
The Unlicense
2.49k stars 340 forks source link

player-cmus - position some times breaks the script #111

Closed maxdevjs closed 5 years ago

maxdevjs commented 5 years ago

99

Some times

cmus-remote -Q 2 "$info" | grep position | awk -F\  '{print $2}'

returns something similar to

23
comment

(23 being an example duration, followed by the word comment), which breaks the script outputting the name of the file. For what I understand, it happens when the archive has a comment beginning with \n, but without a tag comment.

When there is a tag comment, the script does not break and outputs a partial result (only artist, no title).

Some other times (with the tag comment or without it), the output is the expected.

x70b1 commented 5 years ago

Could you paste two complete outputs with that difference? We could look what we need to change in that script.

maxdevjs commented 5 years ago

Thank you for the quick reply. Three outputs, one for each case :)

Working output (complete):

$ cmus-remote -Q 2 "$info" | grep position | awk -F\  '{print $2}'
28

$ cmus-remote -Q 2 "$info"
...
duration 240
position 38
tag artist Brian Hogan
tag album 26 Days
tag title Put It In Drive
tag date 2011
tag tracknumber 3
tag comment Recorded in February 2011 for the RPM Challenge. All songs copyright 2011 Brian P. Hogan.
set aaa_mode all
set continue trueset play_library true
set play_sorted false
set replaygain disabled
set replaygain_limit true
set replaygain_preamp 0.000000
set repeat false
set repeat_current false
set shuffle false
set softvol false
set vol_left 20
set vol_right 20

Partially working output (shows artist):

$ cmus-remote -Q 2 "$info" | grep position | awk -F\  '{print $2}'6

$  cmus-remote -Q 2 "$info"
status paused
duration 159
position 6
tag artist bella coola
tag album Light Years To Be Lonely
tag title Light Years to Be Lonely
tag date 2007
tag genre FOLK: Folk Blues
tag tracknumber 1
tag albumartist Bella Coola
tag composer Angelika Antalova / Angelica Antaltag comment Bella Coola is a Canadian singer/songwriter and guitarist currently based in Central Europe. She enjoys writing and collaborating with international artists and is currently involved in many diverse musical projects. Smokey, understated vocals and percussive guitar playing inform most of her songs on this debut EP.  All of her songs from Light Years To Be Lonely were conceived in the previous century when she was still residing in British Columbia.   All songs are available as digital downloads.
tag replaygain_track_gain -9.2 dB
set aaa_mode all
set continue false
set play_library true
set play_sorted false
set replaygain disabled
set replaygain_limit true
set replaygain_preamp 0.000000
set repeat false
set repeat_current false
set shuffle false
set softvol false
set vol_left 20
set vol_right 20

Broken output (shows file path):

$ cmus-remote -Q 2 "$info" | grep position | awk -F\  '{print $2}'
7
comment

$ cmus-remote -Q 2 "$info"                                        
status paused
...
duration 262
position 7
tag artist Amanda Abizaid
tag album The Great Plan Vol. l
tag title Take It On Faith
tag date 2004
tag genre ROCK: Modern Rock
tag tracknumber 1
tag albumartist Amanda Abizaid
tag composer Amanda Abizaid, Shane Soloski
\nBorn in Beirut, Lebanon, AMANDA JO ABIZAID moved to The United States when she was nine years old.  She learned how to harmonize as a child by singing a wide range of music with her four older sisters. For many years, Amanda studied piano and flute with private teachers.  She continued to perfect her talents at The Catholic University of America, majoring in drama and music. She has also lived and modeled in Wash. D.C., New \nAmanda co-started and fronted the band "BLUE" that performed regularly in and around the Los Angeles area. Now as a solo artist, Amanda Abizaid performs her unique songs on piano and guitar and also with her band. Her original musical compositions include flute and violin parts that add an Arabian flavor to her poetic and classic songwriting: a mixture of sultry/soulful vocals and haunting melodies.  Her debut EP Album, "The Great Plan", Vol. I, was independently released last Summer 2004 and is sold internationally at www.CDBaby.com along with her first single "Lebanon", a song about the poli\nShe was the singing voice for Ally Sheady and Carisma Carpenter on VH1's show "STRANGE FREQUENCY", and has sung songs for WB's "CHARMED", "SUMMERLAND", "SMALLVILLE", Paramount's "THE 4400" (theme song, "A Place In Time"), and many more. Her feature film vocal and songwriting credits include,  "3 BELOW" and "FACING THE LION".  She performs regularly at Genghis Cohen, The Derby and Tangier Lounge in Los Angeles. She has just finished the follow up to "The Great Plan", Vol. II, which is set to be released this F\n3 Below- DITS                 3 Below, Fairlon Suite/writer & vocalist             S\nFacing The Lion-              Facing The Lion, Timeless/co-writer & vocalist       S\nThe Groomsmen-        featured/vocalist                                       Vision\nDevious Beings-       God Rest ye Merry Gentlemen, Come Alive/vocalist        Redbea\nOdd Girl Out-         Dreams In Ashes/vocalist                                Lifeti\nThe 4400      theme song- A Place In Time/vocalist                    Viacom/Paramou\nCharmed-s                     opening song, Not Gonna Drag Me Down/vocalist        W\nBig Man On Campus-    How Do I Make/vocalist                          Next Entertain\nOne Tree Hill-        At The E2 episodes/vocalist                             WB   W\nThe Division-         1 song/vocalist                                 Lifetime Netwo\nThat's Life-y CARISMA 3 episodes/vocalistlistvocalist,Viacom/VH1/Paramount EADViacom\nJC Penny-LS ctures    1 song/v1 song/vocalist                         WB      Boss H\nFelicity-                     1 song/vocalist                                 WB/Wad\nStephen Phillips & Tim P.-                                                    Boss H\nTom Gimbel-                                                           Aerosmith, For\nJennifer Stills-                                                              Three \nTaylor Mills- -                                       The Wallflowers,WilliamsBrian \nScott Bennett -                                                               Brian \nPepper Mashay-                                                                Jungle\nBird York -                                                                   Guided\nRoyal Caribbean Cruise Lines- Christmas CD                                    Wade H\nCarnival Cruise Lines- CD                                                     Wade H\nTaylor Daine-                                                         vocal demo
set aaa_mode all
set continue false
set play_library true
set play_sorted false
set replaygain disabled
set replaygain_limit true
set replaygain_preamp 0.000000
set repeat false
set repeat_current false
set shuffle false
set softvol false
set vol_left 20
set vol_right 20
x70b1 commented 5 years ago

The problem is that we are looking for the position with grep position. If you have now a string like that somewhere in your stream info you run into problems.

Look at this: Her original musical compositions include ...

You could try to use grep "position ". But this is more a workaround than a solution.

x70b1 commented 5 years ago

I rewrote the conditions. Can you test it?

maxdevjs commented 5 years ago

Thank you very much.

I quickly tested it and so far it works as intended. I will use it more in the next days and I will give you a more accurate feedback if I will find something.

x70b1 commented 5 years ago

Sounds good! :sunglasses: I will close this issue. Open another one if you find something bad.