Beispiel #1
0
        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());
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public void FindImdbId_Invalid_Success(string text)
 {
     Assert.False(ProviderIdParsers.TryFindImdbId(text, out _));
 }
Beispiel #4
0
 public void FindImdbId_Valid_Success(string text, string expected)
 {
     Assert.True(ProviderIdParsers.TryFindImdbId(text, out ReadOnlySpan <char> parsedId));
     Assert.Equal(expected, parsedId.ToString());
 }