Ejemplo n.º 1
0
        private void EnsureCovers(Series series)
        {
            foreach (var cover in series.Images)
            {
                var fileName      = GetCoverPath(series.Id, cover.CoverType);
                var alreadyExists = false;
                try
                {
                    alreadyExists = _coverExistsSpecification.AlreadyExists(cover.Url, fileName);
                    if (!alreadyExists)
                    {
                        DownloadCover(series, cover);
                    }
                }
                catch (WebException e)
                {
                    _logger.Warn(string.Format("Couldn't download media cover for {0}. {1}", series, e.Message));
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Couldn't download media cover for " + series);
                }

                EnsureResizedCovers(series, cover, !alreadyExists);
            }
        }
Ejemplo n.º 2
0
        private bool EnsureArtistCovers(Artist artist)
        {
            bool updated  = false;
            var  toResize = new List <Tuple <MediaCover, bool> >();

            foreach (var cover in artist.Metadata.Value.Images)
            {
                var fileName      = GetCoverPath(artist.Id, MediaCoverEntity.Artist, cover.CoverType, cover.Extension);
                var alreadyExists = false;

                try
                {
                    var serverFileHeaders = _httpClient.Head(new HttpRequest(cover.Url)
                    {
                        AllowAutoRedirect = true
                    }).Headers;

                    alreadyExists = _coverExistsSpecification.AlreadyExists(serverFileHeaders.LastModified, serverFileHeaders.ContentLength, fileName);

                    if (!alreadyExists)
                    {
                        DownloadCover(artist, cover, serverFileHeaders.LastModified ?? DateTime.Now);
                        updated = true;
                    }
                }
                catch (WebException e)
                {
                    _logger.Warn("Couldn't download media cover for {0}. {1}", artist, e.Message);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Couldn't download media cover for {0}", artist);
                }

                toResize.Add(Tuple.Create(cover, alreadyExists));
            }

            try
            {
                _semaphore.Wait();

                foreach (var tuple in toResize)
                {
                    EnsureResizedCovers(artist, tuple.Item1, !tuple.Item2);
                }
            }
            finally
            {
                _semaphore.Release();
            }

            return(updated);
        }
Ejemplo n.º 3
0
        private void EnsureAuthorCovers(Author author)
        {
            var toResize = new List <Tuple <MediaCover, bool> >();

            foreach (var cover in author.Metadata.Value.Images)
            {
                var fileName      = GetCoverPath(author.Id, MediaCoverEntity.Author, cover.CoverType, cover.Extension);
                var alreadyExists = false;

                try
                {
                    var serverFileHeaders = GetServerHeaders(cover.Url);

                    alreadyExists = _coverExistsSpecification.AlreadyExists(serverFileHeaders.LastModified, GetContentLength(serverFileHeaders), fileName);

                    if (!alreadyExists)
                    {
                        DownloadCover(author, cover, serverFileHeaders.LastModified ?? DateTime.Now);
                    }
                }
                catch (WebException e)
                {
                    _logger.Warn("Couldn't download media cover for {0}. {1}", author, e.Message);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Couldn't download media cover for {0}", author);
                }

                toResize.Add(Tuple.Create(cover, alreadyExists));
            }

            try
            {
                _semaphore.Wait();

                foreach (var tuple in toResize)
                {
                    EnsureResizedCovers(author, tuple.Item1, !tuple.Item2);
                }
            }
            finally
            {
                _semaphore.Release();
            }
        }
Ejemplo n.º 4
0
        private bool EnsureCovers(Movie movie)
        {
            bool updated  = false;
            var  toResize = new List <Tuple <MediaCover, bool> >();

            foreach (var cover in movie.Images)
            {
                var fileName      = GetCoverPath(movie.Id, cover.CoverType);
                var alreadyExists = false;
                try
                {
                    alreadyExists = _coverExistsSpecification.AlreadyExists(cover.Url, fileName);
                    if (!alreadyExists)
                    {
                        DownloadCover(movie, cover);
                        updated = true;
                    }
                }
                catch (HttpException e)
                {
                    _logger.Warn("Couldn't download media cover for {0}. {1}", movie, e.Message);
                }
                catch (WebException e)
                {
                    _logger.Warn("Couldn't download media cover for {0}. {1}", movie, e.Message);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Couldn't download media cover for {0}", movie);
                }

                toResize.Add(Tuple.Create(cover, alreadyExists));
            }

            try
            {
                _semaphore.Wait();

                foreach (var tuple in toResize)
                {
                    EnsureResizedCovers(movie, tuple.Item1, !tuple.Item2);
                }
            }
            finally
            {
                _semaphore.Release();
            }

            return(updated);
        }
Ejemplo n.º 5
0
        private void EnsureCovers(Movie movie, int retried = 0)
        {
            foreach (var cover in movie.Images)
            {
                var fileName      = GetCoverPath(movie.Id, cover.CoverType);
                var alreadyExists = false;
                try
                {
                    alreadyExists = _coverExistsSpecification.AlreadyExists(cover.Url, fileName);
                    if (!alreadyExists)
                    {
                        DownloadCover(movie, cover);
                    }
                }
                catch (WebException e)
                {
                    if (e.Status == WebExceptionStatus.ProtocolError)
                    {
                        _logger.Warn(e, string.Format("Couldn't download media cover for {0}, likely the cover doesn't exist for this movie. {1}", movie, e.Message));
                    }
                    else
                    {
                        _logger.Warn(e, string.Format("Couldn't download media cover for {0}. {1}", movie, e.Message));
                        if (retried < 3)
                        {
                            retried += 1;
                            _logger.Warn("Retrying for the {0}. time in ten seconds.", retried);
                            System.Threading.Thread.Sleep(10 * 1000);
                            EnsureCovers(movie, retried);
                        }
                        else
                        {
                            _logger.Warn(e, "Couldn't download media cover even after retrying five times :(.");
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Couldn't download media cover for {0}", movie);
                }

                EnsureResizedCovers(movie, cover, !alreadyExists);
            }
        }
Ejemplo n.º 6
0
        private void EnsureCovers(Series series)
        {
            var toResize = new List <Tuple <MediaCover, bool> >();

            foreach (var cover in series.Images)
            {
                var fileName      = GetCoverPath(series.Id, cover.CoverType);
                var alreadyExists = false;
                try
                {
                    alreadyExists = _coverExistsSpecification.AlreadyExists(cover.Url, fileName);
                    if (!alreadyExists)
                    {
                        DownloadCover(series, cover);
                    }
                }
                catch (WebException e)
                {
                    _logger.Warn("Couldn't download media cover for {0}. {1}", series, e.Message);
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Couldn't download media cover for {0}", series);
                }

                toResize.Add(Tuple.Create(cover, alreadyExists));
            }

            try
            {
                _semaphore.Wait();

                foreach (var tuple in toResize)
                {
                    EnsureResizedCovers(series, tuple.Item1, !tuple.Item2);
                }
            }
            finally
            {
                _semaphore.Release();
            }
        }