File multiepisodes.patch of Package MediaElch21812
diff -ru MediaElch-orig/src/tv_shows/TvShowFileSearcher.cpp MediaElch/src/tv_shows/TvShowFileSearcher.cpp
--- MediaElch-orig/src/tv_shows/TvShowFileSearcher.cpp 2021-05-10 08:59:30.000000000 +0200
+++ MediaElch/src/tv_shows/TvShowFileSearcher.cpp 2022-09-04 23:27:20.211009618 +0200
@@ -388,15 +388,16 @@
lastMatchEnd = match.capturedEnd(0);
}
- // Pattern matched
+ // Pattern did not match
if (episodes.isEmpty()) {
return false;
}
// The one episode we found could actually be a multi-episode file.
- // For example: S01E01E02
+ // To avoid false positives, we use a positive lookahead.
+ // For example: "S01E01E02E03 - Name.mov"
if (episodes.count() == 1) {
- rx.setPattern(R"([-_EeXx]+([0-9]+)($|[\-\._\sE]))");
+ rx.setPattern(R"([-_EeXx]+(\d+)(?=$|[\-\._\sEeXx]))");
matches = rx.globalMatch(
filename, lastMatchEnd, QRegularExpression::NormalMatch, QRegularExpression::AnchoredMatchOption);
while (matches.hasNext()) {
diff -ru MediaElch-orig/test/unit/tv_shows/testTvShowFileSearcher.cpp MediaElch/test/unit/tv_shows/testTvShowFileSearcher.cpp
--- MediaElch-orig/test/unit/tv_shows/testTvShowFileSearcher.cpp 2021-05-10 08:59:30.000000000 +0200
+++ MediaElch/test/unit/tv_shows/testTvShowFileSearcher.cpp 2022-09-04 23:29:09.734778618 +0200
@@ -66,8 +66,10 @@
CHECK(getEpisodeNumbers("dir/S01E14-S01E115.mov") == episodeList({14, 115}));
CHECK(getEpisodeNumbers("dir/S01E004-S01E005.mov") == episodeList({4, 5}));
CHECK(getEpisodeNumbers("dir/S01E004-S01E005-S01E15.mov") == episodeList({4, 5, 15}));
+ CHECK(getEpisodeNumbers("dir/S01E02E03E04E06.mov") == episodeList({2, 3, 4, 6}));
- CHECK(getEpisodeNumbers("dir/Name_S01E4-S01E5.mov") == episodeList({4, 5}));
+ // Note: No episode ranges.
+ CHECK(getEpisodeNumbers("dir/Name_S01E4-S01E6.mov") == episodeList({4, 6}));
CHECK(getEpisodeNumbers("dir/S01E4 Name with space S01E05 Second name.mov") == episodeList({4, 5}));
CHECK(getEpisodeNumbers("dir/S01E14-S01E115 - Some name.mov") == episodeList({14, 115}));
CHECK(getEpisodeNumbers("dir/S01E004.S01E005-Another-Title.mov") == episodeList({4, 5}));