Discussion:
[PATCH] add "originaldate" to format options / filters
Johannes Weißl
2011-08-30 19:10:58 UTC
Permalink
This tag is quite useful for re-releases of albums. E.g. "Revolver" by
"The Beatles" was first released in 1966, but was reissued later as
remastered version.
---
Doc/cmus.txt | 12 +++++++-----
comment.c | 2 ++
expr.c | 3 +++
id3.c | 6 ++++--
id3.h | 1 +
options.c | 1 +
track_info.c | 2 ++
track_info.h | 2 ++
ui_curses.c | 3 +++
9 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/Doc/cmus.txt b/Doc/cmus.txt
index ffc210f..449b635 100644
--- a/Doc/cmus.txt
+++ b/Doc/cmus.txt
@@ -973,6 +973,7 @@ Special Keys:
%d %{duration} @br
%f %{path} @br
%F %{filename} @br
+ %{originaldate} @br
%{bitrate} @br
%{codec} @br
%{codec_profile} @br
@@ -1008,9 +1009,10 @@ Examples:
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, bitrate, codec, codec_profile,
- rg_track_gain, rg_track_peak, rg_album_gain, rg_album_peak
+ artist, album, title, tracknumber, discnumber, date, originaldate,
+ genre, comment, albumartist, filename, filemtime, bitrate, codec,
+ codec_profile, rg_track_gain, rg_track_peak, rg_album_gain,
+ rg_album_peak


@h1 PLUGIN OPTIONS
@@ -1152,8 +1154,8 @@ Comparators: none
@h2 Integers

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

diff --git a/comment.c b/comment.c
index 896e73e..e72a7eb 100644
--- a/comment.c
+++ b/comment.c
@@ -160,6 +160,7 @@ int comments_get_date(const struct keyval *comments, const char *key)
static const char *interesting[] = {
"artist", "album", "title", "tracknumber", "discnumber", "genre",
"date", "compilation", "albumartist", "artistsort", "albumartistsort",
+ "originaldate",
"replaygain_track_gain",
"replaygain_track_peak",
"replaygain_album_gain",
@@ -179,6 +180,7 @@ static struct {
{ "WM/Year", "date" },
{ "WM/ArtistSortOrder", "artistsort" },
{ "WM/AlbumArtistSortOrder", "albumartistsort" },
+ { "WM/OriginalReleaseYear", "originaldate" },
{ NULL, NULL }
};

diff --git a/expr.c b/expr.c
index e346d07..3ef43ad 100644
--- a/expr.c
+++ b/expr.c
@@ -428,6 +428,7 @@ static const struct {
{ "codec_profile",EXPR_STR },
{ "comment", EXPR_STR },
{ "date", EXPR_INT },
+ { "originaldate",EXPR_INT },
{ "discnumber", EXPR_INT },
{ "duration", EXPR_INT },
{ "filename", EXPR_STR },
@@ -915,6 +916,8 @@ int expr_eval(struct expr *expr, struct track_info *ti)
val = INT_MAX;
} else if (strcmp(key, "date") == 0) {
val = (ti->date >= 0) ? (ti->date / 10000) : -1;
+ } else if (strcmp(key, "originaldate") == 0) {
+ val = (ti->originaldate >= 0) ? (ti->originaldate / 10000) : -1;
} else if (strcmp(key, "bitrate") == 0) {
val = (ti->bitrate >= 0) ? (int) (ti->bitrate / 1000. + 0.5) : -1;
} else {
diff --git a/id3.c b/id3.c
index 7be4d3e..73d79b3 100644
--- a/id3.c
+++ b/id3.c
@@ -241,6 +241,7 @@ const char * const id3_key_names[NUM_ID3_KEYS] = {
"album",
"title",
"date",
+ "originaldate",
"genre",
"discnumber",
"tracknumber",
@@ -535,7 +536,7 @@ static struct {
/* 2.4.0 */
{ "TDRC", ID3_DATE }, // recording date
{ "TDRL", ID3_DATE }, // release date
- { "TDOR", ID3_DATE }, // original release date
+ { "TDOR", ID3_ORIGINALDATE }, // original release date
{ "TSOP", ID3_ARTISTSORT },

/* >= 2.3.0 */
@@ -550,6 +551,7 @@ static struct {
{ "TSO2", ID3_ALBUMARTISTSORT },
{ "XSOP", ID3_ARTISTSORT }, // obsolete
{ "TCMP", ID3_COMPILATION },
+ { "TORY", ID3_ORIGINALDATE },

/* obsolete frames (2.2.0) */
{ "TP1", ID3_ARTIST },
@@ -688,7 +690,7 @@ static void decode_normal(struct id3tag *id3, const char *buf, int len, int enco
tmp = parse_genre(out);
free(out);
out = tmp;
- } else if (key == ID3_DATE) {
+ } else if (key == ID3_DATE || key == ID3_ORIGINALDATE) {
int date_len = check_date_format(out);
id3_debug("date before: '%s'\n", out);
if (date_len)
diff --git a/id3.h b/id3.h
index 20e9620..3e83dc6 100644
--- a/id3.h
+++ b/id3.h
@@ -28,6 +28,7 @@ enum id3_key {
ID3_ALBUM,
ID3_TITLE,
ID3_DATE,
+ ID3_ORIGINALDATE,
ID3_GENRE,
ID3_DISC,
ID3_TRACK,
diff --git a/options.c b/options.c
index dc315ec..c87baf3 100644
--- a/options.c
+++ b/options.c
@@ -227,6 +227,7 @@ static const struct {
{ "tracknumber", SORT_TRACKNUMBER },
{ "discnumber", SORT_DISCNUMBER },
{ "date", SORT_DATE },
+ { "originaldate", SORT_ORIGINALDATE },
{ "genre", SORT_GENRE },
{ "comment", SORT_COMMENT },
{ "albumartist", SORT_ALBUMARTIST },
diff --git a/track_info.c b/track_info.c
index 0bd2c15..c57e985 100644
--- a/track_info.c
+++ b/track_info.c
@@ -63,6 +63,7 @@ void track_info_set_comments(struct track_info *ti, struct keyval *comments) {
ti->tracknumber = comments_get_int(comments, "tracknumber");
ti->discnumber = comments_get_int(comments, "discnumber");
ti->date = comments_get_date(comments, "date");
+ ti->originaldate = comments_get_date(comments, "originaldate");
ti->genre = keyvals_get_val(comments, "genre");
ti->comment = keyvals_get_val(comments, "comment");
ti->albumartist = comments_get_albumartist(comments);
@@ -183,6 +184,7 @@ int track_info_cmp(const struct track_info *a, const struct track_info *b, const
case SORT_TRACKNUMBER:
case SORT_DISCNUMBER:
case SORT_DATE:
+ case SORT_ORIGINALDATE:
res = getentry(a, key, int) - getentry(b, key, int);
break;
case SORT_FILEMTIME:
diff --git a/track_info.h b/track_info.h
index 1762ecb..6902cfb 100644
--- a/track_info.h
+++ b/track_info.h
@@ -39,6 +39,7 @@ struct track_info {
int tracknumber;
int discnumber;
int date;
+ int originaldate;
double rg_track_gain;
double rg_track_peak;
double rg_album_gain;
@@ -69,6 +70,7 @@ typedef size_t sort_key_t;
#define SORT_TRACKNUMBER offsetof(struct track_info, tracknumber)
#define SORT_DISCNUMBER offsetof(struct track_info, discnumber)
#define SORT_DATE offsetof(struct track_info, date)
+#define SORT_ORIGINALDATE offsetof(struct track_info, originaldate)
#define SORT_RG_TRACK_GAIN offsetof(struct track_info, rg_track_gain)
#define SORT_RG_TRACK_PEAK offsetof(struct track_info, rg_track_peak)
#define SORT_RG_ALBUM_GAIN offsetof(struct track_info, rg_album_gain)
diff --git a/ui_curses.c b/ui_curses.c
index 361bf7a..98236ad 100644
--- a/ui_curses.c
+++ b/ui_curses.c
@@ -219,6 +219,7 @@ enum {
TF_TRACK,
TF_TITLE,
TF_YEAR,
+ TF_ORIGINALYEAR,
TF_GENRE,
TF_COMMENT,
TF_DURATION,
@@ -242,6 +243,7 @@ static struct format_option track_fopts[NR_TFS + 1] = {
DEF_FO_INT('n', "tracknumber", 1),
DEF_FO_STR('t', "title", 0),
DEF_FO_STR('y', "date", 1),
+ DEF_FO_STR('\0', "originaldate", 1),
DEF_FO_STR('g', "genre", 0),
DEF_FO_STR('c', "comment", 0),
DEF_FO_TIME('d', "duration", 0),
@@ -562,6 +564,7 @@ static void fill_track_fopts_track_info(struct track_info *info)
fopt_set_double(&track_fopts[TF_RG_TRACK_PEAK], info->rg_track_peak, isnan(info->rg_track_peak));
fopt_set_double(&track_fopts[TF_RG_ALBUM_GAIN], info->rg_album_gain, isnan(info->rg_album_gain));
fopt_set_double(&track_fopts[TF_RG_ALBUM_PEAK], info->rg_album_peak, isnan(info->rg_album_peak));
+ fopt_set_str(&track_fopts[TF_ORIGINALYEAR], keyvals_get_val(info->comments, "originaldate"));
fopt_set_int(&track_fopts[TF_BITRATE], (int) (info->bitrate / 1000. + 0.5), info->bitrate == -1);
fopt_set_str(&track_fopts[TF_CODEC], info->codec);
fopt_set_str(&track_fopts[TF_CODEC_PROFILE], info->codec_profile);
--
1.7.6
Johannes Weißl
2011-08-30 23:28:05 UTC
Permalink
Otherwise the later keys aren't recognized anymore.
---
expr.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/expr.c b/expr.c
index 3ef43ad..5b48868 100644
--- a/expr.c
+++ b/expr.c
@@ -428,11 +428,11 @@ static const struct {
{ "codec_profile",EXPR_STR },
{ "comment", EXPR_STR },
{ "date", EXPR_INT },
- { "originaldate",EXPR_INT },
{ "discnumber", EXPR_INT },
{ "duration", EXPR_INT },
{ "filename", EXPR_STR },
{ "genre", EXPR_STR },
+ { "originaldate",EXPR_INT },
{ "stream", EXPR_BOOL },
{ "tag", EXPR_BOOL },
{ "title", EXPR_STR },
--
1.7.6
Gregory Petrosyan
2011-08-31 13:10:53 UTC
Permalink
Post by Johannes Weißl
This tag is quite useful for re-releases of albums. E.g. "Revolver" by
"The Beatles" was first released in 1966, but was reissued later as
remastered version.
Looks good, merged -- thanks!

Gregory

Loading...