:: Sorting Online Radio Stations by Genre ::
Awhile back in this post I asked for some help getting my online radio playlist sorted by genre. I have had some limited success and would like to share the results.
As mentioned before, online radio stations from shoutcast and other sources usually contain many genres in different order in the %genre% tag so simply grouping by this tag is not a practical solution. What we need to do is parse the tag and place each station into predefined genre groups. After quite a bit of experimenting I whipped up this code to accomplish this:
$if($strstr($replace($lower(%genre%),', ',' '),goa),Goa,
$if($strstr($replace($lower(%genre%),', ',' '),trance),Trance,
$if($strstr($replace($lower(%genre%),', ',' '),techno),Trance,
$if($strstr($replace($lower(%genre%),', ',' '),anime),Anime,
$if($strstr($replace($lower(%genre%),', ',' '),japanimation),Anime,
$if($strstr($replace($lower(%genre%),', ',' '),jpop),JPop,
$if($strstr($replace($lower(%genre%),', ',' '),jrock),JPop,
$if($strstr($replace($lower(%genre%),', ',' '),japanese),JPop,
Other))))))))
On the end of each line you see on the left the word to search for in the %genre% tag (notice everything was sent to lower case because $strstr() is case sensitive) and on the right is the name of the predefined genre group. You'll need to create a line like this for every genre you want to group. Because of the nature of the cascading if statement, you'll want to place the most specific genres first. If a station would fit into more than one genre, it will be placed into the first category on the list (i.e.: "jpop anime" would be placed into the anime group). The last line is the name of the group where we lump all the stations that dont fit in one of our predefined groups and a bunch of end parenthesis to close the cascading if. If you add more lines for groups you'll need to make sure the parenthesis count increases accordingly.
The next major hurdle I came accross is that even though the above code will group consecutive playlist entries, it will not combine identical subgroups into one large group. In order to achieve proper grouping we need to sort the playlist. Unfortunately I could find no automated way to accomplish this, however we can manually choose Edit> Sort> Sort By... from the foobar menu and enter this variation of the above code:
$if($strstr($replace($lower(%genre%),', ',' '),goa),Goa,$if($strstr($replace($lower(%genre%),', ',' '),trance),Trance,$if($strstr($replace($lower(%genre%),', ',' '),techno),Trance,$if($strstr($replace($lower(%genre%),', ',' '),anime),Anime,$if($strstr($replace($lower(%genre%),', ',' '),japanimation),Anime,$if($strstr($replace($lower(%genre%),', ',' '),jpop),JPop,$if($strstr($replace($lower(%genre%),', ',' '),jrock),JPop,$if($strstr($replace($lower(%genre%),', ',' '),japanese),JPop,$char(255)))))))))|%codec%|$num($sub(1000,%bitrate%),3)
This is essentially the first chunk of code with the linebreaks removed and a few more parameters at the end to polish off the sorting.
---
Here is my current playlist setup for reference:
Row Height: 24
Group By:
$if($strcmp($left(%path%,7),http$char(58)$char(47)$char(47)),
$if($strstr($replace($lower(%genre%),', ',' '),goa),Goa,
$if($strstr($replace($lower(%genre%),', ',' '),trance),Trance,
$if($strstr($replace($lower(%genre%),', ',' '),techno),Trance,
$if($strstr($replace($lower(%genre%),', ',' '),anime),Anime,
$if($strstr($replace($lower(%genre%),', ',' '),japanimation),Anime,
$if($strstr($replace($lower(%genre%),', ',' '),jpop),JPop,
$if($strstr($replace($lower(%genre%),', ',' '),jrock),JPop,
$if($strstr($replace($lower(%genre%),', ',' '),japanese),JPop,
Other))))))))
,
$if(%tracknumber%,%album%%discnumber%,)
)
Item Display:
// Backgrounds
$ifequal($mod(%list_index%,2),0,
$if(%tracknumber%,
$drawrect(0,0,0,0,brushcolor-140-186-236 pencolor-null)
,
$drawrect(0,0,0,0,brushcolor-130-164-209 pencolor-null)
)
,)
$if(%cwb_queueindex%,$drawrect(0,0,0,0,brushcolor-58-110-165 pencolor-null),)
$if(%isplaying%,$drawrect(0,0,0,0,brushcolor-10-36-106 pencolor-null),)
$if(%_selected%,$drawrect(0,0,0,0,brushcolor-null pencolor-233-233-233),)
// Side Art
$puts(art.width,35)
$puts(art.height,128)
$puts(art.num,$add($div($mul(%list_index%,%_height%),$get(art.height)),1))
$puts(art.offset,-$sub($sub($mul(%list_index%,%_height%),$mul($sub($get(art.num),1),$get(art.height))),%_height%))
$imageabs(0,$get(art.offset),images\frames\dark stone\frame.left.png,)
$imageabs($sub(%_width%,$get(art.width)),$get(art.offset),images\frames\dark stone\frame.right.png,)
// Track Number
$padding(50,)
$align(left,middle)$font(tahoma,10,,)
$if(%tracknumber%,
$if(%isplaying%,$font(,,,233-233-233),$font(,,,10-36-106))
%tracknumber%$font(,,,233-233-233).
$if(%isplaying%,$font(,,,233-233-233),$font(,,,0-0-0))
// Title
$alignabs(75,,%_width%,%_height%,,)$font(tahoma,10,,)
$if(%title%,$trim($left(%title%,$sub($strrchr(%title%,$char(40)),1))),)
$if($strrchr(%title%,$char(40)),
$font(,,,233-233-233) $char(40)
$if(%isplaying%,$font(,,,233-233-233),$font(,,,10-36-106))
$substr(%title%,$add($strrchr(%title%,$char(40)),1),$sub($strrchr(%title%,$char(41)),1))
$font(,,,233-233-233)$char(41)
$if(%isplaying%,$font(,,,233-233-233),$font(,,,0-0-0))
)
,
$if(%isplaying%,$font(,,,233-233-233),$font(,,,0-0-0))
$if($strcmp($left(%path%,7),http$char(58)$char(47)$char(47)),
$align(left,top)$left(%title%,60)
,
$alignabs(50,,%_width%,%_height%,,)$font(tahoma,10,,)
[%artist% - ]%title%
)
)
// Subtext
$alignabs($if(%tracknumber%,75,50),14,%_width%,%_height%,,)$font(tahoma,7,,$if(%isplaying%,233-233-233,10-36-106))
$if($strcmp($left(%path%,7),http$char(58)$char(47)$char(47)),
$if2(%url%,%path%)
,
$if2(%codec% ,)$if2(%bitrate%kbps,)
)
// Queue Indicator
$font(tahoma,10,,)
$if(%cwb_queueindex%,
$alignabs($sub(%_width%,$calcwidth(%cwb_queueindexes%),150),,%_width%,%_height%,,)
$font(,,,233-233-233)Q
$if(%isplaying%,$font(,,,233-233-233),$font(,,,140-186-236)):
$font(,,,233-233-233)$char(91)$if(%isplaying%,$font(,,,233-233-233),$font(,,,140-186-236))%cwb_queueindexes%$char(47)%cwb_queuelength%$font(,,,233-233-233)$char(93)
$if(%isplaying%,$font(,,,233-233-233),$font(,,,0-0-0))
,)
// Length or Codec
$if($strcmp($left(%path%,7),http$char(58)$char(47)$char(47)),
$if(%bitrate%,$align(right,top),$align(right,middle))$font(tahoma,9,,$if(%isplaying%,233-233-233,0-0-0))
[%codec%]
$align(right,bottom)$font(tahoma,7,,$if(%isplaying%,233-233-233,10-36-106))
[%bitrate%kbps]
,
$align(right,middle)
$font(tahoma,10,,$if(%isplaying%,233-233-233,0-0-0))
%length%
)
Group Display:
$if($strcmp($left(%path%,7),http$char(58)$char(47)$char(47)),
$drawrect(0,0,0,0,brushcolor-0-0-0 pencolor-null)$padding(4,0)
$font(tahoma,7,,233-233-233)
$align(left,middle)
$align(left,middle)$font(tahoma,12,bold,140-186-236)↘ $font(tahoma,12,,233-233-233)
$if($strstr($replace($lower(%genre%),', ',' '),goa),Goa,
$if($strstr($replace($lower(%genre%),', ',' '),trance),Trance,
$if($strstr($replace($lower(%genre%),', ',' '),techno),Trance,
$if($strstr($replace($lower(%genre%),', ',' '),anime),Anime,
$if($strstr($replace($lower(%genre%),', ',' '),japanimation),Anime,
$if($strstr($replace($lower(%genre%),', ',' '),jpop),JPop,
$if($strstr($replace($lower(%genre%),', ',' '),jrock),JPop,
$if($strstr($replace($lower(%genre%),', ',' '),japanese),JPop,
Other))))))))
,
$if(%tracknumber%,
$drawrect(0,0,0,0,brushcolor-0-0-0 pencolor-null)$padding(4,0)
$font(tahoma,7,,233-233-233)
// Disc Number
//$if(%discnumber%,
//$align(center,bottom)
//$font(,,,233-233-233)$char(40)$font(,,,140-186-236)Disc %discnumber%[ of %totaldiscs%]$font(,,,233-233-233)$char(41)
//)
// Title
$align(left,middle)$font(tahoma,12,bold,140-186-236)↘ $font(tahoma,12,,233-233-233)
$if(%album artist%,
$if($strrchr(%album artist%,$char(12300)),
$font(,,,140-186-236)$char(12300)$font(,,,233-233-233)$substr(%album artist%,2,$sub($len(%album artist%),1))$font(,,,140-186-236)$char(12301)
,%album artist%)
,)
$if($and(%album artist%,%album%),$font(,,,140-186-236) - $font(,,,233-233-233),)
$trim($left(%album%,$sub($strrchr(%album%,$char(40)),1)))
// Genre & Year
$font(tahoma,7,,)
$align(right,top)[$char(91)$font(,,,140-186-236)[%genre%]$if($and(%genre%,%date%), - ,)[%date%]$font(,,,233-233-233)$char(93)]
// CDID
$align(right,bottom)$if(%CDID%,$char(91)$font(,,,140-186-236)%CDID%$font(,,,233-233-233)$char(93),)
,
$drawrect(0,0,0,0,brushcolor-166-202-240 pencolor-null)
$drawrect(0,4,0,4,brushcolor-140-186-236 pencolor-null)
$drawrect(0,10,0,4,brushcolor-130-164-209 pencolor-null)
$drawrect(0,$sub(%_height%,8),0,4,brushcolor-140-186-236 pencolor-null)
$align(center,middle)$font(tahoma,10,italic,0-0-0)
~ Singles ~
)
)
Images Used:
frame.top.left.png, frame.top.png, frame.top.right.png
frame.left.png, frame.right.png
frame.bottom.left.png, frame.bottom.png, frame.bottom.right.png
---
FEATURE REQUEST: I would like to request that this component add a field where we can enter a custom sort string, and then I would like for the component to automatically apply that sort any time the playlist changes.