|
29 | 29 | import java.util.Date;
|
30 | 30 | import java.util.List;
|
31 | 31 | import java.util.Optional;
|
| 32 | +import java.util.stream.Collectors; |
32 | 33 |
|
33 | 34 | @Service
|
34 | 35 | public class MediaServiceImpl implements MediaService {
|
@@ -75,6 +76,19 @@ private void generateMediaDirBySingleAnimeEntity(@Nonnull AnimeEntity animeEntit
|
75 | 76 | animeDirName += " (" + localDateTime.getYear() + "-" + localDateTime.getMonthValue()
|
76 | 77 | + "-" + localDateTime.getDayOfMonth() + ")";
|
77 | 78 | }
|
| 79 | + |
| 80 | + // remove char \ / : * ? " < > | |
| 81 | + animeDirName = animeDirName |
| 82 | + .replace("\\", "") |
| 83 | + .replace("/", "") |
| 84 | + .replace(":", "") |
| 85 | + .replace("*", "") |
| 86 | + .replace("?", "") |
| 87 | + .replace("\"", "") |
| 88 | + .replace("<", "") |
| 89 | + .replace(">", "") |
| 90 | + .replace("|", ""); |
| 91 | + |
78 | 92 | final String animeDirPath = SystemVarUtils.getCurrentAppMediaDirPath()
|
79 | 93 | + File.separator + animeDirName;
|
80 | 94 | File animeDir = new File(animeDirPath);
|
@@ -181,7 +195,7 @@ private void generateMediaDirBySingleSeason(@Nonnull String animeDirPath,
|
181 | 195 | uploadEpFilePath, seasonEntity.getTitle(), episodeEntity.getTitle());
|
182 | 196 | continue;
|
183 | 197 | }
|
184 |
| - Optional<FileEntity> fileEntityOptional = fileService.findByUrl(url); |
| 198 | + Optional<FileEntity> fileEntityOptional = fileService.findByUrl(episodeEntity.getUrl()); |
185 | 199 | String fileName;
|
186 | 200 | if (fileEntityOptional.isPresent()) {
|
187 | 201 | fileName = fileEntityOptional.get().getName();
|
@@ -220,6 +234,46 @@ private void generateMediaDirBySingleSeason(@Nonnull String animeDirPath,
|
220 | 234 | episodeEntity.getOverview(), episodePlot, String.valueOf(seasonNum),
|
221 | 235 | String.valueOf(seq), String.valueOf(bgmtvId));
|
222 | 236 | }
|
| 237 | + |
| 238 | + // link episode subtitle file |
| 239 | + List<FileEntity> existsFileEntityList = |
| 240 | + fileService.findListByNameLike(fileName.replaceAll(RegexConst.FILE_POSTFIX, "")) |
| 241 | + .stream() |
| 242 | + .filter(fileEntity -> !fileName.equalsIgnoreCase(fileEntity.getName())) |
| 243 | + .toList(); |
| 244 | + if (!existsFileEntityList.isEmpty()) { |
| 245 | + for (FileEntity fileEntity : existsFileEntityList) { |
| 246 | + String name = fileEntity.getName(); |
| 247 | + String postfix = FileUtils.parseFilePostfix(name); |
| 248 | + if ("ass".equalsIgnoreCase(postfix) |
| 249 | + && name.contains( |
| 250 | + fileName.replaceAll(RegexConst.FILE_POSTFIX, ""))) { |
| 251 | + File mediaSubtitleFile = |
| 252 | + new File(seasonDirPath + File.separator + name); |
| 253 | + File uploadSubtitleFile = new File( |
| 254 | + SystemVarUtils.getCurrentAppDirPath() |
| 255 | + + File.separator + fileEntity.getUrl()); |
| 256 | + if (mediaSubtitleFile.exists()) { |
| 257 | + continue; |
| 258 | + } |
| 259 | + try { |
| 260 | + Files.createLink(mediaSubtitleFile.toPath(), |
| 261 | + uploadSubtitleFile.toPath()); |
| 262 | + LOGGER.info( |
| 263 | + "create media episode subtitle hard link success, " |
| 264 | + + "link={}, existing={}", |
| 265 | + mediaSubtitleFile.getAbsolutePath(), |
| 266 | + uploadSubtitleFile.getAbsolutePath()); |
| 267 | + } catch (IOException e) { |
| 268 | + LOGGER.error( |
| 269 | + "create media episode subtitle hard link fail, link={}, " |
| 270 | + + "existing={}", |
| 271 | + mediaSubtitleFile.getAbsolutePath(), |
| 272 | + uploadSubtitleFile.getAbsolutePath()); |
| 273 | + } |
| 274 | + } |
| 275 | + } |
| 276 | + } |
223 | 277 | }
|
224 | 278 | }
|
225 | 279 |
|
|
0 commit comments