From f4a99beb161d1444af686f5a54ce7bdc1b0790a8 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Thu, 15 Aug 2019 14:54:22 +0200 Subject: [PATCH 1/7] Fix tvdb guest stars loop --- .../TV/TheTVDB/TvdbEpisodeProvider.cs | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index 302d40c6b7..287da36d48 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 {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(')'); - name = person.Substring(0, index).Trim(); + if (roleEndIndex != -1) + { + roles.Add(currentRole.TrimEnd(')')); + // Update the outer index (keep in mind it adds 1 after the iteration) + i = j; + break; + } + + roles.Add(currentRole); } result.AddPerson(new PersonInfo { Type = PersonType.GuestStar, Name = name, - Role = role + Role = string.Join(", ", roles) }); } From f7f3627bb12eb06e104d5c52e074c45c37e6e4ca Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Thu, 15 Aug 2019 14:56:49 +0200 Subject: [PATCH 2/7] Remove unused import --- MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index 287da36d48..5249a3fc03 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Net; From 11504321b5e76a0eb9bda57bfcae4f85df994384 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Thu, 15 Aug 2019 19:54:01 +0200 Subject: [PATCH 3/7] Handle negative roleStartIndex since not all guest stars have roles --- .../TV/TheTVDB/TvdbEpisodeProvider.cs | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index 5249a3fc03..5b0f326c0e 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -205,31 +205,38 @@ namespace MediaBrowser.Providers.TV.TheTVDB var currentActor = episode.GuestStars[i]; var roleStartIndex = currentActor.IndexOf('('); - var roles = new List {currentActor.Substring(roleStartIndex + 1)}; - var name = currentActor.Substring(0, roleStartIndex).Trim(); - - // Fetch all roles - for (var j = i + 1; j < episode.GuestStars.Length; ++j) + string name = currentActor; + string role = ""; + if (roleStartIndex != -1) { - var currentRole = episode.GuestStars[j]; - var roleEndIndex = currentRole.IndexOf(')'); + var roles = new List {currentActor.Substring(roleStartIndex + 1)}; + name = name.Substring(0, roleStartIndex).Trim(); - if (roleEndIndex != -1) + // Fetch all roles + for (var j = i + 1; j < episode.GuestStars.Length; ++j) { - roles.Add(currentRole.TrimEnd(')')); - // Update the outer index (keep in mind it adds 1 after the iteration) - i = j; - break; + 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; + } + + roles.Add(currentRole); } - roles.Add(currentRole); + role = string.Join(", ", roles); } result.AddPerson(new PersonInfo { Type = PersonType.GuestStar, Name = name, - Role = string.Join(", ", roles) + Role = role }); } From 26b4fb21fe7992d5a489ed2ced74ee58671ee2d4 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Fri, 16 Aug 2019 19:53:28 +0200 Subject: [PATCH 4/7] Update MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs Co-Authored-By: Bond-009 --- MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index 5b0f326c0e..59df6ade4f 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -206,7 +206,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB var roleStartIndex = currentActor.IndexOf('('); string name = currentActor; - string role = ""; + string role = string.Empty; if (roleStartIndex != -1) { var roles = new List {currentActor.Substring(roleStartIndex + 1)}; From 15f7a2078b010b2a5aa644e05832a83e02c41bf0 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Fri, 16 Aug 2019 19:58:44 +0200 Subject: [PATCH 5/7] Invert the if --- .../TV/TheTVDB/TvdbEpisodeProvider.cs | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index 59df6ade4f..36e172dfbd 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -205,38 +205,41 @@ namespace MediaBrowser.Providers.TV.TheTVDB var currentActor = episode.GuestStars[i]; var roleStartIndex = currentActor.IndexOf('('); - string name = currentActor; - string role = string.Empty; - if (roleStartIndex != -1) + if (roleStartIndex == -1) { - var roles = new List {currentActor.Substring(roleStartIndex + 1)}; - name = name.Substring(0, roleStartIndex).Trim(); - - // Fetch all roles - for (var j = i + 1; j < episode.GuestStars.Length; ++j) + result.AddPerson(new PersonInfo { - var currentRole = episode.GuestStars[j]; - var roleEndIndex = currentRole.IndexOf(')'); + Type = PersonType.GuestStar, + Name = currentActor, + Role = string.Empty + }); + continue; + } - if (roleEndIndex != -1) - { - roles.Add(currentRole.TrimEnd(')')); - // Update the outer index (keep in mind it adds 1 after the iteration) - i = j; - break; - } + var roles = new List {currentActor.Substring(roleStartIndex + 1)}; - roles.Add(currentRole); + // Fetch all roles + for (var j = i + 1; j < episode.GuestStars.Length; ++j) + { + 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; } - role = string.Join(", ", roles); + roles.Add(currentRole); } result.AddPerson(new PersonInfo { Type = PersonType.GuestStar, - Name = name, - Role = role + Name = currentActor.Substring(0, roleStartIndex).Trim(), + Role = string.Join(", ", roles) }); } From daf29233e6350f97eb585d21d99e708ced8e66b7 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Fri, 16 Aug 2019 20:07:00 +0200 Subject: [PATCH 6/7] Invert the second if --- .../TV/TheTVDB/TvdbEpisodeProvider.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index 36e172dfbd..22c630d980 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -224,15 +224,15 @@ namespace MediaBrowser.Providers.TV.TheTVDB var currentRole = episode.GuestStars[j]; var roleEndIndex = currentRole.IndexOf(')'); - if (roleEndIndex != -1) + if (roleEndIndex == -1) { - roles.Add(currentRole.TrimEnd(')')); - // Update the outer index (keep in mind it adds 1 after the iteration) - i = j; - break; + roles.Add(currentRole); } - roles.Add(currentRole); + roles.Add(currentRole.TrimEnd(')')); + // Update the outer index (keep in mind it adds 1 after the iteration) + i = j; + break; } result.AddPerson(new PersonInfo From e4158d9703c8490a0a918422cb2180fec5cb65b9 Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Fri, 16 Aug 2019 20:11:01 +0200 Subject: [PATCH 7/7] Continue --- MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index 22c630d980..b03794ba05 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -227,6 +227,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB if (roleEndIndex == -1) { roles.Add(currentRole); + continue; } roles.Add(currentRole.TrimEnd(')'));