Exemple #1
0
        private async Task <QueryResult <ServerItem> > GetItemsFromPerson(Person person, User user, int?startIndex, int?limit)
        {
            var items = user.RootFolder.GetRecursiveChildren(user)
                        .Where(i => i is Movie || i is Series)
                        .Where(i => i.ContainsPerson(person.Name))
                        .ToList();

            var trailerResult = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery
            {
                ContentTypes = new[] { ChannelMediaContentType.MovieExtra },
                ExtraTypes   = new[] { ExtraType.Trailer },
                UserId       = user.Id.ToString("N")
            }, CancellationToken.None).ConfigureAwait(false);

            var currentIds = items.Select(i => i.GetProviderId(MetadataProviders.Imdb))
                             .ToList();

            var trailersToAdd = trailerResult.Items
                                .Where(i => i.ContainsPerson(person.Name))
                                .Where(i =>
            {
                // Try to filter out dupes using imdb id
                var imdb = i.GetProviderId(MetadataProviders.Imdb);
                if (!string.IsNullOrWhiteSpace(imdb) &&
                    currentIds.Contains(imdb, StringComparer.OrdinalIgnoreCase))
                {
                    return(false);
                }
                return(true);
            });

            items.AddRange(trailersToAdd);

            items = _libraryManager.Sort(items, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending)
                    .Skip(startIndex ?? 0)
                    .Take(limit ?? int.MaxValue)
                    .ToList();

            var serverItems = items.Select(i => new ServerItem
            {
                Item     = i,
                StubType = null
            })
                              .ToArray();

            return(new QueryResult <ServerItem>
            {
                TotalRecordCount = serverItems.Length,
                Items = serverItems
            });
        }
Exemple #2
0
        private async Task <QueryResult <BaseItem> > GetAllTrailers(User user)
        {
            var trailerResult = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery
            {
                ContentTypes = new[] { ChannelMediaContentType.MovieExtra },
                ExtraTypes   = new[] { ExtraType.Trailer },
                UserId       = user.Id.ToString("N")
            }, CancellationToken.None).ConfigureAwait(false);


            return(new QueryResult <BaseItem>
            {
                Items = trailerResult.Items,
                TotalRecordCount = trailerResult.TotalRecordCount
            });
        }
        private async Task DownloadAllChannelContent(string userId,
                                                     CancellationToken cancellationToken,
                                                     IProgress <double> progress)
        {
            var result = await _manager.GetAllMediaInternal(new AllChannelMediaQuery
            {
                UserId = userId
            }, cancellationToken).ConfigureAwait(false);

            progress.Report(5);

            var innerProgress = new ActionableProgress <double>();

            innerProgress.RegisterAction(p => progress.Report(5 + (.95 * p)));

            var path = _manager.ChannelDownloadPath;

            await DownloadChannelContent(result, path, cancellationToken, innerProgress).ConfigureAwait(false);
        }
Exemple #4
0
        /// <summary>
        /// Downloads the trailer for item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="contentType">Type of the content.</param>
        /// <param name="providersToMatch">The providers to match.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public async Task DownloadTrailerForItem(BaseItem item, ChannelMediaContentType contentType, List <MetadataProviders> providersToMatch, CancellationToken cancellationToken)
        {
            var providerValues = providersToMatch.Select(item.GetProviderId)
                                 .ToList();

            if (providerValues.All(string.IsNullOrWhiteSpace))
            {
                return;
            }

            var channelTrailers = await _channelManager.GetAllMediaInternal(new AllChannelMediaQuery
            {
                ContentTypes = new[] { contentType },
                ExtraTypes   = new[] { ExtraType.Trailer }
            }, CancellationToken.None);

            var channelItem = channelTrailers
                              .Items
                              .OfType <IChannelMediaItem>()
                              .FirstOrDefault(i =>
            {
                var currentProviderValues = providersToMatch.Select(i.GetProviderId).ToList();

                var index = 0;
                foreach (var val in providerValues)
                {
                    if (!string.IsNullOrWhiteSpace(val) && string.Equals(currentProviderValues[index], val, StringComparison.OrdinalIgnoreCase))
                    {
                        return(true);
                    }
                    index++;
                }

                return(false);
            });

            if (channelItem == null)
            {
                return;
            }

            var destination = Directory.Exists(item.Path) ?
                              Path.Combine(item.Path, Path.GetFileName(item.Path) + "-trailer") :
                              Path.Combine(Path.GetDirectoryName(item.Path), Path.GetFileNameWithoutExtension(item.Path) + "-trailer");

            _libraryMonitor.ReportFileSystemChangeBeginning(Path.GetDirectoryName(destination));

            try
            {
                await _channelManager.DownloadChannelItem(channelItem, destination, new Progress <double>(), cancellationToken)
                .ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
            }
            catch (ChannelDownloadException)
            {
                // Logged at lower levels
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error downloading channel content for {0}", ex, item.Name);
            }
            finally
            {
                _libraryMonitor.ReportFileSystemChangeComplete(Path.GetDirectoryName(destination), true);
            }
        }