protected void ParseProviderLinks(T item, string xml) { if (ProviderIdParsers.TryFindImdbId(xml, out var imdbId)) { item.SetProviderId(MetadataProvider.Imdb, imdbId.ToString()); } if (item is Movie) { if (ProviderIdParsers.TryFindTmdbMovieId(xml, out var tmdbId)) { item.SetProviderId(MetadataProvider.Tmdb, tmdbId.ToString()); } } if (item is Series) { if (ProviderIdParsers.TryFindTmdbSeriesId(xml, out var tmdbId)) { item.SetProviderId(MetadataProvider.Tmdb, tmdbId.ToString()); } if (ProviderIdParsers.TryFindTvdbId(xml, out var tvdbId)) { item.SetProviderId(MetadataProvider.Tvdb, tvdbId.ToString()); } } }
public static string?GetAttributeValue(this string str, string attribute) { if (str.Length == 0) { throw new ArgumentException("String can't be empty.", nameof(str)); } if (attribute.Length == 0) { throw new ArgumentException("String can't be empty.", nameof(attribute)); } string srch = "[" + attribute + "="; int start = str.IndexOf(srch, StringComparison.OrdinalIgnoreCase); if (start != -1) { start += srch.Length; int end = str.IndexOf(']', start); return(str.Substring(start, end - start)); } // for imdbid we also accept pattern matching if (string.Equals(attribute, "imdbid", StringComparison.OrdinalIgnoreCase)) { var match = ProviderIdParsers.TryFindImdbId(str, out var imdbId); return(match ? imdbId.ToString() : null); } return(null); }
public void FindTvdbId_Invalid_Success(string text) { Assert.False(ProviderIdParsers.TryFindTvdbId(text, out _)); }
public void FindTvdbId_Valid_Success(string text, string expected) { Assert.True(ProviderIdParsers.TryFindTvdbId(text, out ReadOnlySpan <char> parsedId)); Assert.Equal(expected, parsedId.ToString()); }