diff options
| author | Claus Vium <clausvium@gmail.com> | 2019-08-15 14:54:22 +0200 |
|---|---|---|
| committer | Claus Vium <clausvium@gmail.com> | 2019-08-15 14:54:22 +0200 |
| commit | f4a99beb161d1444af686f5a54ce7bdc1b0790a8 (patch) | |
| tree | ad9e21da7f1e22dcaee7a2d2ba38875279014314 | |
| parent | 685e9e4f58c2e00a0157098a2309b2cb97cb2f14 (diff) | |
Fix tvdb guest stars loop
| -rw-r--r-- | MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index 302d40c6b..287da36d4 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Net; @@ -193,24 +194,43 @@ namespace MediaBrowser.Providers.TV.TheTVDB }); } - foreach (var person in episode.GuestStars) + // GuestStars is a weird list of names and roles + // Example: + // 1: Some Actor (Role1 + // 2: Role2 + // 3: Role3) + // 4: Another Actor (Role1 + // ... + for (var i = 0; i < episode.GuestStars.Length; ++i) { - var index = person.IndexOf('('); - string role = null; - var name = person; + var currentActor = episode.GuestStars[i]; + var roleStartIndex = currentActor.IndexOf('('); - if (index != -1) + var roles = new List<string> {currentActor.Substring(roleStartIndex + 1)}; + var name = currentActor.Substring(0, roleStartIndex).Trim(); + + // Fetch all roles + for (var j = i + 1; j < episode.GuestStars.Length; ++j) { - role = person.Substring(index + 1).Trim().TrimEnd(')'); + var currentRole = episode.GuestStars[j]; + var roleEndIndex = currentRole.IndexOf(')'); + + if (roleEndIndex != -1) + { + roles.Add(currentRole.TrimEnd(')')); + // Update the outer index (keep in mind it adds 1 after the iteration) + i = j; + break; + } - name = person.Substring(0, index).Trim(); + roles.Add(currentRole); } result.AddPerson(new PersonInfo { Type = PersonType.GuestStar, Name = name, - Role = role + Role = string.Join(", ", roles) }); } |
