Beispiel #1
0
        private void FetchDataFromTrailersNode(XmlReader reader, IHasTrailers item)
        {
            reader.MoveToContent();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Trailer":
                    {
                        var val = reader.ReadElementContentAsString();

                        if (!string.IsNullOrWhiteSpace(val))
                        {
                            item.AddTrailerUrl(val, false);
                        }
                        break;
                    }

                    default:
                        reader.Skip();
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds the trailer URL.
        /// </summary>
        public static void AddTrailerUrl(this IHasTrailers item, string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }

            var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));

            if (current == null)
            {
                var mediaUrl = new MediaUrl
                {
                    Url = url
                };

                if (item.RemoteTrailers.Length == 0)
                {
                    item.RemoteTrailers = new[] { mediaUrl };
                }
                else
                {
                    var list = item.RemoteTrailers.ToArray(item.RemoteTrailers.Length + 1);
                    list[list.Length - 1] = mediaUrl;

                    item.RemoteTrailers = list;
                }
            }
        }
        private void FetchDataFromTrailersNode(XmlReader reader, IHasTrailers item)
        {
            reader.MoveToContent();
            reader.Read();

            // Loop through each element
            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Trailer":
                    {
                        var val = reader.ReadElementContentAsString();

                        if (!string.IsNullOrWhiteSpace(val))
                        {
                            item.AddTrailerUrl(val);
                        }
                        break;
                    }

                    default:
                        reader.Skip();
                        break;
                    }
                }
                else
                {
                    reader.Read();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets the trailer ids.
        /// </summary>
        /// <returns>List&lt;Guid&gt;.</returns>
        public static List <Guid> GetTrailerIds(this IHasTrailers item)
        {
            var list = item.LocalTrailerIds.ToList();

            list.AddRange(item.RemoteTrailerIds);
            return(list);
        }
Beispiel #5
0
        /// <summary>
        /// Adds the trailer URL.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="url">The URL.</param>
        /// <param name="isDirectLink">if set to <c>true</c> [is direct link].</param>
        /// <exception cref="System.ArgumentNullException">url</exception>
        public static void AddTrailerUrl(this IHasTrailers item, string url, bool isDirectLink)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException("url");
            }

            var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));

            if (current == null)
            {
                item.RemoteTrailers.Add(new MediaUrl
                {
                    Url = url
                });
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets the trailer ids.
        /// </summary>
        /// <returns><see cref="IReadOnlyList{Guid}" />.</returns>
        public static IReadOnlyList <Guid> GetTrailerIds(this IHasTrailers item)
        {
            var localIds  = item.LocalTrailerIds;
            var remoteIds = item.RemoteTrailerIds;

            var all   = new Guid[localIds.Count + remoteIds.Count];
            var index = 0;

            foreach (var id in localIds)
            {
                all[index++] = id;
            }

            foreach (var id in remoteIds)
            {
                all[index++] = id;
            }

            return(all);
        }
Beispiel #7
0
        /// <summary>
        /// Gets the trailers.
        /// </summary>
        /// <returns><see cref="IReadOnlyList{BaseItem}" />.</returns>
        public static IReadOnlyList <BaseItem> GetTrailers(this IHasTrailers item)
        {
            var localIds       = item.LocalTrailerIds;
            var remoteIds      = item.RemoteTrailerIds;
            var libraryManager = BaseItem.LibraryManager;

            var all   = new BaseItem[localIds.Count + remoteIds.Count];
            var index = 0;

            foreach (var id in localIds)
            {
                all[index++] = libraryManager.GetItemById(id);
            }

            foreach (var id in remoteIds)
            {
                all[index++] = libraryManager.GetItemById(id);
            }

            return(all);
        }
Beispiel #8
0
        private async Task AssignTrailers(IHasTrailers item, BaseItem[] channelTrailers)
        {
            if (item is Game)
            {
                return;
            }

            var imdbId = item.GetProviderId(MetadataProviders.Imdb);
            var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);

            var trailers = channelTrailers.Where(i =>
            {
                if (!string.IsNullOrWhiteSpace(imdbId) &&
                    string.Equals(imdbId, i.GetProviderId(MetadataProviders.Imdb), StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }
                if (!string.IsNullOrWhiteSpace(tmdbId) &&
                    string.Equals(tmdbId, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }
                return(false);
            });

            var trailerIds = trailers.Select(i => i.Id)
                             .ToList();

            if (!trailerIds.SequenceEqual(item.RemoteTrailerIds))
            {
                item.RemoteTrailerIds = trailerIds;

                var baseItem = (BaseItem)item;
                await baseItem.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None)
                .ConfigureAwait(false);
            }
        }
        private async Task AssignTrailers(IHasTrailers item, BaseItem[] channelTrailers)
        {
            if (item is Game)
            {
                return;
            }

            var imdbId = item.GetProviderId(MetadataProviders.Imdb);
            var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);

            var trailers = channelTrailers.Where(i =>
            {
                if (!string.IsNullOrWhiteSpace(imdbId) &&
                    string.Equals(imdbId, i.GetProviderId(MetadataProviders.Imdb), StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
                if (!string.IsNullOrWhiteSpace(tmdbId) &&
                    string.Equals(tmdbId, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
                return false;
            });

            var trailerIds = trailers.Select(i => i.Id)
                .ToList();

            if (!trailerIds.SequenceEqual(item.RemoteTrailerIds))
            {
                item.RemoteTrailerIds = trailerIds;

                var baseItem = (BaseItem)item;
                await baseItem.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None)
                        .ConfigureAwait(false);
            }
        }
        private void AssignTrailers(IHasTrailers item, IEnumerable <BaseItem> channelTrailers)
        {
            if (item is Game)
            {
                return;
            }

            var imdbId = item.GetProviderId(MetadataProviders.Imdb);
            var tmdbId = item.GetProviderId(MetadataProviders.Tmdb);

            var trailers = channelTrailers.Where(i =>
            {
                if (!string.IsNullOrEmpty(imdbId) &&
                    string.Equals(imdbId, i.GetProviderId(MetadataProviders.Imdb), StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }
                if (!string.IsNullOrEmpty(tmdbId) &&
                    string.Equals(tmdbId, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase))
                {
                    return(true);
                }
                return(false);
            });

            var trailerIds = trailers.Select(i => i.Id)
                             .ToArray();

            if (!trailerIds.SequenceEqual(item.RemoteTrailerIds))
            {
                item.RemoteTrailerIds = trailerIds;

                var baseItem = (BaseItem)item;
                baseItem.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None);
            }
        }
Beispiel #11
0
 /// <summary>
 /// Gets the trailer count.
 /// </summary>
 /// <returns><see cref="IReadOnlyList{Guid}" />.</returns>
 public static int GetTrailerCount(this IHasTrailers item)
 => item.LocalTrailerIds.Count + item.RemoteTrailerIds.Count;