From 52ef8e5b5b351b1a788bae150a3c654252aab879 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 27 Mar 2017 02:39:38 +0800 Subject: [PATCH] Improved duration, seconds, minutes and hours bindings --- source/net/filebot/cli/CmdlineOperations.java | 4 ++-- .../net/filebot/format/MediaBindingBean.java | 22 ++++++++++++++----- .../ui/rename/BindingDialog.properties | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index 48cd09bc..3f04b543 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -555,7 +555,7 @@ public class CmdlineOperations implements CmdlineInterface { return newFile; } - private Map formatMatches(List> matches, ExpressionFormat format, File outputDir) throws Exception { + private Map formatMatches(List> matches, ExpressionFileFormat format, File outputDir) throws Exception { // map old files to new paths by applying formatting and validating filenames Map renameMap = new LinkedHashMap(); @@ -1037,7 +1037,7 @@ public class CmdlineOperations implements CmdlineInterface { public Stream getMediaInfo(Collection files, FileFilter filter, ExpressionFormat format) throws Exception { // use default expression format if not set if (format == null) { - return getMediaInfo(files, filter, new ExpressionFormat("{fn} [{resolution} {vc} {channels} {ac} {minutes}m]")); + return getMediaInfo(files, filter, new ExpressionFormat("{fn} [{resolution} {vc} {channels} {ac} {hours}]")); } return files.stream().filter(filter::accept).map(f -> { diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 9db82581..ce3c8e95 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; @@ -817,18 +818,27 @@ public class MediaBindingBean { } @Define("duration") - public Long getDuration() { - return new Double(getMediaInfo(StreamKind.General, 0, "Duration")).longValue(); + public Duration getDuration() { + long d = new Double(getMediaInfo(StreamKind.General, 0, "Duration")).longValue(); + return Duration.ofMillis(d); } @Define("seconds") - public Integer getSeconds() { - return (int) (getDuration() / 1000); + public long getSeconds() { + return getDuration().getSeconds(); } @Define("minutes") - public Integer getDurationInMinutes() { - return (int) (getDuration() / 60000); + public long getMinutes() { + return getDuration().toMinutes(); + } + + @Define("hours") + public String getHours() { + Duration d = getDuration(); + + // use RATIO instead of COLON for file name compatibility (see https://unicode-table.com/en/2236/) + return String.format("%d∶%02d", d.toHours(), d.minusHours(d.toHours()).toMinutes()); } @Define("media") diff --git a/source/net/filebot/ui/rename/BindingDialog.properties b/source/net/filebot/ui/rename/BindingDialog.properties index 4b0cdca9..0fee057e 100644 --- a/source/net/filebot/ui/rename/BindingDialog.properties +++ b/source/net/filebot/ui/rename/BindingDialog.properties @@ -2,4 +2,4 @@ parameter.exclude: ^StreamKind|^UniqueID|^StreamOrder|^ID|Count$ # preview expressions (keys are tagged so they can be sorted alphabetically) -expressions: n, y, s, e, sxe, s00e00, t, d, startdate, absolute, es, e00, sy, sc, di, dc, age, special, episode, series, primaryTitle, alias, movie, tmdbid, imdbid, pi, pn, lang, subt, plex, az, type, anime, regular, music, album, artist, albumArtist, actors, director, collection, genre, genres, languages, runtime, certification, rating, votes, vc, ac, cf, vf, hpi, af, channels, resolution, dim, width, height, bitdepth, bitrate, kbps, khz, ws, hd, source, tags, s3d, group, original, info, info.network, info.status, info.productionCompanies, info.productionCountries, info.certifications, info.certifications.AU, info.certifications.DE, omdb.rating, omdb.votes, localize.deu.n, localize.deu.t, localize.zho.n, localize.zho.t, order.airdate.sxe, order.dvd.sxe, fn, ext, mediaType, mediaPath, file, file.name, folder, folder.name, mediaTitle, audioLanguages, textLanguages, duration, seconds, minutes, bytes, megabytes, gigabytes, crc32, media.title, media.collection, media.season, media.part, media.partID, media.genre, media.contentType, media.description, media.lyrics, video[0].codecID, video[0].frameRate, video[0].displayAspectRatioString, video[0].scanType, audio.language, audio[0].bitRateString, audio[0].language, text.language, text[0].language, text[0].codecInfo, camera, camera.maker, camera.model, location, location.country +expressions: n, y, s, e, sxe, s00e00, t, d, startdate, absolute, es, e00, sy, sc, di, dc, age, special, episode, series, primaryTitle, alias, movie, tmdbid, imdbid, pi, pn, lang, subt, plex, az, type, anime, regular, music, album, artist, albumArtist, actors, director, collection, genre, genres, languages, runtime, certification, rating, votes, vc, ac, cf, vf, hpi, af, channels, resolution, dim, width, height, bitdepth, bitrate, kbps, khz, ws, hd, source, tags, s3d, group, original, info, info.network, info.status, info.productionCompanies, info.productionCountries, info.certifications, info.certifications.AU, info.certifications.DE, omdb.rating, omdb.votes, localize.deu.n, localize.deu.t, localize.zho.n, localize.zho.t, order.airdate.sxe, order.dvd.sxe, fn, ext, mediaType, mediaPath, file, file.name, folder, folder.name, mediaTitle, audioLanguages, textLanguages, duration, seconds, minutes, hours, bytes, megabytes, gigabytes, crc32, media.title, media.collection, media.season, media.part, media.partID, media.genre, media.contentType, media.description, media.lyrics, video[0].codecID, video[0].frameRate, video[0].displayAspectRatioString, video[0].scanType, audio.language, audio[0].bitRateString, audio[0].language, text.language, text[0].language, text[0].codecInfo, camera, camera.maker, camera.model, location, location.country