Handle negative roleStartIndex since not all guest stars have roles

This commit is contained in:
Claus Vium 2019-08-15 19:54:01 +02:00
parent f7f3627bb1
commit 11504321b5

View file

@ -205,31 +205,38 @@ namespace MediaBrowser.Providers.TV.TheTVDB
var currentActor = episode.GuestStars[i]; var currentActor = episode.GuestStars[i];
var roleStartIndex = currentActor.IndexOf('('); var roleStartIndex = currentActor.IndexOf('(');
var roles = new List<string> {currentActor.Substring(roleStartIndex + 1)}; string name = currentActor;
var name = currentActor.Substring(0, roleStartIndex).Trim(); string role = "";
if (roleStartIndex != -1)
// Fetch all roles
for (var j = i + 1; j < episode.GuestStars.Length; ++j)
{ {
var currentRole = episode.GuestStars[j]; var roles = new List<string> {currentActor.Substring(roleStartIndex + 1)};
var roleEndIndex = currentRole.IndexOf(')'); 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(')')); var currentRole = episode.GuestStars[j];
// Update the outer index (keep in mind it adds 1 after the iteration) var roleEndIndex = currentRole.IndexOf(')');
i = j;
break; 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 result.AddPerson(new PersonInfo
{ {
Type = PersonType.GuestStar, Type = PersonType.GuestStar,
Name = name, Name = name,
Role = string.Join(", ", roles) Role = role
}); });
} }