2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

98_MediaList.pm: added sorting setting function,

default sort by filename



git-svn-id: https://svn.fhem.de/fhem/trunk@15000 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Tobias.Faust 2017-09-04 06:30:40 +00:00
parent 8328f3e37e
commit ec070262ff
2 changed files with 51 additions and 0 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- feature: 98_MediaList.pm: added sorting setting function,
default sort by filename
- feature: 10_pilight_ctrl: support protocol heitech
- feature: 91_sequence: add delay and omit name options (Forum #75925)
- bugfix: 74_AMADDevice: fix a lot of Bugs

View File

@ -82,6 +82,7 @@ sub MediaList_Initialize($)
"Playlist_Del" => { "count" => "1"}, #Arg: TrackNr
"Playlist_Empty" => { "count" => "0", "args" => "noArg"}, #Leeren
# "Playlist_Drop" => { "count" => "1"} #Loeschen, erst relevant wenn abgespeicherte Playlist
"SortBy" => { "count" => "1", "args" => "File,Title"}
);
}
@ -227,6 +228,18 @@ sub MediaList_Set($@)
MediaList_OnPlayPressed($hash, $par);
}
# sortiere Playlist nach Kriterien, zb. File, Title, Artist, etc
if($cmd eq "SortBy") {
return "sort criteria required: ". $sets{$cmd}{"args"} if (!$par);
my $json = ReadingsVal($me, "currentdir_playlist", "[]");
return "no currentdir_playlist available, please select one" if($json eq "[]");
$json = MediaList_playlist_sort($json, $par, "asc");
readingsSingleUpdate($hash, "currentdir_playlist", $json, 1);
return undef;
}
}
###########################################################################
@ -430,6 +443,8 @@ sub MediaList_done_playlistinfo($) {
delete($hash->{helper}{RUNNING_PID});
$playlist = MediaList_playlist_sort($playlist, "File", "asc"); # sortiere Playlist per default nach Dateinamen
my @data = @{JSON::XS->new->decode($playlist)};
for(my $j=0; $j<=$#data; $j++) {
$playlistduration += $data[$j]->{Time}
@ -705,6 +720,39 @@ sub MediaList_readingsSingleUpdateByName($$$) {
readingsSingleUpdate($defs{$devName}, $readingName, $readingVal, 1);
}
####################################
# die PlayList sortieren, Parameter
# 1. Hash
# 2. SortiTem: Filename, Title
# 3. order: asc, desc
####################################
sub MediaList_playlist_sort {
my ($json, $SortItem, $order) = @_;
my @t;
my @sortdata;
my @data = @{JSON::XS->new->decode($json)};
# Log3 undef, 1, "JSON: ".Dumper($json);
# Log3 undef, 1, "DATA: ".Dumper(@data);
for(my $j=0; $j<=$#data; $j++) {
push(@t, $data[$j]->{$SortItem});
}
@t = sort(@t);
@t = reverse @t if($order eq "desc");
for(my $i=0; $i<=$#t; $i++) {
for(my $j=0; $j<=$#data; $j++) {
if($t[$i] eq $data[$j]->{$SortItem}) {
push(@sortdata, $data[$j]);
}
}
}
return JSON::XS->new->encode(\@sortdata);
}
####################################
# CrawlerRoutine zur Navigation im
@ -795,6 +843,7 @@ sub MediaList_Crawl($$) {
Note: this module needs the following additional modules:<br>
<ul>
<li>libmp3-tag-perl</li>
<li>libjson-xs-perl</li>
<li>libmp3-info-perl</li>
<li>libmath-round-perl</li>