Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Improves Wasari tvdb matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Cordeiro committed Apr 16, 2023
1 parent c269409 commit 8196a86
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Wasari.Crunchyroll/EpisodeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand All @@ -9,8 +10,10 @@

namespace Wasari.Crunchyroll;

internal static class EpisodeExtensions
internal static partial class EpisodeExtensions
{
private static string NormalizeUsingRegex(this string str) => string.Join(string.Empty, EpisodeTitleNormalizeRegex().Matches(str).Select(o => o.Value));

public static async IAsyncEnumerable<ApiEpisode> EnrichWithWasariApi(this IAsyncEnumerable<ApiEpisode> episodes, IServiceProvider serviceProvider, IOptions<DownloadOptions> downloadOptions)
{
var wasariTvdbApi = downloadOptions.Value.TryEnrichEpisodes ? serviceProvider.GetService<IWasariTvdbApi>() : null;
Expand Down Expand Up @@ -64,7 +67,7 @@ public static async IAsyncEnumerable<ApiEpisode> EnrichWithWasariApi(this IAsync
{
wasariEpisode = wasariApiEpisodes
.Where(i => !i.IsMovie)
.SingleOrDefault(o => o.Name.StartsWith(episode.Title, StringComparison.InvariantCultureIgnoreCase));
.SingleOrDefault(o => o.Name.NormalizeUsingRegex().StartsWith(episode.Title.NormalizeUsingRegex(), StringComparison.InvariantCultureIgnoreCase));

if (wasariEpisode == null)
{
Expand Down Expand Up @@ -99,4 +102,7 @@ public static async IAsyncEnumerable<ApiEpisode> EnrichWithWasariApi(this IAsync
yield return episode;
}
}

[GeneratedRegex("[a-zA-Z0-9 ]+")]
private static partial Regex EpisodeTitleNormalizeRegex();
}

0 comments on commit 8196a86

Please sign in to comment.