コード例 #1
0
        private List <PendingRelease> IncludeRemoteAlbums(List <PendingRelease> releases, Dictionary <string, RemoteAlbum> knownRemoteAlbums = null)
        {
            var result = new List <PendingRelease>();

            var artistMap = new Dictionary <int, Artist>();

            if (knownRemoteAlbums != null)
            {
                foreach (var artist in knownRemoteAlbums.Values.Select(v => v.Artist))
                {
                    if (!artistMap.ContainsKey(artist.Id))
                    {
                        artistMap[artist.Id] = artist;
                    }
                }
            }

            foreach (var artist in _artistService.GetArtists(releases.Select(v => v.ArtistId).Distinct().Where(v => !artistMap.ContainsKey(v))))
            {
                artistMap[artist.Id] = artist;
            }

            foreach (var release in releases)
            {
                var artist = artistMap.GetValueOrDefault(release.ArtistId);

                // Just in case the artist was removed, but wasn't cleaned up yet (housekeeper will clean it up)
                if (artist == null)
                {
                    return(null);
                }

                List <Album> albums;

                RemoteAlbum knownRemoteAlbum;
                if (knownRemoteAlbums != null && knownRemoteAlbums.TryGetValue(release.Release.Title, out knownRemoteAlbum))
                {
                    albums = knownRemoteAlbum.Albums;
                }
                else
                {
                    albums = _parsingService.GetAlbums(release.ParsedAlbumInfo, artist);
                }

                release.RemoteAlbum = new RemoteAlbum
                {
                    Artist          = artist,
                    Albums          = albums,
                    ParsedAlbumInfo = release.ParsedAlbumInfo,
                    Release         = release.Release
                };

                result.Add(release);
            }

            return(result);
        }
コード例 #2
0
        private List <PendingRelease> IncludeRemoteBooks(List <PendingRelease> releases, Dictionary <string, RemoteBook> knownRemoteBooks = null)
        {
            var result = new List <PendingRelease>();

            var authorMap = new Dictionary <int, Author>();

            if (knownRemoteBooks != null)
            {
                foreach (var author in knownRemoteBooks.Values.Select(v => v.Author))
                {
                    if (!authorMap.ContainsKey(author.Id))
                    {
                        authorMap[author.Id] = author;
                    }
                }
            }

            foreach (var author in _authorService.GetAuthors(releases.Select(v => v.AuthorId).Distinct().Where(v => !authorMap.ContainsKey(v))))
            {
                authorMap[author.Id] = author;
            }

            foreach (var release in releases)
            {
                var author = authorMap.GetValueOrDefault(release.AuthorId);

                // Just in case the author was removed, but wasn't cleaned up yet (housekeeper will clean it up)
                if (author == null)
                {
                    return(null);
                }

                List <Book> books;

                RemoteBook knownRemoteBook;
                if (knownRemoteBooks != null && knownRemoteBooks.TryGetValue(release.Release.Title, out knownRemoteBook))
                {
                    books = knownRemoteBook.Books;
                }
                else
                {
                    books = _parsingService.GetAlbums(release.ParsedBookInfo, author);
                }

                release.RemoteBook = new RemoteBook
                {
                    Author         = author,
                    Books          = books,
                    ParsedBookInfo = release.ParsedBookInfo,
                    Release        = release.Release
                };

                result.Add(release);
            }

            return(result);
        }
コード例 #3
0
        private object DownloadRelease(ReleaseResource release)
        {
            var remoteBook = _remoteBookCache.Find(GetCacheKey(release));

            if (remoteBook == null)
            {
                _logger.Debug("Couldn't find requested release in cache, cache timeout probably expired.");

                throw new NzbDroneClientException(HttpStatusCode.NotFound, "Couldn't find requested release in cache, try searching again");
            }

            try
            {
                if (remoteBook.Author == null)
                {
                    if (release.BookId.HasValue)
                    {
                        var book = _bookService.GetBook(release.BookId.Value);

                        remoteBook.Author = _authorService.GetAuthor(book.AuthorId);
                        remoteBook.Books  = new List <Book> {
                            book
                        };
                    }
                    else if (release.AuthorId.HasValue)
                    {
                        var author = _authorService.GetAuthor(release.AuthorId.Value);
                        var books  = _parsingService.GetAlbums(remoteBook.ParsedBookInfo, author);

                        if (books.Empty())
                        {
                            throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse books in the release");
                        }

                        remoteBook.Author = author;
                        remoteBook.Books  = books;
                    }
                    else
                    {
                        throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to find matching author and books");
                    }
                }
                else if (remoteBook.Books.Empty())
                {
                    var books = _parsingService.GetAlbums(remoteBook.ParsedBookInfo, remoteBook.Author);

                    if (books.Empty() && release.BookId.HasValue)
                    {
                        var book = _bookService.GetBook(release.BookId.Value);

                        books = new List <Book> {
                            book
                        };
                    }

                    remoteBook.Books = books;
                }

                if (remoteBook.Books.Empty())
                {
                    throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse books in the release");
                }

                _downloadService.DownloadReport(remoteBook);
            }
            catch (ReleaseDownloadException ex)
            {
                _logger.Error(ex, "Getting release from indexer failed");
                throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed");
            }

            return(release);
        }
コード例 #4
0
ファイル: ReleaseModule.cs プロジェクト: debbielobo1/Lidarr
        private object DownloadRelease(ReleaseResource release)
        {
            var remoteAlbum = _remoteAlbumCache.Find(GetCacheKey(release));

            if (remoteAlbum == null)
            {
                _logger.Debug("Couldn't find requested release in cache, cache timeout probably expired.");

                throw new NzbDroneClientException(HttpStatusCode.NotFound, "Couldn't find requested release in cache, try searching again");
            }

            try
            {
                if (remoteAlbum.Artist == null)
                {
                    if (release.AlbumId.HasValue)
                    {
                        var album = _albumService.GetAlbum(release.AlbumId.Value);

                        remoteAlbum.Artist = _artistService.GetArtist(album.ArtistId);
                        remoteAlbum.Albums = new List <Album> {
                            album
                        };
                    }
                    else if (release.ArtistId.HasValue)
                    {
                        var artist = _artistService.GetArtist(release.ArtistId.Value);
                        var albums = _parsingService.GetAlbums(remoteAlbum.ParsedAlbumInfo, artist);

                        if (albums.Empty())
                        {
                            throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse albums in the release");
                        }

                        remoteAlbum.Artist = artist;
                        remoteAlbum.Albums = albums;
                    }
                    else
                    {
                        throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to find matching artist and albums");
                    }
                }
                else if (remoteAlbum.Albums.Empty())
                {
                    var albums = _parsingService.GetAlbums(remoteAlbum.ParsedAlbumInfo, remoteAlbum.Artist);

                    if (albums.Empty() && release.AlbumId.HasValue)
                    {
                        var album = _albumService.GetAlbum(release.AlbumId.Value);

                        albums = new List <Album> {
                            album
                        };
                    }

                    remoteAlbum.Albums = albums;
                }

                if (remoteAlbum.Albums.Empty())
                {
                    throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse albums in the release");
                }

                _downloadService.DownloadReport(remoteAlbum);
            }
            catch (ReleaseDownloadException ex)
            {
                _logger.Error(ex, ex.Message);
                throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed");
            }

            return(release);
        }