Skip to content

Commit

Permalink
code clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
kookxiang committed Feb 4, 2025
1 parent 95f7630 commit 318eb6a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading;
Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.Bangumi/BangumiApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public async Task<IEnumerable<PersonInfo>> GetSubjectPersonInfos(int id, Cancell
{
if (id <= 0) return [];
var persons = await GetSubjectPersons(id, token);
return persons?.Select(person => person.ToPersonInfo()).Where(info => info != null) as IEnumerable<PersonInfo> ?? [];
return (persons ?? []).Select(person => person.ToPersonInfo()).Where(info => info != null)!;
}

public async Task<Episode?> GetEpisode(int id, CancellationToken token)
Expand Down
8 changes: 4 additions & 4 deletions Jellyfin.Plugin.Bangumi/Model/RelatedCharacter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using MediaBrowser.Controller.Entities;
#if EMBY
using PersonEntityType = MediaBrowser.Model.Entities.PersonType;
#else
using Jellyfin.Data.Enums;
#endif
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using MediaBrowser.Controller.Entities;

namespace Jellyfin.Plugin.Bangumi.Model;

Expand Down
6 changes: 3 additions & 3 deletions Jellyfin.Plugin.Bangumi/Model/RelatedPerson.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using MediaBrowser.Controller.Entities;
#if EMBY
using PersonEntityType = MediaBrowser.Model.Entities.PersonType;
#else
using Jellyfin.Data.Enums;
#endif
using System.Collections.Generic;
using System.Text.Json.Serialization;
using MediaBrowser.Controller.Entities;

namespace Jellyfin.Plugin.Bangumi.Model;

Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static bool IsSpecial(string filePath, bool checkParent = true)
var parentPath = Path.GetDirectoryName(filePath);
var folderName = Path.GetFileName(parentPath);
return SpecialEpisodeFileNameRegex().IsMatch(fileName) ||
(checkParent && SpecialEpisodeFileNameRegex().IsMatch(folderName ?? ""));
checkParent && SpecialEpisodeFileNameRegex().IsMatch(folderName ?? "");
}

private async Task<Model.Episode?> GetEpisode(EpisodeInfo info, LocalConfiguration localConfiguration, CancellationToken token)
Expand Down
1 change: 0 additions & 1 deletion Jellyfin.Plugin.Bangumi/Providers/SubjectImageProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down
8 changes: 4 additions & 4 deletions Jellyfin.Plugin.Bangumi/ScheduledTask/ArchiveDownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public async Task ExecuteAsync(IProgress<double> progress, CancellationToken can
var entry = zipStream.GetEntry(fileName);
if (entry == null)
throw new FileNotFoundException($"{fileName} not found in archive file");
progress.Report(65D + (30D * (completed + 0.2D) / archive.Stores.Count));
progress.Report(65D + 30D * (completed + 0.2D) / archive.Stores.Count);

await using (var writeStream = File.OpenWrite(newStore.FilePath))
{
Expand All @@ -72,17 +72,17 @@ public async Task ExecuteAsync(IProgress<double> progress, CancellationToken can
await writeStream.FlushAsync(cancellationToken);
}

progress.Report(65D + (30D * (completed + 0.5D) / archive.Stores.Count));
progress.Report(65D + 30D * (completed + 0.5D) / archive.Stores.Count);

log.Info("generating index for {TempName}", $"temp/{newFileName}");
await newStore.GenerateIndex(cancellationToken);
progress.Report(65D + (30D * (completed + 0.8D) / archive.Stores.Count));
progress.Report(65D + 30D * (completed + 0.8D) / archive.Stores.Count);

log.Info("replacing {FileName} and index files with {TempName}", fileName, $"temp/{newFileName}");
await oldStore.Move(archive.TempPath, Path.GetRandomFileName());
await newStore.Move(archive.BasePath, fileName);

progress.Report(65D + (30D * ++completed / archive.Stores.Count));
progress.Report(65D + 30D * ++completed / archive.Stores.Count);
}

await archive.SubjectRelations.GenerateIndex(zipStream, cancellationToken);
Expand Down

0 comments on commit 318eb6a

Please sign in to comment.