How to parse a m3u file with dmenu? (Solved)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
jplt3
Posts: 118
Joined: Mon 08 Apr 2019, 20:40
Location: Planet Earth

How to parse a m3u file with dmenu? (Solved)

#1 Post by jplt3 »

hi all,
i'am using dmenu a dynamic menu for X with dwm a tiling window manager ,
i want to parse a m3u file with dmenu !

here is my stations in radios.m3u

Code: Select all

#EXTM3U 
#EXTINF:-1,Funk Radio
http://server3.digital-webstream.de:12160
#EXTINF:-1,Funk Radio 2
http://radiomeuh.ice.infomaniak.ch/radiomeuh-128.mp3
#EXTINF:-1,Radio NOVA
http://broadcast.infomaniak.net/radionova-high.mp3

Code: Select all

cat radios.m3u | cut -d ',' -f2 | tail -n +2 | dmenu -l 20 -p "Radio:" | xargs -r mpv &
How to display just the name of the station and play the url ?

Thanks for your help.
Last edited by jplt3 on Mon 20 Jan 2020, 20:37, edited 1 time in total.
JpLt

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#2 Post by technosaurus »

Ok, going from memory here typing on a phone, so beware of syntax, but it may simplify things

Code: Select all

while read Line; do
case $Line in
"#"*)continue;; #ignore comments
*)IFS=:      #use colon as separators
  set $Line  #put "fields" into numbered variables
  echo cell 1 is $1, cell 2 is $2, etc...
  ;;
esac
done < path/to/myfile
Edit: nevermind, I read it wrong. This would be simple in awk, but I don't have all of the syntax memorized. Essentially you would set the record separator (RS I think) to "\n#EXTINF:-1," and the field separator to (IFS I think) to "\n" .... then $1 is the category and $2 is the url
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
jplt3
Posts: 118
Joined: Mon 08 Apr 2019, 20:40
Location: Planet Earth

#3 Post by jplt3 »

I found this solution that i found in another forum and it works like i want :

Code: Select all

#!/bin/sh
radio=radio.m3u
choice=$(awk -F ','  '{print $2}' "$radio" | awk 'NF{print}' | dmenu -l 20 -p "Radio:")
mpv $(sed -n "/$choice/{n;p;}" "$radio")
I'am not a coder ! but i really have to learn awk,sed,cut,etc.....

Thanks technosaurus.
JpLt

Post Reply