Improved duration, seconds, minutes and hours bindings

This commit is contained in:
Reinhard Pointner 2017-03-27 02:39:38 +08:00
parent 20c85970e2
commit 52ef8e5b5b
3 changed files with 19 additions and 9 deletions

View File

@ -555,7 +555,7 @@ public class CmdlineOperations implements CmdlineInterface {
return newFile;
}
private Map<File, File> formatMatches(List<Match<File, ?>> matches, ExpressionFormat format, File outputDir) throws Exception {
private Map<File, File> formatMatches(List<Match<File, ?>> matches, ExpressionFileFormat format, File outputDir) throws Exception {
// map old files to new paths by applying formatting and validating filenames
Map<File, File> renameMap = new LinkedHashMap<File, File>();
@ -1037,7 +1037,7 @@ public class CmdlineOperations implements CmdlineInterface {
public Stream<String> getMediaInfo(Collection<File> 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 -> {

View File

@ -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")

View File

@ -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