Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ private void download(ReleaseWithPath release) {
if (downloadAll) {
selection = release.matchingSubs;
if (!selection.isEmpty()) {
System.out.println("Downloading ALL found subtitles for release: ${release.fileNameOrName}");
System.out.println("Downloading ALL found subtitles for release: ${release.folderNameOrName}");
}
} else {
selection = userInteractionHandlerAction.subtitleSelection(release, subtitleSelection, dryRun);
}
if (selection.isEmpty()) {
System.out.println("No subtitles found for: ${release.fileNameOrName}");
System.out.println("No subtitles found for: ${release.folderNameOrName}");
} else {
AtomicInteger counter = new AtomicInteger(1);
IntStream.range(0, selection.size()).forEach(j -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.time.temporal.ChronoUnit.*;
import static org.lodder.subtools.multisubdownloader.Messages.*;
import static util.Utils.*;

import java.time.Instant;
import java.time.LocalDate;
Expand Down Expand Up @@ -89,7 +90,7 @@ private Optional<String> getUrlLatestNewStableGithubRelease() {
url:"$REPO_URL/releases",
cacheType:CacheType.NONE,
userAgent:null))
.selectFirstByCss("#repo-content-turbo-frame .box a[href='$REPO_URI/releases/latest']");
.selectFirstByCss("#repo-content-turbo-frame .box a[href='$REPO_URI/releases/latest']");
Pattern versionPattern = Pattern.compile("\\d*\\.\\d\\.\\d");
String versionText = element.parentElement().selectFirst("a").text();
Matcher matcher = versionPattern.matcher(versionText);
Expand Down Expand Up @@ -152,8 +153,8 @@ private Optional<String> getUrlLatestNewNightlyGithubRelease() {
}

private LocalDateTime getBuildTista() {
String timestamp = PropertiesReader.getProperty(PomProperty.BUILD_TIMESTAMP);
return zonedDateTimeStringToLocalDateTime(timestamp);
return ifNotNullOrElseGet(PropertiesReader.getProperty(PomProperty.BUILD_TIMESTAMP),
this::zonedDateTimeStringToLocalDateTime, LocalDateTime::now);
}

private String getVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public UserInteractionHandlerCLI(UserInteractionSettingsIntf settings) {
@Override
public List<Subtitle> selectSubtitles(Release release) {
System.out.printf("\n%s : %s%n", getText("SelectDialog.SelectCorrectSubtitleThisRelease"),
release.fileNameOrName);
release.folderNameOrName);
return PrompterExt.promptValuesFromList(prompter,
getText("SelectDialog.EnterListSelectedSubtitles"),
release.matchingSubs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void cleanUpFiles(ReleaseWithPath release, Path destination, String video
throw new IllegalArgumentException("Destination [%s] is not a folder".formatted(destination));
}

release.path.list()
release.path.parent.list()
.filter(p -> (p.isDirectory() && p.fileNameContainsIgnoreCase(SAMPLE_DIR_NAME))
|| (p.isRegularFile() && FILE_FILTERS.contains(p.getExtension())))
.forEachEx(p -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ private void download(ReleaseWithPath release, Subtitle subtitle, LibrarySetting
}

if (!librarySettings.hasLibraryAction(LibraryActionType.NOTHING)) {
Path oldLocationFile = release.path.resolve(ifNullThen(release.fileName, release.name));
Path oldLocationFile = release.path.parent.resolve(ifNullThen(release.fileName, release.name));
if (oldLocationFile.exists()) {
LOGGER.info("Moving/Renaming [{}] to folder [{}] this might take a while... ", videoFileName, path);
oldLocationFile.moveToDir(path);
if (!librarySettings.hasLibraryOtherFileAction(LibraryOtherFileActionType.NOTHING)) {
CleanAction cleanAction = new CleanAction(librarySettings);
cleanAction.cleanUpFiles(release, path, videoFileName);
}
if (librarySettings.removeEmptyFolders && release.path.isEmptyDir()) {
release.path.deletePath();
if (librarySettings.removeEmptyFolders && release.path.parent.isEmptyDir()) {
release.path.parent.deletePath();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void moveAndRename(Path f, ReleaseWithPath release) {
Path newDir = switch (librarySettings.action) {
case MOVE, MOVE_AND_RENAME ->
PathLibraryBuilder.fromSettings(librarySettings, manager, userInteractionHandler).buildPath(release);
case RENAME, NOTHING -> release.path;
case RENAME, NOTHING -> release.path.parent;
};
if (!newDir.exists()) {
LOGGER.debug("Creating dir [{}]", newDir.toAbsolutePath());
Expand All @@ -59,7 +59,7 @@ public void moveAndRename(Path f, ReleaseWithPath release) {
}
LOGGER.trace("rename: newDir [{}]", newDir);

Path file = release.path.resolve(release.fileName);
Path file = release.path.parent.resolve(release.fileName);

try {
if (librarySettings.hasLibraryAction(LibraryActionType.MOVE) ||
Expand All @@ -68,15 +68,15 @@ public void moveAndRename(Path f, ReleaseWithPath release) {
file.moveToDirAndRename(newDir, filename);
} else {
LOGGER.info("Moving [{}] to the library folder [{}] , this might take a while... ", filename,
release.path);
file.moveToDirAndRename(release.path, filename);
release.path.parent);
file.moveToDirAndRename(release.path.parent, filename);
}
if (!librarySettings.hasLibraryOtherFileAction(LibraryOtherFileActionType.NOTHING)) {
new CleanAction(librarySettings).cleanUpFiles(release, newDir, filename);
}

if (librarySettings.removeEmptyFolders && release.path.isEmptyDir()) {
Files.delete(release.path);
if (librarySettings.removeEmptyFolders && release.path.parent.isEmptyDir()) {
Files.delete(release.path.parent);
}
} catch (IOException e) {
LOGGER.error("Unsuccessful in moving the file to the library", e);
Expand All @@ -87,15 +87,15 @@ private String getNewFilename(Path f, Release release) {
FilenameLibraryBuilder filenameLibraryBuilder =
FilenameLibraryBuilder.fromSettings(librarySettings, manager, userInteractionHandler);
String filename = filenameLibraryBuilder.buildPathStructure(release);
if (release.fileNameOrName.endsWith(".srt")) {
if (release.folderNameOrName.endsWith(".srt")) {
Language language = null;
if (librarySettings.includeLanguageCode) {
language = DetectLanguage.execute(f);
if (language == null) {
LOGGER.error("Unable to detect language, leaving language code blank");
}
}
return filenameLibraryBuilder.buildSubtitle(release.fileNameOrName, filename, language, 0);
return filenameLibraryBuilder.buildSubtitle(release.folderNameOrName, filename, language, 0);
}
return filename;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public List<Subtitle> subtitleSelection(Release release, final boolean subtitleS
} else {
if (!subs.isEmpty()) {
LOGGER.debug("determineWhatSubtitleDownload for videoFile: [{}] # found subs: [{}]",
release.fileNameOrName, subs.size());
release.folderNameOrName, subs.size());
if (settings.optionsAlwaysConfirm) {
return userInteractionHandler.selectSubtitles(release);
} else if (subs.size() == 1 && subs.first.subtitleMatchType == SubtitleMatchType.EXACT) {
Expand All @@ -78,14 +78,14 @@ public List<Subtitle> subtitleSelection(Release release, final boolean subtitleS
return userInteractionHandler.selectSubtitles(release);
} else {
LOGGER.info("Multiple subs detected for: [{}] Unhandleable for CMD! switch to GUI or use " +
"'--selection' as switch in de CMD", release.fileNameOrName);
"'--selection' as switch in de CMD", release.folderNameOrName);
}
} else {
LOGGER.debug("determineWhatSubtitleDownload: only one sub taking it!!!!");
return List.of(subs.first);
}
}
LOGGER.debug("determineWhatSubtitleDownload: No subs found for [{}]", release.fileNameOrName);
LOGGER.debug("determineWhatSubtitleDownload: No subs found for [{}]", release.folderNameOrName);
}
return List.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CLISearchProgress() {

@Override
public void progress(SubtitleProvider provider, int jobsLeft, Release release) {
this.tableModel.update(provider.provider, jobsLeft, release.fileNameOrName);
this.tableModel.update(provider.provider, jobsLeft, release.folderNameOrName);
this.printProgress();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void rename(Path dir) throws IOException {
if (file.isRegularFile()) {
if (!file.fileNameContainsIgnoreCase("sample") && extensions.contains(file.getExtension())) {
releaseFactory.createRelease(file, userInteractionHandler).ifPresent(release -> {
publish(release.fileNameOrName);
publish(release.folderNameOrName);
if (release.isOfType(videoType)) {
moveAndRenameAction.moveAndRename(file, release);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SelectDialog(@Nullable JFrame frame=null, List<Subtitle> subtitles, Relea
contentPane
.layout(new MigLayout("", "[1000px:n,grow,fill]", "[][::100px,fill][grow]"))
.addComponent("cell 0 0",
new JLabel(getText("SelectDialog.SelectCorrectSubtitleThisRelease") + release.fileNameOrName))
new JLabel(getText("SelectDialog.SelectCorrectSubtitleThisRelease") + release.folderNameOrName))
.addComponent("cell 0 1,grow", new JScrollPane().viewportView(customTable = createCustomTable()))
.addComponent("cell 0 2,grow", new JPanel()
.layout(new FlowLayout(FlowLayout.RIGHT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void windowClosing(WindowEvent e) {
@Override
public void progress(SubtitleProvider provider, int jobsLeft, Release release) {
this.setVisible();
this.tableModel.update(provider.subtitleProviderFrontEnd.name, jobsLeft, release.fileNameOrName);
this.tableModel.update(provider.subtitleProviderFrontEnd.name, jobsLeft, release.folderNameOrName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public void setRecursiveSelected(boolean selected) {
}

public void addSelectFolderAction(ActionListener selectFolderAction) {
if (selectFolderAction != null) {
btnBrowse.addActionListener(selectFolderAction);
}
btnBrowse.addActionListener(selectFolderAction);
}

public void setIncomingPath(String path) {
Expand All @@ -72,5 +70,4 @@ public boolean isRecursiveSelected() {
public boolean isForceOverwrite() {
return chkForceSubtitleOverwrite.isSelected();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ protected Void doInBackground() {
case MovieReleaseWithPath _ ->
new MoveAndRenameAction(settings.movieLibrarySettings, manager, userInteractionHandler);
};
moveAndRenameAction.moveAndRename(selectedShow.path.resolve(selectedShow.fileName), selectedShow);
moveAndRenameAction.moveAndRename(selectedShow.path.parent.resolve(selectedShow.fileName),
selectedShow);
model.removeShow(selectedShow);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public boolean excludeSubtitle(Release release, Subtitle subtitle) {
}

protected String getReleaseName(Release release) {
return StringUtils.substringBeforeLast(release.fileNameOrName, ".");
return StringUtils.substringBeforeLast(release.folderNameOrName, ".");
}

protected boolean checkKeywordSubtitleMatch(Subtitle subtitle, String keywordsFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public String buildPathStructure(Release release) {
case MovieRelease movieRelease -> buildMovieFolderStructure(movieRelease);
};
}
return release.fileNameOrName;
return release.folderNameOrName;
}

private String buildEpisodeFolderStructure(TvRelease tvRelease) {
Expand All @@ -101,7 +101,7 @@ private String buildEpisodeFolderStructure(TvRelease tvRelease) {
filename = replace(filename, SerieStructureTag.QUALITY, tvRelease.quality);
filename = replace(filename, SerieStructureTag.RELEASE_GROUP, tvRelease.releaseGroup);

filename += "." + StringUtils.substringAfterLast(tvRelease.fileNameOrName, ".");
filename += "." + StringUtils.substringAfterLast(tvRelease.folderNameOrName, ".");
filename = filename.removeIllegalWindowsChars();
if (replaceSpace) {
filename = filename.replace(' ', replacingSpaceChar);
Expand All @@ -117,7 +117,7 @@ private String buildMovieFolderStructure(MovieRelease movieRelease) {
filename = replace(filename, MovieStructureTag.QUALITY, movieRelease.quality);
filename = replace(filename, MovieStructureTag.RELEASE_GROUP, movieRelease.releaseGroup);

filename += "." + StringUtils.substringAfterLast(movieRelease.fileNameOrName, ".");
filename += "." + StringUtils.substringAfterLast(movieRelease.folderNameOrName, ".");

filename = filename.removeIllegalWindowsChars();
if (replaceSpace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Path buildPath(ReleaseWithPath release) {
};
return libraryFolder.resolve(pathStructure.split(FolderStructureTag.SEPARATOR.label));
} else {
return release.path;
return release.path.parent;
}
}

Expand All @@ -75,7 +75,7 @@ public String buildPathStructure(Release release) {
case MovieRelease movieRelease -> buildMovieFolderStructure(movieRelease);
};
} else {
return release.fileNameOrName;
return release.folderNameOrName;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Set<SUB> searchSubtitles(MovieRelease movieRelease, Language language) {
}
if (subtitles.isEmpty()) {
if (movieRelease instanceof MovieReleaseWithPath release) {
Path file = release.path.resolve(release.fileName);
Path file = release.path.parent.resolve(release.fileName);
if (file.exists()) {
try {
subtitles.addAll(searchMovieSubtitlesWithHash(FileHasher.computeHash(file), language));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import java.util.HashSet;
import java.util.Set;

import manifold.ext.props.rt.api.val;
import org.jspecify.annotations.NullMarked;
import org.lodder.subtools.sublibrary.model.Subtitle;

@NullMarked
public class SubtitleProviderStore {
protected final Set<SubtitleProvider<? extends Subtitle>> subtitleProviders = new HashSet<>();

@val Set<SubtitleProvider<? extends Subtitle>> allProviders = Set.copyOf(this.subtitleProviders);
public Set<SubtitleProvider<? extends Subtitle>> getAllProviders() {
return Set.copyOf(this.subtitleProviders);
}

public void addProvider(SubtitleProvider<? extends Subtitle> provider) {
this.subtitleProviders.add(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import manifold.ext.props.rt.api.val;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class PropertiesReader {
Expand All @@ -31,7 +32,7 @@ private static PropertiesReader getPropertiesReader() {
return propertiesReaderInstance;
}

public static String getProperty(PomProperty property) {
public static @Nullable String getProperty(PomProperty property) {
return PropertiesReader.getPropertiesReader().properties.getProperty(property.value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private Settings createSettings(boolean keyword, boolean exact, boolean excludeh
private ReleaseWithoutPath createRelease(String filename, String releasegroup) {
ReleaseWithoutPath release = mock(TvReleaseWithoutPath.class);

when(release.fileNameOrName).thenReturn(filename);
when(release.folderNameOrName).thenReturn(filename);
when(release.releaseGroup).thenReturn(releasegroup);

return release;
Expand Down
Loading
Loading