Discussion:
[PATCH 1/2] expr.c: add bitrate and codec to filter expressions
Johannes Weißl
2011-04-04 14:57:18 UTC
Permalink
---
Doc/cmus.txt | 5 +++--
expr.c | 12 +++++++++---
2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/Doc/cmus.txt b/Doc/cmus.txt
index 83a0b78..119b40d 100644
--- a/Doc/cmus.txt
+++ b/Doc/cmus.txt
@@ -1086,7 +1086,7 @@ built-in filters. Also (and)-grouping is done implicitly.
@h2 Strings

@li long
-*filename*, *artist*, *album*, *title*, *genre*, *comment*
+*filename*, *artist*, *album*, *title*, *genre*, *comment*, *codec*
@br
Comparators: *=* and *!=* (not equal)

@@ -1098,7 +1098,8 @@ Comparators: none
@h2 Integers

@li long
-*discnumber*, *tracknumber*, *date* (year), *duration* (seconds)
+*discnumber*, *tracknumber*, *date* (year), *duration* (seconds),
+*bitrate*
@br
Comparators: *<*, *<=*, *=*, *>=*, *>*, *!=*

diff --git a/expr.c b/expr.c
index 6b52954..b184693 100644
--- a/expr.c
+++ b/expr.c
@@ -409,6 +409,8 @@ static const struct {
} builtin[] = {
{ "album", EXPR_STR },
{ "artist", EXPR_STR },
+ { "bitrate", EXPR_INT },
+ { "codec", EXPR_STR },
{ "comment", EXPR_STR },
{ "date", EXPR_INT },
{ "discnumber", EXPR_INT },
@@ -849,12 +851,14 @@ int expr_eval(struct expr *expr, struct track_info *ti)
val = ti->filename;
if (!using_utf8 && utf8_encode(val, charset, &uval) == 0)
val = uval;
+ } else if (strcmp(key, "codec") == 0) {
+ val = ti->codec;
} else {
val = keyvals_get_val(ti->comments, key);
- /* non-existing string tag equals to "" */
- if (!val)
- val = "";
}
+ /* non-existing string tag equals to "" */
+ if (!val)
+ val = "";
res = glob_match(&expr->estr.glob_head, val);
free(uval);
if (expr->estr.op == SOP_EQ)
@@ -870,6 +874,8 @@ int expr_eval(struct expr *expr, struct track_info *ti)
val = INT_MAX;
} else if (strcmp(key, "date") == 0) {
val = comments_get_date(ti->comments, key) / 10000;
+ } else if (strcmp(key, "bitrate") == 0) {
+ val = (ti->bitrate >= 0) ? (int) (ti->bitrate / 1000. + 0.5) : -1;
} else {
val = comments_get_int(ti->comments, key);
}
--
1.7.4.1
Johannes Weißl
2011-04-04 14:57:19 UTC
Permalink
---
Doc/cmus.txt | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Doc/cmus.txt b/Doc/cmus.txt
index 119b40d..f0c514e 100644
--- a/Doc/cmus.txt
+++ b/Doc/cmus.txt
@@ -951,6 +951,8 @@ Special Keys:
%d %{duration} @br
%f %{path} @br
%F %{filename} @br
+ %{bitrate} @br
+ %{codec} @br
%{rg_track_gain} @br
%{rg_track_peak} @br
%{rg_album_gain} @br
@@ -980,8 +982,8 @@ Sort option (lib_sort, pl_sort) value is space separated list of the following
sort keys:

artist, album, title, tracknumber, discnumber, date, genre, comment,
- albumartist, filename, filemtime, rg_track_gain, rg_track_peak,
- rg_album_gain, rg_album_peak
+ albumartist, filename, filemtime, bitrate, codec, rg_track_gain,
+ rg_track_peak, rg_album_gain, rg_album_peak


@h1 PLUGIN OPTIONS
--
1.7.4.1
Johannes Weißl
2011-04-05 05:43:20 UTC
Permalink
:filter date=-1 is now possible
---
expr.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/expr.c b/expr.c
index b184693..64aa0dd 100644
--- a/expr.c
+++ b/expr.c
@@ -873,7 +873,7 @@ int expr_eval(struct expr *expr, struct track_info *ti)
if (is_url(ti->filename))
val = INT_MAX;
} else if (strcmp(key, "date") == 0) {
- val = comments_get_date(ti->comments, key) / 10000;
+ val = (ti->date >= 0) ? (ti->date / 10000) : -1;
} else if (strcmp(key, "bitrate") == 0) {
val = (ti->bitrate >= 0) ? (int) (ti->bitrate / 1000. + 0.5) : -1;
} else {
--
1.7.4.1
Gregory Petrosyan
2011-04-05 21:06:28 UTC
Permalink
Post by Johannes Weißl
:filter date=-1 is now possible
Merged all 3 to master, thanks!

Gregory

Loading...