forked from squentin/gmusicbrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmusicbrowser_songs.pm
5584 lines (5361 loc) · 206 KB
/
gmusicbrowser_songs.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2005-2015 Quentin Sculo <squentin@free.fr>
#
# This file is part of Gmusicbrowser.
# Gmusicbrowser is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
use strict;
use warnings;
use utf8;
package Songs;
#our %Songs;
our ($IDFromFile,$MissingHash); my $KeepIDFromFile;
our ($Artists_split_re,$Artists_title_re,$Articles_re);
my @MissingKeyFields;
our (%Def,%Types,%Categories,%FieldTemplates,@Fields,%HSort,%Aliases);
my %FuncCache;
INIT {
our $nan= unpack 'F', pack('F',sin(9**9**9)); # sin 9**9**9 is slighly more portable than $nan="nan", use unpack pack because the nan will be stored that way
our %timespan_menu=
( year => _("year"),
month => _("month"),
day => _("day"),
);
@MissingKeyFields=qw/size title album artist track/;
%Categories=
( file => [_"File properties",10],
audio => [_"Audio properties",30],
basic => [_"Basic fields",20],
extra => [_"Extra fields",50],
stats => [_"Statistics",40],
unknown => [_"Other",80], #fallback category
custom => [_"Custom",70],
replaygain=> [_"Replaygain",60],
);
%Types=
( generic =>
{ _ => '____[#ID#]',
get => '#_#',
set => '#get# = #VAL#',
display => '#get#',
grouptitle=> '#display#',
'editwidget:many' => sub { my $field=$_[0]; GMB::TagEdit::Combo->new(@_, Field_property($field,'edit_listall')); },
'editwidget:single' => sub { my $field=$_[0]; GMB::TagEdit::EntryString->new( @_,0,Field_property($field,'edit_listall') ); },
'editwidget:per_id' => sub { my $field=$_[0]; GMB::TagEdit::EntryString->new( @_,Field_properties($field,'editwidth','edit_listall') ); },
'filter:m' => '#display# .=~. m"#VAL#"', 'filter_prep:m' => \&Filter::QuoteRegEx,
'filter:mi' => '::superlc(#display#) .=~. m"#VAL#"i', 'filter_prep:mi'=> sub { Filter::QuoteRegEx( ::superlc($_[0]) )},
'filter:si' => 'index( ::superlc(#display#),"#VAL#") .!=. -1', 'filter_prep:si'=> sub {quotemeta ::superlc($_[0])},
'filter:s' => 'index( #display#, "#VAL#") .!=. -1', 'filter_prep:s'=> sub {quotemeta $_[0]},
'filter:fuzzy' => '.!!. Filter::_fuzzy_match(#VAL1#/100,"#VAL2#",lc(#get#))', 'filter_prep:fuzzy'=> sub {my @arg=split / /,$_[0],2; $arg[0],quotemeta lc($arg[1])},
'filterpat:fuzzy'=> [ round => "%d", unit => '%', min=>20, max=>99, default_value=>65, ],
'filterdesc:fuzzy'=> [ _"%s fuzzy match with %s",_"fuzzy match", 'fuzzy string', ],
'filterdesc:-fuzzy'=> _"no %s fuzzy match with %s",
'filterdesc:mi' => [ _"matches regexp %s",_"matches regexp",'regexp', icase=>1, ],
'filterdesc:si' => [ _"contains %s", _"contains", 'substring', icase=>1, ],
'filterdesc:e' => [ _"is equal to %s", _"is equal to", 'string', completion=>1, ],
'filterdesc:m' => [_"matches regexp %s (case sensitive)",'mi'],
'filterdesc:s' => [_"contains %s (case sensitive)", 'si'],
'filterdesc:-m' => _"doesn't match regexp %s (case sensitive)",
'filterdesc:-mi'=> _"doesn't match regexp %s",
'filterdesc:-s' => _"doesn't contain %s (case sensitive)",
'filterdesc:-si'=> _"doesn't contain %s",
'filterdesc:-e' => _"isn't equal to %s",
'smartfilter:=empty' => 'e:',
'smartfilter:=' => 'e',
'smartfilter:#' => \&Filter::smartstring_fuzzy,
'smartfilter::' => 'si s',
'smartfilter:~' => 'mi m',
default_filter => 'si',
autofill_re => '.+',
},
unknown =>
{ parent => 'generic',
},
virtual =>
{ parent => 'string',
_ => '#get#',
},
special => {},
flags =>
{ _ => '____[#ID#]',
init => '___name[0]="#none#"; ___iname[0]=::superlc(___name[0]); #sgid_to_gid(VAL=$_)# for #init_namearray#',
init_namearray => '@{ $::Options{Fields_options}{#field#}{persistent_values} ||= $Def{#field#}{default_persistent_values} || [] }',
none => quotemeta _"None",
default => '""',
check => '#VAL#= do {my $v=#VAL#; my @l; if (ref $v) {@l= @$v} else {@l= split /\x00/,$v} for (@l) { tr/\x00-\x1F//d; s/\s+$//; }; @l=sort @l; \@l }',
get_list => 'my $v=#_#; ref $v ? map(___name[$_], @$v) : $v ? ___name[$v] : ();',
get_gid => 'my $v=#_#; ref $v ? $v : [$v]',
gid_to_get => '(#GID# ? ___name[#GID#] : "")',
gid_to_display => '___name[#GID#]',
s_sort => '___sort{ sprintf("%x", #_#)}',
si_sort => '___isort{ sprintf("%x", #_#)}',
always_first_gid=> 0,
's_sort:gid' => '___name[#GID#]',
'si_sort:gid' => '___iname[#GID#]',
get => 'do {my $v=#_#; !$v ? "" : ref $v ? join "\\x00",map ___name[$_],@$v : ___name[$v];}',
newval => 'push @___iname, ::superlc(___name[-1]); ::IdleDo("newgids_#field#",1000,sub { ___new=0; ::HasChanged("newgids_#field#"); }) unless ___new++;',
sgid_to_gid => '___gid{#VAL#}||= do { my $i=push(@___name, #VAL#); #newval#; $i-1; }',
set => '{my $v=#VAL#;
my @list= sort (ref $v ? @$v : split /\\x00/,$v);
my @ids;
for my $name (@list)
{ my $id= #sgid_to_gid(VAL=$name)#;
push @ids,$id;
}
my $val= @ids<2 ? $ids[0]||0 :
(___group{join(" ",map sprintf("%x",$_),@ids)}||= \@ids);
___isort{ sprintf("%x",$val) }||= ::superlc( ___sort{ sprintf("%x",$val) }||= join ";",@list );
#_#=$val;
}',
diff => 'do {my $v=#_#; my $old=!$v ? "" : ref $v ? join "\\x00",map ___name[$_],@$v : ___name[$v]; $v=#VAL#; my $new= join "\\x00", @$v; $old ne $new; }', # #VAL# should be a sorted arrayref, as returned by #check#
display => 'do { my $v=#_#; !$v ? "" : ref $v ? join ", ",map ___name[$_],@$v : ___name[$v]; }',
check_multi => 'for my $lref (@{#VAL#}) { for (@$lref) {tr/\x00-\x1F//d; s/\s+$//;} }',
set_multi => 'do {my $c=#_#; my %h=( $c ? ref $c ? map((___name[$_]=>0), @$c) : (___name[$c]=>0) : ()); my ($toadd,$torm,$toggle)=@{#VAL#}; $h{$_}= (exists $h{$_} ? -1 : 1) for @$toggle; $h{$_}++ for @$toadd; $h{$_}-- for @$torm; (scalar grep $h{$_}!=0, keys %h) ? [grep $h{$_}>=0, keys %h] : undef; }',
makefilter => '#GID# ? "#field#:~:".___name[#GID#] : "#field#:ecount:0"',
'filter:~' => '.!!. do {my $v=#_#; $v ? ref $v ? grep(#VAL#==$_, @$v) : ($v == #VAL#) : 0}',
#smartmatch version: 'filter:~' => '.!!. do {my $v=#_#; $v ? #VAL# ~~ $v : 0}', # is flag set
'filter_prep:~' => '___gid{#PAT#} ||= #sgid_to_gid(VAL=#PAT#)#;',
'filter_prephash:~' => 'return { map { #sgid_to_gid(VAL=$_)#, undef } keys %{#HREF#} }',
'filter:h~' => '.!!. do {my $v=#_#; $v ? ref $v ? grep(exists $hash#VAL#->{$_+0}, @$v) : (exists $hash#VAL#->{#_#+0}) : 0}',
'filter:ecount' => '#VAL# .==. do {my $v=#_#; $v ? ref $v ? scalar(@$v) : 1 : 0}',
#FIXME for filters s,m,mi,h~, using a list of matching names in ___inames/___names could be better (using a bitstring)
'filter:s' => 'do { my $v=#_#; !$v ? .0. : ref $v ? (.!!. grep index(___name[$_], "#VAL#") != -1 ,@$v) : (index(___name[$v], "#VAL#") .!=. -1); }',
'filter:si' => 'do { my $v=#_#; !$v ? .0. : ref $v ? (.!!. grep index(___iname[$_], "#VAL#") != -1 ,@$v) : (index(___iname[$v], "#VAL#") .!=. -1); }',
'filter:fuzzy' => 'do { my $v=#_#; !$v ? .0. : ref $v ? (.!!. ::first {Filter::_fuzzy_match(#VAL1#/100,"#VAL2#",___iname[$_])} @$v) : .!!. Filter::_fuzzy_match(#VAL1#/100,"#VAL2#",___iname[$v]); }',
'filter:m' => 'do { my $v=#_#; !$v ? .0. : ref $v ? (.!!. grep ___name[$_] =~ m"#VAL#" ,@$v) : ___name[$v] .=~. m"#VAL#"; }',
'filter:mi' => 'do { my $v=#_#; !$v ? .0. : ref $v ? (.!!. grep ___iname[$_] =~ m"#VAL#"i ,@$v) : ___iname[$v] .=~. m"#VAL#"i; }',
'filter_prep:m' => \&Filter::QuoteRegEx,
'filter_prep:mi'=> sub { Filter::QuoteRegEx( ::superlc($_[0]) )},
'filter_prep:si'=> sub {quotemeta ::superlc($_[0])},
'filter_prep:s' => sub {quotemeta $_[0]},
'filter_prep:fuzzy'=>sub {my @arg=split / /,$_[0],2; $arg[0],quotemeta ::superlc($arg[1])},
stats => 'do {my $v=#_#; #HVAL#{$_+0}=undef for ref $v ? @$v : $v;} ---- AFTER: #HVAL#=[map ___name[$_], keys %{#HVAL#}];',
'stats:gid' => 'do {my $v=#_#; #HVAL#{$_+0}=undef for ref $v ? @$v : $v;}',
hashm => 'do {my $v=#_#; ref $v ? @$v : $v }',
'hashm:name' => 'do {my $v=#_#; ref $v ? map(___name[$_], @$v) : $v ? ___name[$v] : () }',
is_set => 'my $gid=___gid{#VAL#}; my $v=#_#; $gid ? ref $v ? (grep $_==$gid, @$v) : $v==$gid : 0;',
#smartmatch version : is_set => 'my $gid=___gid{#VAL#}; my $v=#_#; $gid ? $gid ~~ $v : 0;',
listall => '1..$#___name',
'editwidget:many' => sub { GMB::TagEdit::EntryMassList->new(@_) },
'editwidget:single' => sub { GMB::TagEdit::FlagList->new(@_) },
'editwidget:per_id' => sub { GMB::TagEdit::FlagList->new(@_) },
autofill_re => '.+',
'filterdesc:~' => [ _"includes %s", _"includes", 'combostring', ],
'filterdesc:-~' => _"doesn't include %s",
'filterdesc:ecount:0' => _"has none",
'filterdesc:-ecount:0'=> _"has at least one",
'filterdesc:mi' => [ _"matches regexp %s",_"matches regexp",'regexp', icase=>1, ],
'filterdesc:si' => [ _"contains %s", _"contains", 'substring', icase=>1, ],
'filterdesc:m' => [_"matches regexp %s (case sensitive)",'mi'],
'filterdesc:s' => [_"contains %s (case sensitive)", 'si'],
'filterdesc:-m' => _"doesn't match regexp %s (case sensitive)",
'filterdesc:-mi'=> _"doesn't match regexp %s",
'filterdesc:-s' => _"doesn't contain %s (case sensitive)",
'filterdesc:-si'=> _"doesn't contain %s",
'filterdesc:fuzzy'=> [ _"%s fuzzy match with %s",_"fuzzy match", 'fuzzy string', ],
'filterdesc:-fuzzy'=> _"no %s fuzzy match with %s",
'smartfilter:=empty' => 'ecount:0',
'smartfilter:=' => '~',
'smartfilter::' => 'si s',
'smartfilter:~' => 'mi m',
'smartfilter:#' => \&Filter::smartstring_fuzzy,
'filterpat:fuzzy'=> [ round => "%d", unit => '%', min=>20, max=>99, default_value=>65, ],
default_filter => 'si',
load_extra => '___gid{#SGID#} || return;',
save_extra => 'my %h; while ( my ($sgid,$gid)=each %___gid ) { $h{$sgid}= [#SUBFIELDS#] } delete $h{""}; return \%h;',
},
artists =>
{ _ => '____[#ID#]',
mainfield => 'artist',
#plugin => 'picture',
# _name => '__#mainfield#_name[#_#]',
# _iname => '__#mainfield#_iname[#_#]',
get => 'do {my $v=#_#; ref $v ? join "\\x00",map __#mainfield#_name[$_],@$v : __#mainfield#_name[$v];}',
display => 'do {my $v=#_#; ref $v ? join ", ", map __#mainfield#_name[$_],@$v : __#mainfield#_name[$v];}',
get_gid => 'my $v=#_#; ref $v ? $v : [$v]',
's_sort:gid' => '__#mainfield#_name[#GID#]',
'si_sort:gid' => '__#mainfield#_iname[#GID#]',
#display => '##mainfield#->display#',
get_list => 'my @l=( ##mainfield#->get#, grep(defined, #title->get# =~ m/$Artists_title_re/g) ); my %h; grep !$h{$_}++, map split(/$Artists_split_re/), @l;',
gid_to_get => '(#GID#!=1 ? __#mainfield#_name[#GID#] : "")', # or just '__#mainfield#_name[#GID#]' ?
gid_to_display => '__#mainfield#_name[#GID#]',
update => 'my @ids;
for my $name (do{ #get_list# })
{ my $id= ##mainfield#->sgid_to_gid(VAL=$name)#;
push @ids,$id;
}
#_# = @ids==1 ? $ids[0] :
@ids==0 ? 1 :
(___group{join(" ",map sprintf("%x",$_),@ids)}||= \@ids);', # 1 for @ids==0 is the special gid for unknown artists defined in artist's init
'filter:m' => '(ref #_# ? (.!!. grep __#mainfield#_name[$_] =~ m"#VAL#", @{#_#}) : (__#mainfield#_name[#_#] .=~. m"#VAL#"))',
'filter:mi' => '(ref #_# ? (.!!. grep __#mainfield#_iname[$_] =~ m"#VAL#"i, @{#_#}) : (__#mainfield#_iname[#_#] .=~. m"#VAL#"i))',
'filter:s' => '(ref #_# ? (.!!. grep index( __#mainfield#_name[$_],"#VAL#") != -1, @{#_#}) : (index(__#mainfield#_name[#_#],"#VAL#") .!=. -1))',
'filter:si' => '(ref #_# ? (.!!. grep index( __#mainfield#_iname[$_], "#VAL#") != -1, @{#_#}) : (index(__#mainfield#_iname[#_#], "#VAL#") .!=. -1))',
'filter:fuzzy' => 'do { my $v=#_#; ref $v ? (.!!. ::first {Filter::_fuzzy_match(#VAL1#/100,"#VAL2#",__#mainfield#_iname[$_])} @$v) : .!!. Filter::_fuzzy_match(#VAL1#/100,"#VAL2#",__#mainfield#_iname[$v]); }',
'filter_prep:m' => \&Filter::QuoteRegEx,
'filter_prep:mi'=> sub { Filter::QuoteRegEx( ::superlc($_[0]) )},
'filter_prep:si'=> sub { quotemeta ::superlc($_[0])},
'filter_prep:s' => sub {quotemeta $_[0]},
'filter_prep:fuzzy'=>sub {my @arg=split / /,$_[0],2; $arg[0],quotemeta ::superlc($arg[1])},
'filter:~' => '(ref #_# ? (.!!. grep $_ == #VAL#, @{#_#}) : (#_# .==. #VAL#))',#FIXME use simpler/faster version if perl5.10 (with ~~)
'filter_prep:~' => '##mainfield#->filter_prep:~#',
'filter_prephash:~' => '##mainfield#->filter_prephash:~#',
'filter_simplify:~' => sub { length($_[0]) ? split /$Artists_split_re/,$_[0] : $_[0]; },
'filter:h~' => '(ref #_# ? (grep .!!. exists $hash#VAL#->{$_+0}, @{#_#}) : (.!!. exists $hash#VAL#->{#_#+0}))',
makefilter => '"#field#:~:".##mainfield#->gid_to_sgid#',
#group => '#_# !=',
stats => 'do {my $v=#_#; #HVAL#{__#mainfield#_name[$_]}=undef for ref $v ? @$v : $v;} ---- AFTER: #HVAL#=[keys %{#HVAL#}];',
'stats:gid' => 'do {my $v=#_#; #HVAL#{$_}=undef for ref $v ? @$v : $v;} ---- AFTER: #HVAL#=[keys %{#HVAL#}];',
hashm => 'do {my $v=#_#; ref $v ? @$v : $v}',
listall => '##mainfield#->listall#',
'filterdesc:~' => [ _"includes artist %s", _"includes artist", 'menustring', ],
'filterdesc:-~' => _"doesn't include artist %s",
'filterdesc:mi' => [ _"matches regexp %s",_"matches regexp",'regexp', icase=>1, ],
'filterdesc:si' => [ _"contains %s", _"contains", 'substring', icase=>1, ],
'filterdesc:m' => [_"matches regexp %s (case sensitive)",'mi'],
'filterdesc:s' => [_"contains %s (case sensitive)", 'si'],
'filterdesc:-m' => _"doesn't match regexp %s (case sensitive)",
'filterdesc:-mi'=> _"doesn't match regexp %s",
'filterdesc:-s' => _"doesn't contain %s (case sensitive)",
'filterdesc:-si'=> _"doesn't contain %s",
'filterdesc:fuzzy'=> [ _"%s fuzzy match with %s",_"fuzzy match", 'fuzzy string', ],
'filterdesc:-fuzzy'=> _"no %s fuzzy match with %s",
'smartfilter:=' => '~',
'smartfilter::' => 'si s',
'smartfilter:~' => 'mi m',
'smartfilter:#' => \&Filter::smartstring_fuzzy,
'filterpat:fuzzy'=> [ round => "%d", unit => '%', min=>20, max=>99, default_value=>65, ],
default_filter => 'si',
},
artist_first =>
{ parent => 'artist', #FIXME
_ => 'do {my $v=__artists__[#ID#]; ref $v ? $v->[0] : $v}',
#update => ';',
init => ';', #FIXME
},
artist =>
{ #set => '#_#= (#VAL# eq "" ? 0 : (__#mainfield#_gid{#VAL#}||= (push @__#mainfield#_name, #VAL#)-1));',
parent => 'fewstring',
mainfield => 'artist',
init => '____=""; __#mainfield#_gid{""}=1; #_iname#[1]=::superlc( #_name#[1]=_("<Unknown>") );',
get => 'do {my $v=#_#; $v!=1 ? #_name#[$v] : "";}',
gid_to_get => '(#GID#!=1 ? #_name#[#GID#] : "")',
gid_to_sgid => '(#GID#!=1 ? #_name#[#GID#] : "")',
search_gid => 'my $gid=__#mainfield#_gid{#VAL#}||0; $gid>1 ? $gid : undef;',
makefilter => '"#field#:~:" . #gid_to_sgid#',
diff => 'do {my $old=#_#; ($old!=1 ? #_name#[$old] : "") ne #VAL# }',
#save_extra => 'my %h; for my $gid (2..$##_name#) { my $v=__#mainfield#_picture[$gid]; next unless defined $v; ::_utf8_on($v); $h{ #_name#[$gid] }=$v; } return artist_pictures',
listall => '2..@#_name#-1',
load_extra => '__#mainfield#_gid{#SGID#} || return;',
save_extra => 'my %h; while ( my ($sgid,$gid)=each %__#mainfield#_gid ) { $h{$sgid}= [#SUBFIELDS#] } delete $h{""}; return \%h;',
#plugin => 'picture',
'filter:pic' => '.!!. __#mainfield#_picture[#_#]',
'filterdesc:pic:1'=> _"has a picture",
'filterdesc:-pic:1'=> _"doesn't have a picture",
},
album =>
{ parent => 'fewstring',
mainfield => 'album',
_empty => 'vec(__#mainfield#_empty,#_#,1)',
unknown => '_("<Unknown>")." "',
init => '____=""; __#mainfield#_gid{"\\x00"}=1; __#mainfield#_empty=""; vec(__#mainfield#_empty,1,1)=1; __#mainfield#_sgid[1]="\\x00"; #_iname#[1]=::superlc( #_name#[1]=_("<Unknown>") );',
findgid => 'do{ my $name=#VAL#; my $sgid= $name ."\\x00". ($name eq "" ? "artist=".#artist->get# : do {my $a=#album_artist_raw->get#; $a ne "" ? "album_artist=$a" : #compilation->get# ? "compilation=1" : ""} );
__#mainfield#_gid{$sgid}||= do {my $n=@#_name#; if ($name eq "") {vec(__#mainfield#_empty,$n,1)=1; $name=#unknown#.#artist->get#; } push @#_name#,$name; push @__#mainfield#_sgid,$sgid; #newval#; $n; };
};',
#possible sgid : album."\x00". "" if no album name and no artist
# "artist=".artist if no album name
# "album_artist"=album_artist if non-empty album_artist
# "compilation=1" if empty album_artist, compilation flag set
# ""
load => '#_#= #findgid#;',
set => 'my $oldgid=#_#; my $newgid= #_#= #findgid#; if ($newgid+1==@#_name# && $newgid!=$oldgid) { ___picture[$newgid]= ___picture[$oldgid]; }', #same as load, but if gid changed and is new, use picture from old gid
#newval => 'push @#_iname#, ::superlc( #_name#[-1] );',
get => '(#_empty# ? "" : #_name#[#_#])',
gid_to_get => '(vec(__#mainfield#_empty,#GID#,1) ? "" : #_name#[#GID#])',
sgid_to_gid => 'do {my $s=#VAL#; __#mainfield#_gid{$s}||= do { my $n=@#_name#; if ($s=~s/\x00(\w+)=(.*)$// && $s eq "" && $1 eq "artist") { $s= #unknown#.$2; vec(__#mainfield#_empty,$n,1)=1;} push @#_name#,$s; push @__#mainfield#_sgid,#VAL#; #newval#; $n }}',
gid_to_sgid => '$__#mainfield#_sgid[#GID#]',
makefilter => '"#field#:~:" . #gid_to_sgid#',
update => 'my $albumname=#get#; #set(VAL=$albumname)#;',
listall => 'grep !vec(__#mainfield#_empty,$_,1), 2..@#_name#-1',
'stats:artistsort' => '#HVAL#->{ #album_artist->get_gid# }=undef; ---- AFTER: #HVAL#=do { my @ar= keys %{#HVAL#}; @ar>1 ? ::superlc(_"Various artists") : __artist_iname[$ar[0]]; }',
#plugin => 'picture',
load_extra => ' __#mainfield#_gid{#SGID#} || return;',
save_extra => 'my %h; while ( my ($sgid,$gid)=each %__#mainfield#_gid ) { $h{$sgid}= [#SUBFIELDS#] } delete $h{""}; return \%h;',
'filter:pic' => '.!!. __#mainfield#_picture[#_#]',
'filterdesc:pic:1'=> _"has a picture",
'filterdesc:-pic:1'=> _"doesn't have a picture",
'filterpat:menustring'=> [ display=> sub { my $s=shift; $s=~s/\x00.*//; $s; } ], # could display $album by $album_artist instead
#load_extra => '___pix[ #sgid_to_gid(VAL=$_[0])# ]=$_[1];',
#save_extra => 'my @res; for my $gid (1..$##_name#) { my $v=___pix[$gid]; next unless length $v; push @res, [#*:gid_to_sgid(GID=$gid)#,$val]; } return \@res;',
},
string =>
{ parent => 'generic',
default => '""',
check => '#VAL#=~tr/\x1D\x00//d; #VAL#=~s/\s+$//;', #remove trailing spaces and \x1D\x00
diff => '#_# ne #VAL#',
s_sort => '#_#',
'filter:e' => '#_# .eq. "#VAL#"',
hash => '#_#',
group => '#_# ne',
stats => '#HVAL#{#_#}=undef; ---- AFTER: #HVAL#=[keys %{#HVAL#}];',
},
istring => # _much_ faster with case/accent insensitive operations, at the price of double memory
{ parent => 'string',
_iname => '___iname[#ID#]',
set => '#_# = #VAL#; #_iname#= ::superlc(#VAL#);',
si_sort => '#_iname#',
'filter:si' => 'index( #_iname#,"#VAL#") .!=. -1', 'filter_prep:si'=> sub { quotemeta ::superlc($_[0])},
'filter:mi' => '#_iname# .=~. m"#VAL#"i', 'filter_prep:mi'=> sub { Filter::QuoteRegEx( ::superlc($_[0]) )},
'filter:fuzzy' => ' .!!. Filter::_fuzzy_match(#VAL1#/100,"#VAL2#",#_iname#)', 'filter_prep:fuzzy'=> sub {my @arg=split / /,$_[0],2; $arg[0],quotemeta ::superlc($arg[1])},
},
text => #multi-lines string
{ parent => 'string',
check => '#VAL#=~tr/\x00-\x09\x0B\x0C\x0E-\x1F//d; #VAL#=~s/\s+$//;',
'editwidget:single' => sub { GMB::TagEdit::EntryText->new(@_); },
'editwidget:many' => sub { GMB::TagEdit::EntryText->new(@_); },
},
filename=>
{ parent => 'string',
check => ';', #override string's check because not needed and filename may not be utf8
get => '#_#',
set => '#_#=#VAL#; ::_utf8_off(#_#);',
display => '::filename_to_utf8displayname(#get#)',
hash_to_display => '::filename_to_utf8displayname(#VAL#)', #only used by FolderList:: and MassTag::
load => '#_#=::decode_url(#VAL#)',
save => 'filename_escape(#_#)',
#'filterpat:string' => [ display => \&::filename_to_utf8displayname, ],
},
# picture =>
# { get_picture => '__#mainfield#_picture[#GID#] || $::Options{Default_picture_#mainfield#};',
# get_pixbuf => 'my $file= #get_picture#; GMB::Picture::pixbuf($file);',
# set_picture => '::_utf8_off(#VAL#); __#mainfield#_picture[#GID#]= #VAL# eq "" ? undef : #VAL#; ::HasChanged("Picture_#mainfield#",#GID#);',
# 'load_extra:picture' => 'if (#VAL# ne "") { __#mainfield#_picture[#GID#]= ::decode_url(#VAL#); }',
# 'save_extra:picture' => 'do { my $v=__#mainfield#_picture[#GID#]; defined $v ? ::url_escape($v) : ""; }',
# },
_picture =>
{ _ => '__#mainfield#_picture[#GID#]',
init => '@__#mainfield#_picture=(); push @GMB::Picture::ArraysOfFiles, \@__#mainfield#_picture;',
default => '$::Options{Default_picture}{#mainfield#}',
get_for_gid => '#_# || #default#;',
pixbuf_for_gid => 'my $file= #get_for_gid#; GMB::Picture::pixbuf($file);',
set_for_gid => '::_utf8_off(#VAL#); #_#= #VAL# eq "" ? undef : #VAL#; ::HasChanged("Picture_#mainfield#",#GID#);',
load_extra => 'if (#VAL# ne "") { #_#= ::decode_url(#VAL#); }',
save_extra => 'do { my $v=#_#; defined $v ? filename_escape($v) : ""; }',
get => '__#mainfield#_picture[ ##mainfield#->get_gid# ]',
},
fewstring=> #for strings likely to be repeated
{ _ => 'vec(____,#ID#,#bits#)',
bits => 32, #32 bits by default (16 bits ?)
mainfield => '#field#',
_name => '__#mainfield#_name',
_iname => '__#mainfield#_iname',
sgid_to_gid => '__#mainfield#_gid{#VAL#}||= do { my $i=push(@#_name#, #VAL#); #newval#; $i-1; }',
newval => 'push @#_iname#, ::superlc( #_name#[-1] );',
#newval => 'push @#_iname#, ::superlc(#VAL#);',
set => '#_# = #sgid_to_gid#;',
init => '____=""; __#mainfield#_gid{""}=1; #_name#[1]=#_iname#[1]="";',
check => '#VAL#=~tr/\x00-\x1F//d; #VAL#=~s/\s+$//;',
default => '""',
get_gid => '#_#',
get => '#_name#[#_#]',
diff => '#get# ne #VAL#',
display => '#_name#[#_#]',
s_sort => '#_name#[#_#]',
si_sort => '#_iname#[#_#]',
gid_to_get => '#_name#[#GID#]',
's_sort:gid' => '#_name#[#GID#]',
'si_sort:gid' => '#_iname#[#GID#]',
always_first_gid=> 0,
gid_to_display => '#_name#[#GID#]',
'filter:m' => '#_name#[#_#] .=~. m"#VAL#"',
'filter:mi' => '#_iname#[#_#] .=~. m"#VAL#"i',
'filter:fuzzy' => '.!!. Filter::_fuzzy_match(#VAL1#/100,"#VAL2#",#_iname#[#_#])', 'filter_prep:fuzzy'=> sub {my @arg=split / /,$_[0],2; $arg[0],quotemeta ::superlc($arg[1])},
'filter:si' => 'index( #_iname#[#_#],"#VAL#") .!=. -1', 'filter_prep:si' => sub {quotemeta ::superlc($_[0])},
'filter:s' => 'index( #_name#[#_#], "#VAL#") .!=. -1',
'filter:e' => '#_name#[#_#] .eq. "#VAL#"',
'filter:~' => '#_# .==. #VAL#', 'filter_prep:~' => '#sgid_to_gid(VAL=#PAT#)#',
'filter_prephash:~' => 'return {map { #sgid_to_gid(VAL=$_)#,undef} keys %{#HREF#}}',
'filter:h~' => '.!!. exists $hash#VAL#->{#_#}',
# hash => '#_name#[#_#]',
hash => '#_#',
#"hash:gid" => '#_#',
makefilter => '"#field#:~:".#_name#[#GID#]',
group => '#_# !=',
stats => '#HVAL#{#_name#[#_#]}=undef; ---- AFTER: #HVAL#=[keys %{#HVAL#}];',
'stats:gid' => '#HVAL#{#_#}=undef; ---- AFTER: #HVAL#=[keys %{#HVAL#}];',
listall => '2..@#_name#-1',
edit_listall => 1,
parent => 'generic',
maxgid => '@#_name#-1',
'filterdesc:~' => [ _"is %s", _"is", 'menustring', ],
'filterdesc:-~' => _"isn't %s",
#gsummary => 'my $gids=Songs::UniqList(#field#,#IDs#); @$gids==1 ? #gid_to_display(GID=$gids->[0])# : #names(count=scalar @$gids)#;',
},
number =>
{ parent => 'generic',
set => '#_# = #VAL#||0',
########save => '(#_# || "")',
n_sort => '#_#',
'n_sort:gid' => '#GID#',
diff => '#_# != #VAL#',
'filter:e' => '#_# .==. #VAL#',
'filter:>' => '#_# .>. #VAL#',
'filter:<' => '#_# .<. #VAL#',
'filter:b' => '#_# .>=. #VAL1# .&&. #_# .<=. #VAL2#',
'filter_prep:b' => \&filter_prep_numbers_between,
'filter_prep:>' => \&filter_prep_numbers,
'filter_prep:<' => \&filter_prep_numbers,
'filter_prep:e' => \&filter_prep_numbers,
'group' => '#_# !=',
'stats:range' => 'push @{#HVAL#},#_#; ---- AFTER: #HVAL#=do {my ($m0,$m1)=(sort {$a <=> $b} @{#HVAL#})[0,-1]; $m0==$m1 ? $m0 : "$m0 - $m1"}',
'stats:average' => 'push @{#HVAL#},#_#; ---- AFTER: #HVAL#=do { my $s=0; $s+=$_ for @{#HVAL#}; $s/@{#HVAL#}; }',
'stats:sum' => '#HVAL# += #_#;',
stats => '#HVAL#{#_#+0}=undef;',
hash => '#_#+0',
display => '(#_# ? sprintf("#displayformat#", #_# ) : "")', #replace 0 with ""
gid_to_display => '#GID#',
get_gid => '#_#+0',
makefilter => '"#field#:e:#GID#"',
default => '0+0', #not 0 because it needs to be true :(
autofill_re => '\\d+',
default_filter => '>',
'filterdesc:e' => [ "= %s", "=", 'value', ],
'filterdesc:>' => [ "> %s", ">", 'value', noinv=>1 ],
'filterdesc:<' => [ "< %s", "<", 'value', noinv=>1 ],
'filterdesc:-<' => [ "≥ %s", "≥", 'value', noinv=>1 ],
'filterdesc:->' => [ "≤ %s", "≤", 'value', noinv=>1 ],
'filterdesc:b' => [ _"between %s and %s", _"between", 'value value'],
'filterdesc:-b' => _"not between %s and %s",
'filterdesc:-e' => "≠ %s",
'filterdesc:h' => [ _"in the top %s", _"in the top", 'number',], # "the %s most" "the most", ?
'filterdesc:t' => [ _"in the bottom %s",_"in the bottom", 'number',], # "the %s least" "the least", ?
'filterdesc:-h' => _"not in the top %s",
'filterdesc:-t' => _"not in the bottom %s",
'filterpat:substring' => [icase => 0],
'filterpat:regexp' => [icase => 0],
'smartfilter:>' => \&Filter::_smartstring_number_moreless,
'smartfilter:<' => \&Filter::_smartstring_number_moreless,
'smartfilter:<='=> \&Filter::_smartstring_number_moreless,
'smartfilter:>='=> \&Filter::_smartstring_number_moreless,
'smartfilter:=' => \&Filter::_smartstring_number,
'smartfilter::' => \&Filter::_smartstring_number,
'smartfilter:~' => 'm',
'smartfilter:=empty' => 'e:0',
'smartfilter:#' => undef,
filter_exclude => 'fuzzy', # do not show these filters
rightalign=>1, #right-align in SongTree and SongList
},
'number.div' =>
{ group => 'int(#_#/#ARG0#) !=',
hash => 'int(#_#/#ARG0#)', #hash:minute => '60*int(#_#/60)',
#makefilter => '"#field#:".(!#GID# ? "e:0" : "b:".(#GID# * #ARG0#)." ".((#GID#+1) * #ARG0#))',
makefilter => 'Filter->newadd(1, "#field#:-<:".(#GID# * #ARG0#), "#field#:<:".((#GID#+1) * #ARG0#) )', #FIXME decimal separator must be always "."
gid_to_display => '#GID# * #ARG0#',
get_gid => 'int(#_#/#ARG0#)',
},
fewnumber =>
{ _ => '___value[vec(____,#ID#,#bits#)]',
parent => 'number',
bits => 16,
init => '____=""; ___value[0]=undef;',
set => 'vec(____,#ID#,#bits#) = ___gid{#VAL#}||= do { push(@___value, #VAL#+0)-1; }',
check => '#VAL#= #VAL# =~m/^(-?\d*\.?\d+)$/ ? $1 : 0;',
displayformat => '%d',
},
integer =>
{ _ => 'vec(____,#ID#,#bits#)',
displayformat => '%d',
bits => 32, #use 32 bits by default
#check => '#VAL#= #VAL# =~m/^(\d+)$/ ? $1 : 0;',
check => '#VAL#= #VAL# =~m/^(\d+)/ && $1<2**#bits# ? $1 : 0;', # set to 0 if overflow
init => '____="";',
parent => 'number',
'editwidget:all'=> sub { my $field=$_[0]; GMB::TagEdit::EntryNumber->new(@_,min=>$Def{$field}{edit_min},max=>$Def{$field}{edit_max},digits=>0,mode=>$Def{$field}{edit_mode}); },
step => 1, #minimum difference between 2 values, used to simplify filters
},
'integer.div' =>
{ makefilter => '"#field#:b:".(#GID# * #ARG0#)." ".(((#GID#+1) * #ARG0#)-1)',
},
float => #make sure the string doesn't have the utf8 flag, else substr won't work
{ _ => 'unpack("F",substr(____,#ID#<<3,8))',
display => 'do {my $v=#_#; (#v_is_nan# ? "" : ::format_number($v,"#displayformat#"))}', # replace novalue (NaN) with ""
get => 'do {my $v=#_#; (#v_is_nan# ? "" : $v ); }', #
diff => ($nan==$nan ? 'do {my $new=#VAL#; $new=#nan# unless length $new; $new!=#_# }' :
'do {my $new=#VAL#; $new=#nan# unless length $new; my $v=#_#; $new!=$v && ($new==$new || ! #v_is_nan#) }'),
displayformat => '%.2f',
init => '____=" "x8;', #needs init for ID==0
parent => 'number',
nan => '$Songs::nan',
v_is_nan => ($nan==$nan ? '($v==#nan#)' : '($v!=$v)'), #on some system $nan!=$nan, on some not. In case nan==0, 0 will be treated as novalue, could treat novalue as 0 instead
novalue => '#nan#', #use NaN as novalue
default => '#novalue#',
set => 'substr(____,#ID#<<3,8)=pack("F",(length(#VAL#) ? #VAL# : #novalue#))',
check => '#VAL#= #VAL# =~m/^(-?\d*\.?\d+(?:e[-+]\d+)?)$/i ? $1 : #novalue#;',
# FIXME make sure that locale is set to C (=> '.' as decimal separator) when needed
'editwidget:all'=> sub { my $field=$_[0]; GMB::TagEdit::EntryNumber->new(@_,min=>$Def{$field}{edit_min},max=>$Def{$field}{edit_max},signed=>1,digits=>2,mode=>'allow_empty'); },
autofill_re => '-?\\d*\\.?\\d+',
'filterpat:value' => [ digits => 2, signed=>1, round => "%.2f", ],
n_sort => 'do {my $v=#_#; #v_is_nan# ? "-inf" : $v}',
'filter:defined' => 'do {my $v=#_#; .!. (#v_is_nan#)}',
'filterdesc:defined:1' => _"is defined",
'filterdesc:-defined:1' => _"is not defined",
'smartfilter:=empty' => '-defined:1',
'stats:same'=> 'do {my $v1=#HVAL#; my $v2=#_#; if (defined $v1) { #HVAL#=#nan# if $v1!=$v2; } else { #HVAL#= $v2 } }', #hval=nan if $v1!=$v2 works both if nan==nan or nan!=nan : set hval to nan if either one of them is nan or if they are not equal. That way no need to use #v_is_nan#, which would be complicated as it uses $v
},
'float.range'=>
{ get_gid => 'do {my $v=#_#; #v_is_nan# ? #nan_gid# : int($v/#range_step#) ;}',
nan_gid => '-2**31+1', #gid in FilterList are Long, 2**31-1 is GID_ALL
always_first_gid=> -2**31+1,
range_step => '1', #default step
gid_to_display => '( #GID#==#nan_gid# ? _"not defined" : do {my $v= #GID# * #range_step#; "$v .. ".($v+#range_step#)})',
gid_to_get => '( #GID#==#nan_gid# ? #nan# : #GID# * #range_step#)',
hash => '#get_gid#',
makefilter => '#GID#==#nan_gid# ? "#field#:-defined:1" : do { my $v= #GID# * #range_step#; Filter->newadd(1, "#field#:-<:".$v, "#field#:<:".($v + #range_step#)); }', #FIXME decimal separator must be always "."
'n_sort:gid' => '( do{my $n=#GID#==#nan_gid# ? "-inf" : #GID# * #range_step#;warn "#GID# => $n";$n })',
'n_sort:gid' => '( #GID#==#nan_gid# ? "-inf" : #GID# * #range_step# )',
'n_sort:gid' => '#GID#', # #nan_gid# is already the most negative number, no need to replace it with -inf
},
'length' =>
{ display => 'sprintf("%d:%02d", #_#/60, #_#%60)',
parent => 'integer',
'filter_prep:e' => \&::ConvertTimeLength,
'filter_prep:>' => \&::ConvertTimeLength,
'filter_prep:<' => \&::ConvertTimeLength,
'filter_prep:b' => sub {sort {$a <=> $b} map ::ConvertTimeLength($_), split / /,$_[0],2},
},
'length.div' => { gid_to_display => 'my $v=#GID# * #ARG0#; sprintf("%d:%02d", $v/60, $v%60);', },
size =>
{ display => '( ::format_number( #_#/'. ::MB() .',"%.1f").q( '. _"MB" .') )',
'filter_prep:e' => \&::ConvertSize,
'filter_prep:>' => \&::ConvertSize,
'filter_prep:<' => \&::ConvertSize,
'filter_prep:b' => sub {sort {$a <=> $b} map ::ConvertSize($_), split / /,$_[0],2},
parent => 'integer',
'filterpat:value' => [ unit=> \%::SIZEUNITS, default_unit=> 'm', default_value=>1, ],
},
'size.div' => { gid_to_display => '( ::format_number( #GID# * #ARG0#/'. ::MB() .',"%d").q( '. _"MB" .') )', },
rating =>
{ parent => 'integer',
bits => 8,
_ => 'vec(____,#ID#,#bits#)',
_default=> 'vec(___default_,#ID#,#bits#)',
init => '____ = ___default_ = "";',
default => '""',
diff => '(#VAL# eq "" ? 255 : #VAL#)!=#_#',
get => '(#_#==255 ? "" : #_#)',
display => '(#_#==255 ? "" : #_#)',
'stats:range' => 'push @{#HVAL#},#_default#; ---- AFTER: #HVAL#=do {my ($m0,$m1)=(sort {$a <=> $b} @{#HVAL#})[0,-1]; $m0==$m1 ? $m0 : "$m0 - $m1"}',
'stats:average' => 'push @{#HVAL#},#_default#; ---- AFTER: #HVAL#=do { my $s=0; $s+=$_ for @{#HVAL#}; $s/@{#HVAL#}; }',
check => '#VAL#= #VAL# =~m/^\d+$/ ? (#VAL#>100 ? 100 : #VAL#) : "";',
set => '{ my $v=#VAL#; #_default#= ($v eq "" ? $::Options{DefaultRating} : $v); #_# = ($v eq "" ? 255 : $v); }',
makefilter => '"#field#:~:#GID#"',
'filter:~' => '#_# .==. #VAL#',
'filter:e' => '#_default# .==. #VAL#',
'filter:>' => '#_default# .>. #VAL#',
'filter:<' => '#_default# .<. #VAL#',
'filter:b' => '#_default# .>=. #VAL1# .&&. #_default# .<=. #VAL2#',
'filterdesc:~' => [_"set to %s", _"set to", 'value'],
'filterdesc:-~' => _"not set to %s",,
'filterdesc:~:255'=> 'set to default',
'filterdesc:-~:255'=>'not set to default',
'smartfilter:=empty' => '~:255',
n_sort => '#_default#',
#array => '#_default#',
gid_to_display => '#GID#==255 ? _"Default" : #GID#',
percent => '#_default#', #for random mode
update => '___default_=____; my $d=pack "C",$::Options{DefaultRating}; ___default_=~s/\xff/$d/g;', #\xff==255 # called when $::Options{DefaultRating} has changed
#"hash:gid" => '#_#',
hash => '#_#',
'editwidget:all' => sub {GMB::TagEdit::EntryRating->new(@_) },
},
date =>
{ parent => 'integer',
display => 'Songs::DateString(#_#)',
daycount=> 'do { my $t=(time-( #_# ) )/86400; ($t<0)? 0 : $t}', #for random mode
'filter_prep:>ago' => \&::ConvertTime,
'filter_prep:<ago' => \&::ConvertTime,
'filter_prep:bago' => sub {sort {$a <=> $b} map ::ConvertTime($_), split / /,$_[0],2},
'filter:>ago' => '#_# .<. #VAL#',
'filter:<ago' => '#_# .>. #VAL#',
'filter:bago' => '#_# .>=. #VAL1# .&&. #_# .<=. #VAL2#',
#'filterdesc:e' => [_"is equal to %s", _"is equal to", 'date' ],
filter_exclude => 'e', # do not show these filters
'filterdesc:>ago' => [_"more than %s ago", _"more than", 'ago', ],
'filterdesc:<ago' => [_"less than %s ago", _"less than", 'ago', ],
'filterdesc:>' => [_"after %s", _"after", 'date', ],
'filterdesc:<' => [_"before %s", _"before", 'date', ],
'filterdesc:b' => [_"between %s and %s", _"between (absolute dates)", 'date date'],
'filterdesc:bago' => [_"between %s ago and %s ago", _"between (relative dates)", 'ago ago'],
'filterdesc:->ago' => _"less than %s ago",
'filterdesc:-<ago' => _"more than %s ago",
'filterdesc:->' => _"before %s",
'filterdesc:-<' => _"after %s",
'filterdesc:-b' => _"not between %s and %s",
'filterdesc:-bago' => _"not between %s ago and %s ago",
'filterdesc:h' => [ _"the %s most recent", _"the most recent", 'number'], #"the %s latest" "the latest" ?
'filterdesc:t' => [ _"the %s least recent", _"the least recent", 'number'], #"the %s earliest" "the earliest" ?
'filterdesc:-h' => _"not the %s most recent",
'filterdesc:-t' => _"not the %s least recent",
'filterpat:ago' => [ unit=> \%::DATEUNITS, default_unit=> 'd', ],
'filterpat:date' => [ display=> sub { my $var=shift; $var= ::strftime_utf8('%c',localtime $var) if $var=~m/^\d+$/; $var; }, ],
default_filter => '<ago',
'smartfilter:>' => \&Filter::_smartstring_date_moreless,
'smartfilter:<' => \&Filter::_smartstring_date_moreless,
'smartfilter:<='=> \&Filter::_smartstring_date_moreless,
'smartfilter:>='=> \&Filter::_smartstring_date_moreless,
'smartfilter:=' => \&Filter::_smartstring_date,
'smartfilter::' => \&Filter::_smartstring_date,
'smartfilter:~' => 'm',
'smartfilter:=empty' => 'e:0',
#for date.year, date.month, date.day :
always_first_gid=> 0,
group => '#mktime# !=',
get_gid => '#_# ? #mktime# : 0',
hash => '(#_# ? #mktime# : 0)', #or use post-hash modification for 0 case
subtypes_menu=> \%timespan_menu,
grouptitle=> 'my $gid=#get_gid#; #gid_to_display(GID=$gid)#;',
rightalign=>0,
},
'date.year' =>
{ mktime => '::mktime(0,0,0,1,0,(localtime(#_#))[5])',
gid_to_display => '(#GID# ? ::strftime_utf8("%Y",localtime(#GID#)) : _"never")',
makefilter => '"#field#:".(!#GID# ? "e:0" : "b:".#GID#." ".(::mktime(0,0,0,1,0,(localtime(#GID#))[5]+1)-1))',
},
'date.month' =>
{ mktime => '::mktime(0,0,0,1,(localtime(#_#))[4,5])',
gid_to_display => '(#GID# ? ::strftime_utf8("%b %Y",localtime(#GID#)) : _"never")',
makefilter => '"#field#:".(!#GID# ? "e:0" : "b:".#GID#." ".do{my ($m,$y)= (localtime(#GID#))[4,5]; ::mktime(0,0,0,1,$m+1,$y)-1})',
},
'date.day' =>
{ mktime => '::mktime(0,0,0,(localtime(#_#))[3,4,5])',
gid_to_display => '(#GID# ? ::strftime_utf8("%x",localtime(#GID#)) : _"never")',
makefilter => '"#field#:".(!#GID# ? "e:0" : "b:".#GID#." ".do{my ($d,$m,$y)= (localtime(#GID#))[3,4,5]; ::mktime(0,0,0,$d+1,$m,$y)-1})',
},
dates_compact => # ___index_ : binary string containing position (in unit of 1 date => 4 bytes) of the first date in ___values_ for each song
# ___nb_ : binary string containing number of dates for each song
# ___values_ : binary string containing the actual dates
# ___free_ : array containing free positions in ___values_ for each size
{ parent => 'dates',
_ => 'substr(___values_, #index# * #bytes#, #nb# * #bytes#)',
index => 'vec(___index_,#ID#,32)', # => max 2**32 songs that share the same number of dates, could maybe use 16 bits instead
nb => 'vec(___nb_,#ID#,16)', # => max 2**16 dates per song, could maybe use 8 bits instead
get_list => 'unpack("#packformat#*", #_#)',
init => '___index_= ___values_= ___nb_ = "";',
set => '{ my $v=#VAL#;
my @list= !$v ? () : sort { $a <=> $b } (ref $v ? @$v : split /\D+/,$v);
if (my $nb=#nb#) { ___free_[$nb].= pack "N",#index#; } # add previous space to list of free spaces
if (@list)
{ my $string= pack "#packformat#*", @list;
my $nb= #nb#= scalar @list;
if (___free_[$nb]) # re-use old space
{ #index#= unpack "N", substr(___free_[$nb],-4,4,"");
#_#= $string;
}
else # use new space
{ #index#= length(___values_)/#bytes#;
___values_ .= $string;
}
}
else { #index#=0; #nb#=0 }
}',
'filter:ecount' => '#VAL# .==. #nb#',
'stats:count' => '#HVAL# += #nb#;',
},
dates =>
{ parent => 'generic', # for m mi s si filters
_ => '____[#ID#]',
default => 'undef',
bits => 32, packformat=> 'L', # replace with 64 and Q for 64bits dates
bytes => '(#bits#/8)',
check => ';',
get_list => 'unpack("#packformat#*",#_#||"")',
display => 'join("\n",map Songs::DateString($_), reverse #get_list#)',
gid_to_get => '#GID#',
gid_to_display => 'Songs::DateString(#GID#)',
#n_sort => 'unpack("#packformat#*",substr(#_#||"",-#bytes#))', #sort by last date, not used
'n_sort:gid' => '#GID#',
get => 'join(" ",#get_list#)',
set => '{ my $v=#VAL#;
my @list= !$v ? () : sort { $a <=> $b } (ref $v ? @$v : split /\D+/,$v);
#_#= !@list ? undef : pack("#packformat#*", @list);
}', #use undef instead of '' if no dates to save some memory
diff => 'do {my $old=#_#||""; my $new=#VAL#; $new= pack "#packformat#*",sort { $a <=> $b } (ref $new ? @$new : split /\D+/,$new); $old ne $new; }',
check_multi => 'for my $lref (@{#VAL#}) {@$lref=grep m/^\d+$/, @$lref}',
set_multi => 'do {my %h; $h{$_}=0 for #get_list#; my ($toadd,$torm,$toggle)=@{#VAL#}; $h{$_}= (exists $h{$_} ? -1 : 1) for @$toggle; $h{$_}++ for @$toadd; $h{$_}-- for @$torm; (scalar grep $h{$_}!=0, keys %h) ? [grep $h{$_}>=0, keys %h] : undef; }',
'filter:ecount' => '#VAL# .==. length(#_#)/#bytes#',
'stats:count' => '#HVAL# += length(#_#)/#bytes#;',
#example of use : Songs::BuildHash('artist',$::Library,undef,'playhistory:countrange:DATE1-DATE2')); where DATE1 and DATE2 are secongs since epoch and DATE1<DATE2
'stats:countrange' => 'INIT: my ($$date1,$$date2)= #ARG#=~m/(\d+)/g; ---- #HVAL# ++ for grep $$date1<$_ && $$date2>$_, #get_list#;', #count plays between 2 dates (in seconds since epoch)
'stats:countafter' => '#HVAL# ++ for grep #ARG#<$_, #get_list#;', #count plays after date (in seconds since epoch)
'stats:countbefore' => '#HVAL# ++ for grep #ARG#>$_, #get_list#;', #count plays before date (in seconds since epoch)
stats => 'do {#HVAL#{$_}=undef for #get_list#;};',
'filter:e' => '.!!. do{ grep($_ == #VAL#, #get_list#) }',
'filter:>' => '.!!. do{ grep($_ > #VAL#, #get_list#) }',
'filter:<' => '.!!. do{ grep($_ < #VAL#, #get_list#) }',
'filter:b' => '.!!. do{ grep($_ >= #VAL1# && $_ <= #VAL2#, #get_list#) }',
'filter_prep:>' => \&filter_prep_numbers,
'filter_prep:<' => \&filter_prep_numbers,
'filter_prep:e' => \&filter_prep_numbers,
'filter_prep:b' => \&filter_prep_numbers_between,
'filter_prep:>ago' => \&::ConvertTime,
'filter_prep:<ago' => \&::ConvertTime,
'filter_prep:bago' => sub {sort {$a <=> $b} map ::ConvertTime($_), split / /,$_[0],2},
'filter:>ago' => '.!!. do{ grep($_ < #VAL#, #get_list#) }',
'filter:<ago' => '.!!. do{ grep($_ > #VAL#, #get_list#) }',
'filter:bago' => '.!!. do{ grep($_ >= #VAL1# && $_ <= #VAL2#, #get_list#) }',
#copy of filterdesc:* smartfilter:* from date type
'filterdesc:>ago' => [_"more than %s ago", _"more than", 'ago', ],
'filterdesc:<ago' => [_"less than %s ago", _"less than", 'ago', ],
'filterdesc:>' => [_"after %s", _"after", 'date', ],
'filterdesc:<' => [_"before %s", _"before", 'date', ],
'filterdesc:b' => [_"between %s and %s", _"between (absolute dates)", 'date date'],
'filterdesc:bago' => [_"between %s ago and %s ago", _"between (relative dates)", 'ago ago'],
'filterdesc:->ago' => _"not more than %s ago",
'filterdesc:-<ago' => _"not less than %s ago",
'filterdesc:->' => _"not after %s",
'filterdesc:-<' => _"not before %s",
'filterdesc:-b' => _"not between %s and %s",
'filterdesc:-bago' => _"not between %s ago and %s ago",
'filterdesc:h' => [ _"the %s most recent", _"the most recent", 'number'], #"the %s latest" "the latest" ?
'filterdesc:t' => [ _"the %s least recent", _"the least recent", 'number'], #"the %s earliest" "the earliest" ?
'filterdesc:-h' => _"not the %s most recent",
'filterdesc:-t' => _"not the %s least recent",
'filterpat:ago' => [ unit=> \%::DATEUNITS, default_unit=> 'd', ],
'filterpat:date' => [ display=> sub { my $var=shift; $var= ::strftime_utf8('%c',localtime $var) if $var=~m/^\d+$/; $var; }, ],
default_filter => '<ago',
'smartfilter:>' => \&Filter::_smartstring_date_moreless,
'smartfilter:<' => \&Filter::_smartstring_date_moreless,
'smartfilter:<='=> \&Filter::_smartstring_date_moreless,
'smartfilter:>='=> \&Filter::_smartstring_date_moreless,
'smartfilter:=' => \&Filter::_smartstring_date,
'smartfilter::' => \&Filter::_smartstring_date,
'smartfilter:=empty' => 'ecount:0',
'smartfilter:#' => undef,
filter_exclude => 'fuzzy', # do not show these filters
#get_gid => '[#get_list#]',
#hashm => '#get_list#',
#mktime => '$_',
#for dates.year, dates.month, dates.day :
always_first_gid=> 0,
get_gid => '[#_# ? (map #mktime#,#get_list#) : 0]',
hashm => '(#_# ? (map #mktime#,#get_list#) : 0)', #or use post-hash modification for 0 case
subtypes_menu=> \%timespan_menu,
},
#identical to date.*, except #_# is replaced by $_ in mktime, and "e" filter by "ecount"
'dates.year' =>
{ mktime => '::mktime(0,0,0,1,0,(localtime($_))[5])',
gid_to_display => '(#GID# ? ::strftime_utf8("%Y",localtime(#GID#)) : _"never")',
makefilter => '"#field#:".(!#GID# ? "ecount:0" : "b:".#GID#." ".(::mktime(0,0,0,1,0,(localtime(#GID#))[5]+1)-1))',
},
'dates.month' =>
{ mktime => '::mktime(0,0,0,1,(localtime($_))[4,5])',
gid_to_display => '(#GID# ? ::strftime_utf8("%b %Y",localtime(#GID#)) : _"never")',
makefilter => '"#field#:".(!#GID# ? "ecount:0" : "b:".#GID#." ".do{my ($m,$y)= (localtime(#GID#))[4,5]; ::mktime(0,0,0,1,$m+1,$y)-1})',
},
'dates.day' =>
{ mktime => '::mktime(0,0,0,(localtime($_))[3,4,5])',
gid_to_display => '(#GID# ? ::strftime_utf8("%x",localtime(#GID#)) : _"never")',
makefilter => '"#field#:".(!#GID# ? "ecount:0" : "b:".#GID#." ".do{my ($d,$m,$y)= (localtime(#GID#))[3,4,5]; ::mktime(0,0,0,$d+1,$m,$y)-1})',
},
boolean =>
{ parent => 'integer', bits => 1,
check => '#VAL#= #VAL# ? 1 : 0;',
display => "(#_# ? #yes# : #no#)", yes => '_("Yes")', no => 'q()',
'editwidget:all'=> sub { my $field=$_[0]; GMB::TagEdit::EntryBoolean->new(@_); },
'filterdesc:e:0' => [_"is false",_"is false",'',noinv=>1],
'filterdesc:e:1' => [_"is true", _"is true", '',noinv=>1],
'filterdesc:-e:0' => _"is true",
'filterdesc:-e:1' => _"is false",
filter_exclude => 'ALL', #do not show filters inherited from parents
default_filter => 'e:1',
'smartfilter:=empty' => 'e:0',
rightalign=>0,
},
shuffle=>
{ n_sort => 'Songs::update_shuffle($Songs::LastID) ---- vec($Songs::SHUFFLE,#ID#,32)',
},
gidshuffle=>
{ n_sort => 'Songs::update_shuffle(##mainfield#->maxgid#) ---- vec($Songs::SHUFFLE,##mainfield#->get_gid#,32)',
},
writeonly=>
{ diff=>'1',
set => '',
check=>'',
},
);
%Def= #flags : Read Write Editable Sortable Column caseInsensitive sAve List Gettable Properties
(file =>
{ name => _"Filename", width => 400, flags => 'fgascp_', type => 'filename',
'stats:filetoid' => '#HVAL#{ #file->get# }=#ID#',
category=>'file',
alias => 'filename',
},
id =>
{ type=> 'integer',
_ => '#ID#',
'stats:list' => 'push @{#HVAL#}, #ID#',
'stats:uniq' => '#HVAL#=undef', #doesn't really belong here, but simpler this way
'stats:count' => '#HVAL#++',
},
path =>
{ name => _"Folder", width => 200, flags => 'fgascp_', type => 'filename',
'filter:i' => '#_# .=~. m/^#VAL#(?:$::QSLASH|$)/o',
'filter_prep:i' => sub { quotemeta ::decode_url($_[0]); },
'filterdesc:i' => [_"is in %s", _"is in", 'filename'],
'filterdesc:-i' => _"isn't in %s",
'filterpat:filename' => [ display => sub { ::filename_to_utf8displayname(::decode_url($_[0])); }, ],
can_group=>1,
category=>'file',
alias => 'folder',
},
modif =>
{ name => _"Modification", width => 160, flags => 'fgarscp_', type => 'date',
FilterList => {type=>'year',},
can_group=>1,
category=>'file',
alias => 'modified',
},
size =>
{ name => _"Size", width => 80, flags => 'fgarscp_', #32bits => 4G max
type => 'size',
FilterList => {type=>'div.'.::MB(),},
category=>'file',
},
title =>
{ name => _"Title", width => 270, flags => 'fgarwescpi', type => 'istring',
id3v1 => 0, id3v2 => 'TIT2', vorbis => 'title', ape => 'Title', lyrics3v2=> 'ETT', ilst => "\xA9nam",
'filter:~' => '#_iname# .=~. m"(?:^|/) *#VAL# *(?:[/\(\[]|$)"', 'filter_prep:~'=> \&Filter::SmartTitleRegEx,
'filter_simplify:~' => \&Filter::SmartTitleSimplify,
'filterdesc:~' => [_"is smart equal to %s", _"is smart equal", 'substring'],
'filterdesc:-~' => _"Isn't smart equal to %s",
makefilter_fromID => '"title:~:" . #get#',
edit_order=> 10, letter => 't',
category=>'basic',
alias_trans=> ::_p('Field_aliases',"title"), #TRANSLATION: comma-separated list of field aliases for title, these are in addition to english aliases
articles=>1,
},
artist =>
{ name => _"Artist", width => 200, flags => 'fgarwescpi',
type => 'artist',
id3v1 => 1, id3v2 => 'TPE1', vorbis => 'artist', ape => 'Artist', lyrics3v2=> 'EAR', ilst => "\xA9ART",
FilterList => {search=>1,drag=>::DRAG_ARTIST},
all_count=> _"All artists",
apic_id => 8,
picture_field => 'artist_picture',
edit_order=> 20, edit_many=>1, letter => 'a',
can_group=>1,
#names => '::__("%d artist","%d artists",#count#);'
category=>'basic',
alias=> 'by',
alias_trans=> ::_p('Field_aliases',"artist,by"), #TRANSLATION: comma-separated list of field aliases for artist, these are in addition to english aliases
articles=>1,
},
first_artist =>
{ flags => 'fig',
type => 'artist_first', depend => 'artists', name => _"Main artist",
FilterList => {search=>1,drag=>::DRAG_ARTIST},
picture_field => 'artist_picture',
sortgroup=>'artist',
can_group=>1,
articles=>1,
},
artists =>
{ flags => 'gfil', type => 'artists', depend => 'artist title', name => _"Artists",
all_count=> _"All artists",
FilterList => {search=>1,drag=>::DRAG_ARTIST},
picture_field => 'artist_picture',
articles=>1,
},
album =>
{ name => _"Album", width => 200, flags => 'fgarwescpi', type => 'album',
id3v1 => 2, id3v2 => 'TALB', vorbis => 'album', ape => 'Album', lyrics3v2=> 'EAL', ilst => "\xA9alb",
depend => 'artist album_artist_raw compilation', #because albums with no names get the name : <Unknown> (artist)
all_count=> _"All albums",
FilterList => {search=>1,drag=>::DRAG_ALBUM},
apic_id => 3,
picture_field => 'album_picture',
names => '::__("%d album","%d albums",#count#);',
edit_order=> 30, edit_many=>1, letter => 'l',
can_group=>1,
category=>'basic',
alias=> 'on',
alias_trans=> ::_p('Field_aliases',"album,on"), #TRANSLATION: comma-separated list of field aliases for album, these are in addition to english aliases
articles=>1,
},
# genre_picture =>
# { name => "Genre picture",
# flags => 'g',
# depend => 'genre',
# property_of => 'genre',
# mainfield => 'genre',
# type => '_picture',
# },
album_picture =>
{ name => _"Album picture",
flags => 'g',
depend => 'album',
property_of => 'album',
mainfield => 'album',
type => '_picture',
letter => 'c',
},
artist_picture =>
{ name => _"Artist picture",
flags => 'g',
depend => 'artist',
property_of => 'artist',
mainfield => 'artist',
type => '_picture',
},
album_artist_raw =>
{ name => _"Album artist",width => 200, flags => 'fgarwescpi', type => 'artist',
id3v2 => 'TPE2', vorbis => 'albumartist|album_artist', ape => 'Album Artist|Album_artist', ilst => "aART",
#FilterList => {search=>1,drag=>::DRAG_ARTIST},
picture_field => 'artist_picture',
edit_order=> 35, edit_many=>1,
#can_group=>1,
category=>'basic',
},
album_artist =>
{ name => _"Album artist or artist",width => 200, flags => 'fgcsi', type => 'artist',
FilterList => {search=>1,drag=>::DRAG_ARTIST},
picture_field => 'artist_picture',
_ => 'do {my $n=vec(__album_artist_raw__,#ID#,#bits#); $n==1 ? vec(__artist__,#ID#,#bits#) : $n}',
can_group=>1,
letter => 'A',
depend => 'album_artist_raw artist album',
category=>'basic',
articles=>1,
},
album_has_picture=>
{ name => _"Album has picture", width => 20, flags => 'fgcs', type => 'boolean',
_ => '!!(__#mainfield#_picture[ ##mainfield#->get_gid# ])', mainfield=> 'album',
},
artist_has_picture=>
{ name => _"Artist has picture", width => 20, flags => 'fgcs', type => 'boolean',
_ => '!!(__#mainfield#_picture[ ##mainfield#->get_gid# ])', mainfield=> 'artist',
},
has_picture =>
{ name => _"Embedded picture", width => 20, flags => 'fgarscp', type => 'boolean',
id3v2 => 'APIC', vorbis => 'METADATA_BLOCK_PICTURE', 'ilst' => 'covr',
category=>'extra',
disable=>1, options => 'disable',
},
has_lyrics =>
{ name => _"Embedded lyrics", width => 20, flags => 'fgarscp', type => 'boolean',
id3v2 => 'TXXX;FMPS_Lyrics;%v | USLT;;;%v', vorbis => 'FMPS_LYRICS|lyrics', ape => 'FMPS_LYRICS|Lyrics',
'ilst' => "----FMPS_Lyrics|\xA9lyr", lyrics3v2 => 'LYR',
category=>'extra',
disable=>1, options => 'disable',
},
compilation =>
{ name => _"Compilation", width => 20, flags => 'fgarwescp', type => 'boolean',
id3v2 => 'TCMP', vorbis => 'compilation', ape => 'Compilation', ilst => 'cpil',
edit_many=>1,
category=>'basic',
},
grouping =>
{ name => _"Grouping", width => 100, flags => 'fgarwescpi', type => 'fewstring',
FilterList => {search=>1},
can_group=>1,
edit_order=> 55, edit_many=>1,
id3v2 => 'TIT1', vorbis => 'grouping', ape => 'Grouping', ilst => "\xA9grp",
category=>'extra',
articles=>1,
},
year =>
{ name => _"Year", width => 40, flags => 'fgarwescp', type => 'integer', bits => 16,
edit_max=>3000, edit_mode=> 'year',
check => '#VAL#= #VAL# =~m/(\d\d\d\d)/ ? $1 : 0;',
id3v1 => 3, id3v2 => 'TDRC|TYER', 'id3v2.3'=> 'TYER|TDRC', 'id3v2.4'=> 'TDRC|TYER', vorbis => 'date|year', ape => 'Record Date|Year', ilst => "\xA9day",
prewrite=> sub { $_[0] ? $_[0] : undef }, #remove tag if 0
gid_to_display => '#GID# ? #GID# : _"None"',
'stats:range' => '#HVAL#{#_#}=undef; ---- AFTER: delete #HVAL#{0}; #HVAL#=do {my ($m0,$m1)=(sort {$a <=> $b} keys %{#HVAL#})[0,-1]; !defined $m0 ? "" : $m0==$m1 ? $m0 : "$m0 - $m1"}',
editwidth => 6,
edit_order=> 50, edit_many=>1, letter => 'y',
can_group=>1,
FilterList => {},
autofill_re => '[12]\\d{3}',
category=>'basic',
},
track =>
{ name => _"Track", width => 40, flags => 'fgarwescp',
id3v1 => 5, id3v2 => 'TRCK', vorbis => 'tracknumber', ape => 'Track', ilst => "trkn",
prewrite=> sub { $_[0] ? $_[0] : undef }, #remove tag if 0
type => 'integer', displayformat => '%02d', bits => 16,
edit_max => 65535, edit_mode=> 'nozero',
edit_order=> 20, editwidth => 4, letter => 'n',
category=>'basic',
},
disc =>
{ name => _"Disc", width => 40, flags => 'fgarwescp', type => 'integer', bits => 8,