Skip to content

Commit

Permalink
Merge pull request #221 from isdenmois/bugfix/file-duration
Browse files Browse the repository at this point in the history
Show recalculated (based on speed) duration for the original file and for chapter
  • Loading branch information
yermak committed Jan 29, 2021
2 parents 0e5e9af + 567435e commit cdb60c6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/main/java/uk/yermak/audiobookconverter/Chapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import uk.yermak.audiobookconverter.fx.ConverterApplication;

import java.time.Duration;
import java.util.*;
Expand Down Expand Up @@ -61,7 +60,7 @@ public String getDetails() {

@Override
public long getDuration() {
return (long) (media.stream().mapToLong(Organisable::getDuration).sum() / ConverterApplication.getContext().getSpeed());
return media.stream().mapToLong(MediaInfo::getDuration).sum();
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.yermak.audiobookconverter;

import uk.yermak.audiobookconverter.fx.ConverterApplication;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -40,7 +42,7 @@ public String getDetails() {
}

public long getDuration() {
return this.getMediaInfo().getDuration();
return (long) (this.getMediaInfo().getDuration() / ConverterApplication.getContext().getSpeed());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.yermak.audiobookconverter;

import uk.yermak.audiobookconverter.fx.ConverterApplication;

import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -48,7 +50,7 @@ public int getBitrate() {

@Override
public long getDuration() {
return duration;
return (long) (duration / ConverterApplication.getContext().getSpeed());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@ private void subTracks(ActionEvent actionEvent) {
}

private void extractSubtracks(MediaInfo mediaInfo, Boolean wrapWithChapters, long interval) {
double speed = ConverterApplication.getContext().getSpeed();
long duration = mediaInfo.getDuration();

if (speed != 1.0) {
interval = (long) (interval * speed);
duration = (long) (duration * speed);
}

long fullTracks = duration / interval;
List<Track> tracks = new ArrayList<>();
for (int i = 1; i <= fullTracks + (duration % interval > 0 ? 1 : 0); i++) {
Expand Down

0 comments on commit cdb60c6

Please sign in to comment.