Skip to content

Commit

Permalink
Merge pull request #346 from yermak/issue/345_split_combine
Browse files Browse the repository at this point in the history
fixing combine, split, move up and downs for parts, chapters, tracks
  • Loading branch information
yermak authored Dec 23, 2021
2 parents f85a14d + f03f61c commit 843e697
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ private static String cleanText(String text) {


static Collection<File> findPictures(File dir) {
return FileUtils.listFiles(dir, ArtWork.IMAGE_EXTENSIONS, true);
try {
return FileUtils.listFiles(dir, ArtWork.IMAGE_EXTENSIONS, true);
} catch (Exception e) {
logger.error("Failed to search for images in dir:" + dir, e);
return Collections.emptyList();
}
}

static void searchForPosters(List<MediaInfo> media) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/uk/yermak/audiobookconverter/MediaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface MediaInfo extends Organisable {
Chapter getChapter();

int getUID();

String getReference();
}


14 changes: 14 additions & 0 deletions src/main/java/uk/yermak/audiobookconverter/MediaInfoBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public int getUID() {
return Objects.hash(fileName);
}

@Override
public String getReference() {
return getFileName();
}

public int getChannels() {
return this.channels;
}
Expand Down Expand Up @@ -107,5 +112,14 @@ public MediaInfoBean(final String fileName) {
this.duration = 0L;
this.codec = "";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MediaInfo)) return false;
MediaInfo that = (MediaInfo) o;
return getReference().equals(that.getReference());
}

}

10 changes: 10 additions & 0 deletions src/main/java/uk/yermak/audiobookconverter/MediaInfoProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public int getUID() {
return this.getMediaInfo().getUID();
}

@Override
public String getReference() {
return this.getMediaInfo().getReference();
}

@Override
public long getOffset() {
return this.getMediaInfo().getOffset();
Expand All @@ -125,6 +130,11 @@ public int getNumber() {
public int getTotalNumbers() {
return this.getMediaInfo().getTotalNumbers();
}

@Override
public boolean equals(Object obj) {
return this.getMediaInfo().equals(obj);
}
}


13 changes: 13 additions & 0 deletions src/main/java/uk/yermak/audiobookconverter/MediaTrackAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public int getUID() {
return Objects.hash(mediaInfo.getFileName(), track.getTrackNo());
}

@Override
public String getReference() {
return getFileName() + "-" + track.getTrackNo();
}

@Override
public long getOffset() {
return track.getStart();
Expand All @@ -95,4 +100,12 @@ public long getOffset() {
public int getTotalNumbers() {
return 0;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof MediaInfo)) return false;
MediaInfo that = (MediaInfo) o;
return getReference().equals(that.getReference());
}
}
16 changes: 0 additions & 16 deletions src/main/java/uk/yermak/audiobookconverter/Part.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ private String getBookNumberString() {
return String.valueOf(getBook().getBookInfo().bookNumber());
}

/*
private String getNumberString() {
if (getBook().getParts().size() > 1) {
return StringUtils.leftPad(String.valueOf(getNumber()), 2, '0');
} else {
return null;
}
}
*/

/*
private String getDurationString() {
return Utils.formatTimeForFilename(getDuration());
}
*/

public String getTitle() {
return "Part " + getNumber();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ContextMenu menu(Organisable item) {
contextMenu.getItems().add(split);
}

if (item instanceof Chapter && item.getTotalNumbers() > 1 && getSelectionModel().getSelectedItems().size() > 1 /*&& getSelectionModel().getSelectedItems().contains(item)*/) {
if ((item instanceof Chapter || item instanceof Part) && item.getTotalNumbers() > 1 && getSelectionModel().getSelectedItems().size() > 1 /*&& getSelectionModel().getSelectedItems().contains(item)*/) {
MenuItem combine = new MenuItem("Combine");
combine.setOnAction(BookStructureComponent.this::combineChapters);
contextMenu.getItems().add(combine);
Expand Down

0 comments on commit 843e697

Please sign in to comment.