public void Save(Trakt_ImageFanart obj)
 {
     using (var session = JMMService.SessionFactory.OpenSession())
     {
         // populate the database
         using (var transaction = session.BeginTransaction())
         {
             session.SaveOrUpdate(obj);
             transaction.Commit();
         }
     }
 }
        public Trakt_ImageFanart GetByShowIDAndSeason(int showID, int seasonNumber)
        {
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                Trakt_ImageFanart obj = session
                                        .CreateCriteria(typeof(Trakt_ImageFanart))
                                        .Add(Restrictions.Eq("Trakt_ShowID", showID))
                                        .Add(Restrictions.Eq("Season", seasonNumber))
                                        .UniqueResult <Trakt_ImageFanart>();

                return(obj);
            }
        }
 public void Delete(int id)
 {
     using (var session = JMMService.SessionFactory.OpenSession())
     {
         // populate the database
         using (var transaction = session.BeginTransaction())
         {
             Trakt_ImageFanart cr = GetByID(id);
             if (cr != null)
             {
                 session.Delete(cr);
                 transaction.Commit();
             }
         }
     }
 }
        public static string GetFullImagePath(this Trakt_ImageFanart image)
        {
            // typical url
            // http://vicmackey.trakt.tv/images/fanart/3228.jpg

            if (String.IsNullOrEmpty(image.ImageURL))
            {
                return("");
            }

            int pos = image.ImageURL.IndexOf(@"images/");

            if (pos <= 0)
            {
                return("");
            }

            string relativePath = image.ImageURL.Substring(pos + 7, image.ImageURL.Length - pos - 7);

            relativePath = relativePath.Replace("/", @"\");

            return(System.IO.Path.Combine(ImageUtils.GetTraktImagePath(), relativePath));
        }
Example #5
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_DownloadImage: {0}", EntityID);
            string downloadURL = "";

            try
            {
                ImageDownloadRequest req = null;
                switch (EntityTypeEnum)
                {
                case JMMImageType.AniDB_Cover:
                    AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                    AniDB_Anime           anime    = repAnime.GetByID(EntityID);
                    if (anime == null)
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, anime, ForceDownload);
                    break;

                case JMMImageType.TvDB_Episode:

                    TvDB_EpisodeRepository repTvEp = new TvDB_EpisodeRepository();
                    TvDB_Episode           ep      = repTvEp.GetByID(EntityID);
                    if (ep == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(ep.Filename))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, ep, ForceDownload);
                    break;

                case JMMImageType.TvDB_FanArt:

                    TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
                    TvDB_ImageFanart           fanart    = repFanart.GetByID(EntityID);
                    if (fanart == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(fanart.BannerPath))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, fanart, ForceDownload);
                    break;

                case JMMImageType.TvDB_Cover:

                    TvDB_ImagePosterRepository repPoster = new TvDB_ImagePosterRepository();
                    TvDB_ImagePoster           poster    = repPoster.GetByID(EntityID);
                    if (poster == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(poster.BannerPath))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, poster, ForceDownload);
                    break;

                case JMMImageType.TvDB_Banner:

                    TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();
                    TvDB_ImageWideBanner           wideBanner = repBanners.GetByID(EntityID);
                    if (wideBanner == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(wideBanner.BannerPath))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, wideBanner, ForceDownload);
                    break;

                case JMMImageType.MovieDB_Poster:

                    MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
                    MovieDB_Poster           moviePoster     = repMoviePosters.GetByID(EntityID);
                    if (moviePoster == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(moviePoster.URL))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, moviePoster, ForceDownload);
                    break;

                case JMMImageType.MovieDB_FanArt:

                    MovieDB_FanartRepository repMovieFanart = new MovieDB_FanartRepository();
                    MovieDB_Fanart           movieFanart    = repMovieFanart.GetByID(EntityID);
                    if (movieFanart == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(movieFanart.URL))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, movieFanart, ForceDownload);
                    break;

                case JMMImageType.Trakt_Poster:

                    Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
                    Trakt_ImagePoster           traktPoster     = repTraktPosters.GetByID(EntityID);
                    if (traktPoster == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(traktPoster.ImageURL))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, traktPoster, ForceDownload);
                    break;

                case JMMImageType.Trakt_Fanart:

                    Trakt_ImageFanartRepository repTraktFanarts = new Trakt_ImageFanartRepository();
                    Trakt_ImageFanart           traktFanart     = repTraktFanarts.GetByID(EntityID);
                    if (traktFanart == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(traktFanart.ImageURL))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, traktFanart, ForceDownload);
                    break;

                case JMMImageType.Trakt_Friend:

                    Trakt_FriendRepository repFriends = new Trakt_FriendRepository();
                    Trakt_Friend           friend     = repFriends.GetByID(EntityID);
                    if (friend == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(friend.Avatar))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, friend, ForceDownload);
                    break;

                case JMMImageType.Trakt_Episode:

                    Trakt_EpisodeRepository repTraktEpisodes = new Trakt_EpisodeRepository();
                    Trakt_Episode           traktEp          = repTraktEpisodes.GetByID(EntityID);
                    if (traktEp == null)
                    {
                        return;
                    }
                    if (string.IsNullOrEmpty(traktEp.EpisodeImage))
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, traktEp, ForceDownload);
                    break;

                case JMMImageType.AniDB_Character:
                    AniDB_CharacterRepository repChars = new AniDB_CharacterRepository();
                    AniDB_Character           chr      = repChars.GetByID(EntityID);
                    if (chr == null)
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, chr, ForceDownload);
                    break;

                case JMMImageType.AniDB_Creator:
                    AniDB_SeiyuuRepository repCreator = new AniDB_SeiyuuRepository();
                    AniDB_Seiyuu           creator    = repCreator.GetByID(EntityID);
                    if (creator == null)
                    {
                        return;
                    }

                    req = new ImageDownloadRequest(EntityTypeEnum, creator, ForceDownload);
                    break;
                }

                if (req == null)
                {
                    return;
                }

                List <string> fileNames    = new List <string>();
                List <string> downloadURLs = new List <string>();

                string fileNameTemp    = GetFileName(req, false);
                string downloadURLTemp = GetFileURL(req, false);

                fileNames.Add(fileNameTemp);
                downloadURLs.Add(downloadURLTemp);

                if (req.ImageType == JMMImageType.TvDB_FanArt)
                {
                    fileNameTemp    = GetFileName(req, true);
                    downloadURLTemp = GetFileURL(req, true);

                    fileNames.Add(fileNameTemp);
                    downloadURLs.Add(downloadURLTemp);
                }

                for (int i = 0; i < fileNames.Count; i++)
                {
                    string fileName = fileNames[i];
                    downloadURL = downloadURLs[i];

                    bool downloadImage = true;
                    bool fileExists    = File.Exists(fileName);

                    if (fileExists)
                    {
                        if (!req.ForceDownload)
                        {
                            downloadImage = false;
                        }
                        else
                        {
                            downloadImage = true;
                        }
                    }
                    else
                    {
                        downloadImage = true;
                    }

                    if (downloadImage)
                    {
                        string tempName = Path.Combine(ImageUtils.GetImagesTempFolder(), Path.GetFileName(fileName));
                        if (File.Exists(tempName))
                        {
                            File.Delete(tempName);
                        }


                        try
                        {
                            if (fileExists)
                            {
                                File.Delete(fileName);
                            }
                        }
                        catch (Exception ex)
                        {
                            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

                            string msg = string.Format(JMMServer.Properties.Resources.Command_DeleteError, fileName,
                                                       ex.Message);
                            logger.Warn(msg);
                            return;
                        }


                        // download image
                        using (WebClient client = new WebClient())
                        {
                            client.Headers.Add("user-agent", "JMM");
                            //OnImageDownloadEvent(new ImageDownloadEventArgs("", req, ImageDownloadEventType.Started));
                            //BaseConfig.MyAnimeLog.Write("ProcessImages: Download: {0}  *** to ***  {1}", req.URL, fullName);
                            if (downloadURL.Length > 0)
                            {
                                client.DownloadFile(downloadURL, tempName);

                                string extension   = "";
                                string contentType = client.ResponseHeaders["Content-type"].ToLower();
                                if (contentType.IndexOf("gif") >= 0)
                                {
                                    extension = ".gif";
                                }
                                if (contentType.IndexOf("jpg") >= 0)
                                {
                                    extension = ".jpg";
                                }
                                if (contentType.IndexOf("jpeg") >= 0)
                                {
                                    extension = ".jpg";
                                }
                                if (contentType.IndexOf("bmp") >= 0)
                                {
                                    extension = ".bmp";
                                }
                                if (contentType.IndexOf("png") >= 0)
                                {
                                    extension = ".png";
                                }
                                if (extension.Length > 0)
                                {
                                    string newFile = Path.ChangeExtension(tempName, extension);
                                    if (!newFile.ToLower().Equals(tempName.ToLower()))
                                    {
                                        try
                                        {
                                            System.IO.File.Delete(newFile);
                                        }
                                        catch
                                        {
                                            //BaseConfig.MyAnimeLog.Write("DownloadedImage:Download() Delete failed:{0}", newFile);
                                        }
                                        System.IO.File.Move(tempName, newFile);
                                        tempName = newFile;
                                    }
                                }
                            }
                        }

                        // move the file to it's final location
                        // check that the final folder exists
                        string fullPath = Path.GetDirectoryName(fileName);
                        if (!Directory.Exists(fullPath))
                        {
                            Directory.CreateDirectory(fullPath);
                        }


                        System.IO.File.Move(tempName, fileName);
                        logger.Info("Image downloaded: {0}", fileName);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Warn("Error processing CommandRequest_DownloadImage: {0} ({1}) - {2}", downloadURL, EntityID,
                            ex.Message);
                return;
            }
        }
Example #6
0
        private string GetFileName(ImageDownloadRequest req, bool thumbNailOnly)
        {
            switch (req.ImageType)
            {
            case JMMImageType.AniDB_Cover:

                AniDB_Anime anime = req.ImageData as AniDB_Anime;
                return(anime.PosterPath);

            case JMMImageType.TvDB_Episode:

                TvDB_Episode ep = req.ImageData as TvDB_Episode;
                return(ep.FullImagePath);

            case JMMImageType.TvDB_FanArt:

                TvDB_ImageFanart fanart = req.ImageData as TvDB_ImageFanart;
                if (thumbNailOnly)
                {
                    return(fanart.FullThumbnailPath);
                }
                else
                {
                    return(fanart.FullImagePath);
                }

            case JMMImageType.TvDB_Cover:

                TvDB_ImagePoster poster = req.ImageData as TvDB_ImagePoster;
                return(poster.FullImagePath);

            case JMMImageType.TvDB_Banner:

                TvDB_ImageWideBanner wideBanner = req.ImageData as TvDB_ImageWideBanner;
                return(wideBanner.FullImagePath);

            case JMMImageType.MovieDB_Poster:

                MovieDB_Poster moviePoster = req.ImageData as MovieDB_Poster;
                return(moviePoster.FullImagePath);

            case JMMImageType.MovieDB_FanArt:

                MovieDB_Fanart movieFanart = req.ImageData as MovieDB_Fanart;
                return(movieFanart.FullImagePath);

            case JMMImageType.Trakt_Poster:
                Trakt_ImagePoster traktPoster = req.ImageData as Trakt_ImagePoster;
                return(traktPoster.FullImagePath);

            case JMMImageType.Trakt_Fanart:
                Trakt_ImageFanart traktFanart = req.ImageData as Trakt_ImageFanart;
                return(traktFanart.FullImagePath);

            case JMMImageType.Trakt_Friend:
                Trakt_Friend traktFriend = req.ImageData as Trakt_Friend;
                return(traktFriend.FullImagePath);

            case JMMImageType.Trakt_Episode:
                Trakt_Episode traktEp = req.ImageData as Trakt_Episode;
                return(traktEp.FullImagePath);

            case JMMImageType.AniDB_Character:
                AniDB_Character chr = req.ImageData as AniDB_Character;
                return(chr.PosterPath);

            case JMMImageType.AniDB_Creator:
                AniDB_Seiyuu creator = req.ImageData as AniDB_Seiyuu;
                return(creator.PosterPath);

            default:
                return("");
            }
        }
Example #7
0
        public static string GetFileURL(ImageDownloadRequest req, bool thumbNailOnly)
        {
            switch (req.ImageType)
            {
            case JMMImageType.AniDB_Cover:
                AniDB_Anime anime = req.ImageData as AniDB_Anime;
                return(string.Format(Constants.URLS.AniDB_Images, anime.Picname));

            case JMMImageType.TvDB_Episode:
                TvDB_Episode ep = req.ImageData as TvDB_Episode;
                return(string.Format(Constants.URLS.TvDB_Images, ep.Filename));

            case JMMImageType.TvDB_FanArt:
                TvDB_ImageFanart fanart = req.ImageData as TvDB_ImageFanart;

                if (thumbNailOnly)
                {
                    return(string.Format(Constants.URLS.TvDB_Images, fanart.ThumbnailPath));
                }
                else
                {
                    return(string.Format(Constants.URLS.TvDB_Images, fanart.BannerPath));
                }

            case JMMImageType.TvDB_Cover:
                TvDB_ImagePoster poster = req.ImageData as TvDB_ImagePoster;
                return(string.Format(Constants.URLS.TvDB_Images, poster.BannerPath));

            case JMMImageType.TvDB_Banner:
                TvDB_ImageWideBanner wideBanner = req.ImageData as TvDB_ImageWideBanner;
                return(string.Format(Constants.URLS.TvDB_Images, wideBanner.BannerPath));

            case JMMImageType.MovieDB_Poster:
                MovieDB_Poster moviePoster = req.ImageData as MovieDB_Poster;
                return(string.Format(Constants.URLS.MovieDB_Images, moviePoster.URL));

            case JMMImageType.MovieDB_FanArt:

                MovieDB_Fanart movieFanart = req.ImageData as MovieDB_Fanart;
                return(string.Format(Constants.URLS.MovieDB_Images, movieFanart.URL));

            case JMMImageType.Trakt_Poster:
                Trakt_ImagePoster traktPoster = req.ImageData as Trakt_ImagePoster;
                return(traktPoster.ImageURL);

            case JMMImageType.Trakt_Fanart:
                Trakt_ImageFanart traktFanart = req.ImageData as Trakt_ImageFanart;
                return(traktFanart.ImageURL);

            case JMMImageType.Trakt_Friend:
                Trakt_Friend traktFriend = req.ImageData as Trakt_Friend;
                return(traktFriend.Avatar);

            case JMMImageType.Trakt_Episode:
                Trakt_Episode traktEp = req.ImageData as Trakt_Episode;
                return(traktEp.EpisodeImage);

            case JMMImageType.AniDB_Character:
                AniDB_Character chr = req.ImageData as AniDB_Character;
                return(string.Format(Constants.URLS.AniDB_Images, chr.PicName));

            case JMMImageType.AniDB_Creator:
                AniDB_Seiyuu creator = req.ImageData as AniDB_Seiyuu;
                return(string.Format(Constants.URLS.AniDB_Images, creator.PicName));

            default:
                return("");
            }
        }
        public System.IO.Stream GetImage(string ImageType, string ImageID)
        {
            AniDB_AnimeRepository          repAnime       = new AniDB_AnimeRepository();
            TvDB_ImagePosterRepository     repPosters     = new TvDB_ImagePosterRepository();
            TvDB_EpisodeRepository         repEpisodes    = new TvDB_EpisodeRepository();
            TvDB_ImageFanartRepository     repFanart      = new TvDB_ImageFanartRepository();
            TvDB_ImageWideBannerRepository repWideBanners = new TvDB_ImageWideBannerRepository();

            MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
            MovieDB_FanartRepository repMovieFanart  = new MovieDB_FanartRepository();

            Trakt_ImageFanartRepository repTraktFanart   = new Trakt_ImageFanartRepository();
            Trakt_ImagePosterRepository repTraktPosters  = new Trakt_ImagePosterRepository();
            Trakt_EpisodeRepository     repTraktEpisodes = new Trakt_EpisodeRepository();
            Trakt_FriendRepository      repTraktFriends  = new Trakt_FriendRepository();

            JMMImageType imageType = (JMMImageType)int.Parse(ImageType);

            switch (imageType)
            {
            case JMMImageType.AniDB_Cover:

                AniDB_Anime anime = repAnime.GetByAnimeID(int.Parse(ImageID));
                if (anime == null)
                {
                    return(null);
                }

                if (File.Exists(anime.PosterPath))
                {
                    FileStream fs = File.OpenRead(anime.PosterPath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
                    return(BlankImage());
                }

            case JMMImageType.AniDB_Character:

                AniDB_CharacterRepository repChar = new AniDB_CharacterRepository();
                AniDB_Character           chr     = repChar.GetByID(int.Parse(ImageID));
                if (chr == null)
                {
                    return(null);
                }

                if (File.Exists(chr.PosterPath))
                {
                    FileStream fs = File.OpenRead(chr.PosterPath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Character image: {0}", chr.PosterPath);
                    return(BlankImage());
                }

            case JMMImageType.AniDB_Creator:

                AniDB_SeiyuuRepository repCreator = new AniDB_SeiyuuRepository();
                AniDB_Seiyuu           creator    = repCreator.GetByID(int.Parse(ImageID));
                if (creator == null)
                {
                    return(null);
                }

                if (File.Exists(creator.PosterPath))
                {
                    FileStream fs = File.OpenRead(creator.PosterPath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Creator image: {0}", creator.PosterPath);
                    return(BlankImage());
                }

            case JMMImageType.TvDB_Cover:

                TvDB_ImagePoster poster = repPosters.GetByID(int.Parse(ImageID));
                if (poster == null)
                {
                    return(null);
                }

                if (File.Exists(poster.FullImagePath))
                {
                    FileStream fs = File.OpenRead(poster.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Cover image: {0}", poster.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.TvDB_Banner:

                TvDB_ImageWideBanner wideBanner = repWideBanners.GetByID(int.Parse(ImageID));
                if (wideBanner == null)
                {
                    return(null);
                }

                if (File.Exists(wideBanner.FullImagePath))
                {
                    FileStream fs = File.OpenRead(wideBanner.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.TvDB_Episode:

                TvDB_Episode ep = repEpisodes.GetByID(int.Parse(ImageID));
                if (ep == null)
                {
                    return(null);
                }

                if (File.Exists(ep.FullImagePath))
                {
                    FileStream fs = File.OpenRead(ep.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Episode image: {0}", ep.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.TvDB_FanArt:

                TvDB_ImageFanart fanart = repFanart.GetByID(int.Parse(ImageID));
                if (fanart == null)
                {
                    return(null);
                }

                if (File.Exists(fanart.FullImagePath))
                {
                    FileStream fs = File.OpenRead(fanart.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.MovieDB_Poster:

                MovieDB_Poster mPoster = repMoviePosters.GetByID(int.Parse(ImageID));
                if (mPoster == null)
                {
                    return(null);
                }

                // now find only the original size
                mPoster = repMoviePosters.GetByOnlineID(mPoster.URL);
                if (mPoster == null)
                {
                    return(null);
                }

                if (File.Exists(mPoster.FullImagePath))
                {
                    FileStream fs = File.OpenRead(mPoster.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.MovieDB_FanArt:

                MovieDB_Fanart mFanart = repMovieFanart.GetByID(int.Parse(ImageID));
                if (mFanart == null)
                {
                    return(null);
                }

                mFanart = repMovieFanart.GetByOnlineID(mFanart.URL);
                if (mFanart == null)
                {
                    return(null);
                }

                if (File.Exists(mFanart.FullImagePath))
                {
                    FileStream fs = File.OpenRead(mFanart.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.Trakt_Fanart:

                Trakt_ImageFanart tFanart = repTraktFanart.GetByID(int.Parse(ImageID));
                if (tFanart == null)
                {
                    return(null);
                }

                if (File.Exists(tFanart.FullImagePath))
                {
                    FileStream fs = File.OpenRead(tFanart.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.Trakt_Poster:

                Trakt_ImagePoster tPoster = repTraktPosters.GetByID(int.Parse(ImageID));
                if (tPoster == null)
                {
                    return(null);
                }

                if (File.Exists(tPoster.FullImagePath))
                {
                    FileStream fs = File.OpenRead(tPoster.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.Trakt_Episode:
            case JMMImageType.Trakt_WatchedEpisode:

                Trakt_Episode tEpisode = repTraktEpisodes.GetByID(int.Parse(ImageID));
                if (tEpisode == null)
                {
                    return(null);
                }

                if (File.Exists(tEpisode.FullImagePath))
                {
                    FileStream fs = File.OpenRead(tEpisode.FullImagePath);
                    WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.FullImagePath);
                    return(BlankImage());
                }

            default:

                return(BlankImage());
            }
        }
        public string GetImagePath(string ImageType, string ImageID, bool thumnbnailOnly)
        {
            JMMImageType imageType = (JMMImageType)int.Parse(ImageType);

            switch (imageType)
            {
            case JMMImageType.AniDB_Cover:

                AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(int.Parse(ImageID));
                if (anime == null)
                {
                    return(null);
                }

                if (File.Exists(anime.PosterPath))
                {
                    return(anime.PosterPath);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
                    return("");
                }

            case JMMImageType.AniDB_Character:

                AniDB_Character chr = RepoFactory.AniDB_Character.GetByID(int.Parse(ImageID));
                if (chr == null)
                {
                    return(null);
                }

                if (File.Exists(chr.PosterPath))
                {
                    return(chr.PosterPath);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Character image: {0}", chr.PosterPath);
                    return("");
                }

            case JMMImageType.AniDB_Creator:

                AniDB_Seiyuu creator = RepoFactory.AniDB_Seiyuu.GetByID(int.Parse(ImageID));
                if (creator == null)
                {
                    return("");
                }

                if (File.Exists(creator.PosterPath))
                {
                    return(creator.PosterPath);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Creator image: {0}", creator.PosterPath);
                    return("");
                }

            case JMMImageType.TvDB_Cover:

                TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetByID(int.Parse(ImageID));
                if (poster == null)
                {
                    return(null);
                }

                if (File.Exists(poster.FullImagePath))
                {
                    return(poster.FullImagePath);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Cover image: {0}", poster.FullImagePath);
                    return("");
                }

            case JMMImageType.TvDB_Banner:

                TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(int.Parse(ImageID));
                if (wideBanner == null)
                {
                    return(null);
                }

                if (File.Exists(wideBanner.FullImagePath))
                {
                    return(wideBanner.FullImagePath);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.FullImagePath);
                    return("");
                }

            case JMMImageType.TvDB_Episode:

                TvDB_Episode ep = RepoFactory.TvDB_Episode.GetByID(int.Parse(ImageID));
                if (ep == null)
                {
                    return(null);
                }

                if (File.Exists(ep.FullImagePath))
                {
                    return(ep.FullImagePath);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Episode image: {0}", ep.FullImagePath);
                    return("");
                }

            case JMMImageType.TvDB_FanArt:

                TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetByID(int.Parse(ImageID));
                if (fanart == null)
                {
                    return(null);
                }

                if (thumnbnailOnly)
                {
                    if (File.Exists(fanart.FullThumbnailPath))
                    {
                        return(fanart.FullThumbnailPath);
                    }
                    else
                    {
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullThumbnailPath);
                        return("");
                    }
                }
                else
                {
                    if (File.Exists(fanart.FullImagePath))
                    {
                        return(fanart.FullImagePath);
                    }
                    else
                    {
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullImagePath);
                        return("");
                    }
                }

            case JMMImageType.MovieDB_Poster:

                MovieDB_Poster mPoster = RepoFactory.MovieDB_Poster.GetByID(int.Parse(ImageID));
                if (mPoster == null)
                {
                    return(null);
                }

                // now find only the original size
                mPoster = RepoFactory.MovieDB_Poster.GetByOnlineID(mPoster.URL);
                if (mPoster == null)
                {
                    return(null);
                }

                if (File.Exists(mPoster.FullImagePath))
                {
                    return(mPoster.FullImagePath);
                }
                else
                {
                    logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.FullImagePath);
                    return("");
                }

            case JMMImageType.MovieDB_FanArt:

                MovieDB_Fanart mFanart = RepoFactory.MovieDB_Fanart.GetByID(int.Parse(ImageID));
                if (mFanart == null)
                {
                    return(null);
                }

                mFanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(mFanart.URL);
                if (mFanart == null)
                {
                    return(null);
                }

                if (File.Exists(mFanart.FullImagePath))
                {
                    return(mFanart.FullImagePath);
                }
                else
                {
                    logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.FullImagePath);
                    return("");
                }

            case JMMImageType.Trakt_Fanart:

                Trakt_ImageFanart tFanart = RepoFactory.Trakt_ImageFanart.GetByID(int.Parse(ImageID));
                if (tFanart == null)
                {
                    return(null);
                }

                if (File.Exists(tFanart.FullImagePath))
                {
                    return(tFanart.FullImagePath);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.FullImagePath);
                    return("");
                }

            case JMMImageType.Trakt_Poster:

                Trakt_ImagePoster tPoster = RepoFactory.Trakt_ImagePoster.GetByID(int.Parse(ImageID));
                if (tPoster == null)
                {
                    return(null);
                }

                if (File.Exists(tPoster.FullImagePath))
                {
                    return(tPoster.FullImagePath);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.FullImagePath);
                    return("");
                }

            case JMMImageType.Trakt_Episode:
            case JMMImageType.Trakt_WatchedEpisode:

                Trakt_Episode tEpisode = RepoFactory.Trakt_Episode.GetByID(int.Parse(ImageID));
                if (tEpisode == null)
                {
                    return(null);
                }

                if (File.Exists(tEpisode.FullImagePath))
                {
                    return(tEpisode.FullImagePath);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.FullImagePath);
                    return("");
                }

            default:
                return("");
            }
        }
Example #10
0
        /// <summary>
        /// Internal function that return valid image file path on server that exist
        /// </summary>
        /// <param name="id">image id</param>
        /// <param name="type">image type</param>
        /// <param name="thumb">thumb mode</param>
        /// <returns>string</returns>
        internal string ReturnImagePath(int type, int id, bool thumb)
        {
            JMMImageType imageType = (JMMImageType)type;
            string       path      = "";

            switch (imageType)
            {
            // 1
            case JMMImageType.AniDB_Cover:
                SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(id);
                if (anime == null)
                {
                    return(null);
                }
                path = anime.PosterPath;
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
                }
                break;

            // 2
            case JMMImageType.AniDB_Character:
                AniDB_Character chr = RepoFactory.AniDB_Character.GetByCharID(id);
                if (chr == null)
                {
                    return(null);
                }
                path = chr.GetPosterPath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find AniDB_Character image: {0}", chr.GetPosterPath());
                }
                break;

            // 3
            case JMMImageType.AniDB_Creator:
                AniDB_Seiyuu creator = RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(id);
                if (creator == null)
                {
                    return(null);
                }
                path = creator.GetPosterPath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find AniDB_Creator image: {0}", creator.GetPosterPath());
                }
                break;

            // 4
            case JMMImageType.TvDB_Banner:
                TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(id);
                if (wideBanner == null)
                {
                    return(null);
                }
                path = wideBanner.GetFullImagePath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.GetFullImagePath());
                }
                break;

            // 5
            case JMMImageType.TvDB_Cover:
                TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetByID(id);
                if (poster == null)
                {
                    return(null);
                }
                path = poster.GetFullImagePath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find TvDB_Cover image: {0}", poster.GetFullImagePath());
                }
                break;

            // 6
            case JMMImageType.TvDB_Episode:
                TvDB_Episode ep = RepoFactory.TvDB_Episode.GetByID(id);
                if (ep == null)
                {
                    return(null);
                }
                path = ep.GetFullImagePath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find TvDB_Episode image: {0}", ep.GetFullImagePath());
                }
                break;

            // 7
            case JMMImageType.TvDB_FanArt:
                TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetByID(id);
                if (fanart == null)
                {
                    return(null);
                }
                if (thumb)
                {
                    //ratio
                    path = fanart.GetFullThumbnailPath();
                    if (Pri.LongPath.File.Exists(path))
                    {
                        return(path);
                    }
                    else
                    {
                        path = "";
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullThumbnailPath());
                    }
                }
                else
                {
                    path = fanart.GetFullImagePath();
                    if (Pri.LongPath.File.Exists(path))
                    {
                        return(path);
                    }
                    else
                    {
                        path = "";
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.GetFullImagePath());
                    }
                }
                break;

            // 8
            case JMMImageType.MovieDB_FanArt:
                MovieDB_Fanart mFanart = RepoFactory.MovieDB_Fanart.GetByID(id);
                if (mFanart == null)
                {
                    return(null);
                }
                mFanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(mFanart.URL);
                if (mFanart == null)
                {
                    return(null);
                }
                path = mFanart.GetFullImagePath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.GetFullImagePath());
                }
                break;

            // 9
            case JMMImageType.MovieDB_Poster:
                MovieDB_Poster mPoster = RepoFactory.MovieDB_Poster.GetByID(id);
                if (mPoster == null)
                {
                    return(null);
                }
                mPoster = RepoFactory.MovieDB_Poster.GetByOnlineID(mPoster.URL);
                if (mPoster == null)
                {
                    return(null);
                }
                path = mPoster.GetFullImagePath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.GetFullImagePath());
                }
                break;

            // 10
            case JMMImageType.Trakt_Poster:
                Trakt_ImagePoster tPoster = RepoFactory.Trakt_ImagePoster.GetByID(id);
                if (tPoster == null)
                {
                    return(null);
                }
                path = tPoster.GetFullImagePath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.GetFullImagePath());
                }
                break;

            // 11
            case JMMImageType.Trakt_Fanart:
                Trakt_ImageFanart tFanart = RepoFactory.Trakt_ImageFanart.GetByID(id);
                if (tFanart == null)
                {
                    return(null);
                }
                path = tFanart.GetFullImagePath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.GetFullImagePath());
                }
                break;


            // 12 + 16
            case JMMImageType.Trakt_Episode:
            case JMMImageType.Trakt_WatchedEpisode:
                Trakt_Episode tEpisode = RepoFactory.Trakt_Episode.GetByID(id);
                if (tEpisode == null)
                {
                    return(null);
                }
                path = tEpisode.GetFullImagePath();
                if (Pri.LongPath.File.Exists(path))
                {
                    return(path);
                }
                else
                {
                    path = "";
                    logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.GetFullImagePath());
                }
                break;

            // 0, 13-15, 17+
            default:
                path = "";
                break;
            }

            return(path);
        }
Example #11
0
        public byte[] GetImage(string entityID, int entityType, bool thumnbnailOnly)
        {
            AniDB_AnimeRepository          repAnime       = new AniDB_AnimeRepository();
            TvDB_ImagePosterRepository     repPosters     = new TvDB_ImagePosterRepository();
            TvDB_EpisodeRepository         repEpisodes    = new TvDB_EpisodeRepository();
            TvDB_ImageFanartRepository     repFanart      = new TvDB_ImageFanartRepository();
            TvDB_ImageWideBannerRepository repWideBanners = new TvDB_ImageWideBannerRepository();

            MovieDB_PosterRepository repMoviePosters = new MovieDB_PosterRepository();
            MovieDB_FanartRepository repMovieFanart  = new MovieDB_FanartRepository();

            Trakt_ImageFanartRepository repTraktFanart   = new Trakt_ImageFanartRepository();
            Trakt_ImagePosterRepository repTraktPosters  = new Trakt_ImagePosterRepository();
            Trakt_EpisodeRepository     repTraktEpisodes = new Trakt_EpisodeRepository();
            Trakt_FriendRepository      repTraktFriends  = new Trakt_FriendRepository();

            JMMImageType imageType = (JMMImageType)entityType;

            switch (imageType)
            {
            case JMMImageType.AniDB_Cover:

                AniDB_Anime anime = repAnime.GetByAnimeID(int.Parse(entityID));
                if (anime == null)
                {
                    return(null);
                }

                if (File.Exists(anime.PosterPath))
                {
                    return(File.ReadAllBytes(anime.PosterPath));
                }
                else
                {
                    logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
                    return(null);
                }

            case JMMImageType.AniDB_Character:

                AniDB_CharacterRepository repChar = new AniDB_CharacterRepository();
                AniDB_Character           chr     = repChar.GetByID(int.Parse(entityID));
                if (chr == null)
                {
                    return(null);
                }

                if (File.Exists(chr.PosterPath))
                {
                    return(File.ReadAllBytes(chr.PosterPath));
                }
                else
                {
                    logger.Trace("Could not find AniDB_Character image: {0}", chr.PosterPath);
                    return(null);
                }

            case JMMImageType.AniDB_Creator:

                AniDB_SeiyuuRepository repCreator = new AniDB_SeiyuuRepository();
                AniDB_Seiyuu           creator    = repCreator.GetByID(int.Parse(entityID));
                if (creator == null)
                {
                    return(null);
                }

                if (File.Exists(creator.PosterPath))
                {
                    return(File.ReadAllBytes(creator.PosterPath));
                }
                else
                {
                    logger.Trace("Could not find AniDB_Creator image: {0}", creator.PosterPath);
                    return(null);
                }

            case JMMImageType.TvDB_Cover:

                TvDB_ImagePoster poster = repPosters.GetByID(int.Parse(entityID));
                if (poster == null)
                {
                    return(null);
                }

                if (File.Exists(poster.FullImagePath))
                {
                    return(File.ReadAllBytes(poster.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find TvDB_Cover image: {0}", poster.FullImagePath);
                    return(null);
                }

            case JMMImageType.TvDB_Banner:

                TvDB_ImageWideBanner wideBanner = repWideBanners.GetByID(int.Parse(entityID));
                if (wideBanner == null)
                {
                    return(null);
                }

                if (File.Exists(wideBanner.FullImagePath))
                {
                    return(File.ReadAllBytes(wideBanner.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.FullImagePath);
                    return(null);
                }

            case JMMImageType.TvDB_Episode:

                TvDB_Episode ep = repEpisodes.GetByID(int.Parse(entityID));
                if (ep == null)
                {
                    return(null);
                }

                if (File.Exists(ep.FullImagePath))
                {
                    return(File.ReadAllBytes(ep.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find TvDB_Episode image: {0}", ep.FullImagePath);
                    return(null);
                }

            case JMMImageType.TvDB_FanArt:

                TvDB_ImageFanart fanart = repFanart.GetByID(int.Parse(entityID));
                if (fanart == null)
                {
                    return(null);
                }

                if (thumnbnailOnly)
                {
                    if (File.Exists(fanart.FullThumbnailPath))
                    {
                        return(File.ReadAllBytes(fanart.FullThumbnailPath));
                    }
                    else
                    {
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullThumbnailPath);
                        return(null);
                    }
                }
                else
                {
                    if (File.Exists(fanart.FullImagePath))
                    {
                        return(File.ReadAllBytes(fanart.FullImagePath));
                    }
                    else
                    {
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullImagePath);
                        return(null);
                    }
                }

            case JMMImageType.MovieDB_Poster:

                MovieDB_Poster mPoster = repMoviePosters.GetByID(int.Parse(entityID));
                if (mPoster == null)
                {
                    return(null);
                }

                // now find only the original size
                mPoster = repMoviePosters.GetByOnlineID(mPoster.URL);
                if (mPoster == null)
                {
                    return(null);
                }

                if (File.Exists(mPoster.FullImagePath))
                {
                    return(File.ReadAllBytes(mPoster.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.FullImagePath);
                    return(null);
                }

            case JMMImageType.MovieDB_FanArt:

                MovieDB_Fanart mFanart = repMovieFanart.GetByID(int.Parse(entityID));
                if (mFanart == null)
                {
                    return(null);
                }

                mFanart = repMovieFanart.GetByOnlineID(mFanart.URL);
                if (mFanart == null)
                {
                    return(null);
                }

                if (File.Exists(mFanart.FullImagePath))
                {
                    return(File.ReadAllBytes(mFanart.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.FullImagePath);
                    return(null);
                }

            case JMMImageType.Trakt_Fanart:

                Trakt_ImageFanart tFanart = repTraktFanart.GetByID(int.Parse(entityID));
                if (tFanart == null)
                {
                    return(null);
                }

                if (File.Exists(tFanart.FullImagePath))
                {
                    return(File.ReadAllBytes(tFanart.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.FullImagePath);
                    return(null);
                }

            case JMMImageType.Trakt_Friend:


                Trakt_Friend tFriend = repTraktFriends.GetByID(int.Parse(entityID));
                if (tFriend == null)
                {
                    return(null);
                }

                if (File.Exists(tFriend.FullImagePath))
                {
                    return(File.ReadAllBytes(tFriend.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find Trakt_Friend image: {0}", tFriend.FullImagePath);
                    return(null);
                }

            case JMMImageType.Trakt_ActivityScrobble:
            case JMMImageType.Trakt_ShoutUser:


                Trakt_Friend tFriendScrobble = repTraktFriends.GetByID(int.Parse(entityID));
                if (tFriendScrobble == null)
                {
                    return(null);
                }

                if (File.Exists(tFriendScrobble.FullImagePath))
                {
                    return(File.ReadAllBytes(tFriendScrobble.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find Trakt_ActivityScrobble image: {0}", tFriendScrobble.FullImagePath);
                    return(null);
                }

            case JMMImageType.Trakt_Poster:

                Trakt_ImagePoster tPoster = repTraktPosters.GetByID(int.Parse(entityID));
                if (tPoster == null)
                {
                    return(null);
                }

                if (File.Exists(tPoster.FullImagePath))
                {
                    return(File.ReadAllBytes(tPoster.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.FullImagePath);
                    return(null);
                }

            case JMMImageType.Trakt_Episode:
            case JMMImageType.Trakt_WatchedEpisode:

                Trakt_Episode tEpisode = repTraktEpisodes.GetByID(int.Parse(entityID));
                if (tEpisode == null)
                {
                    return(null);
                }

                if (File.Exists(tEpisode.FullImagePath))
                {
                    return(File.ReadAllBytes(tEpisode.FullImagePath));
                }
                else
                {
                    logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.FullImagePath);
                    return(null);
                }

            default:

                return(null);
            }
        }
        public System.IO.Stream GetImage(string ImageType, string ImageID, bool thumnbnailOnly, out string contentType)
        {
            contentType = null;

            JMMImageType imageType = (JMMImageType)int.Parse(ImageType);

            string path;

            switch (imageType)
            {
            case JMMImageType.AniDB_Cover:

                AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(int.Parse(ImageID));
                if (anime == null)
                {
                    return(null);
                }

                path = anime.PosterPath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Cover image: {0}", anime.PosterPath);
                    return(BlankImage());
                }

            case JMMImageType.AniDB_Character:

                AniDB_Character chr = RepoFactory.AniDB_Character.GetByID(int.Parse(ImageID));
                if (chr == null)
                {
                    return(null);
                }

                path = chr.PosterPath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Character image: {0}", chr.PosterPath);
                    return(BlankImage());
                }

            case JMMImageType.AniDB_Creator:

                AniDB_Seiyuu creator = RepoFactory.AniDB_Seiyuu.GetByID(int.Parse(ImageID));
                if (creator == null)
                {
                    return(null);
                }

                path = creator.PosterPath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find AniDB_Creator image: {0}", creator.PosterPath);
                    return(BlankImage());
                }

            case JMMImageType.TvDB_Cover:

                TvDB_ImagePoster poster = RepoFactory.TvDB_ImagePoster.GetByID(int.Parse(ImageID));
                if (poster == null)
                {
                    return(null);
                }

                path = poster.FullImagePath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Cover image: {0}", poster.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.TvDB_Banner:

                TvDB_ImageWideBanner wideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(int.Parse(ImageID));
                if (wideBanner == null)
                {
                    return(null);
                }

                path = wideBanner.FullImagePath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Banner image: {0}", wideBanner.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.TvDB_Episode:

                TvDB_Episode ep = RepoFactory.TvDB_Episode.GetByID(int.Parse(ImageID));
                if (ep == null)
                {
                    return(null);
                }

                path = ep.FullImagePath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find TvDB_Episode image: {0}", ep.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.TvDB_FanArt:

                TvDB_ImageFanart fanart = RepoFactory.TvDB_ImageFanart.GetByID(int.Parse(ImageID));
                if (fanart == null)
                {
                    return(null);
                }

                if (thumnbnailOnly)
                {
                    path = fanart.FullThumbnailPath;
                    if (File.Exists(path))
                    {
                        FileStream fs = File.OpenRead(path);
                        contentType = MimeTypes.GetMimeType(path);
                        return(fs);
                    }
                    else
                    {
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullThumbnailPath);
                        return(null);
                    }
                }
                else
                {
                    path = fanart.FullImagePath;
                    if (File.Exists(path))
                    {
                        FileStream fs = File.OpenRead(path);
                        contentType = MimeTypes.GetMimeType(path);
                        return(fs);
                    }
                    else
                    {
                        logger.Trace("Could not find TvDB_FanArt image: {0}", fanart.FullImagePath);
                        return(BlankImage());
                    }
                }

            case JMMImageType.MovieDB_Poster:

                MovieDB_Poster mPoster = RepoFactory.MovieDB_Poster.GetByID(int.Parse(ImageID));
                if (mPoster == null)
                {
                    return(null);
                }

                // now find only the original size
                mPoster = RepoFactory.MovieDB_Poster.GetByOnlineID(mPoster.URL);
                if (mPoster == null)
                {
                    return(null);
                }

                path = mPoster.FullImagePath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find MovieDB_Poster image: {0}", mPoster.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.MovieDB_FanArt:

                MovieDB_Fanart mFanart = RepoFactory.MovieDB_Fanart.GetByID(int.Parse(ImageID));
                if (mFanart == null)
                {
                    return(null);
                }

                mFanart = RepoFactory.MovieDB_Fanart.GetByOnlineID(mFanart.URL);
                if (mFanart == null)
                {
                    return(null);
                }

                path = mFanart.FullImagePath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find MovieDB_FanArt image: {0}", mFanart.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.Trakt_Fanart:

                Trakt_ImageFanart tFanart = RepoFactory.Trakt_ImageFanart.GetByID(int.Parse(ImageID));
                if (tFanart == null)
                {
                    return(null);
                }

                path = tFanart.FullImagePath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Fanart image: {0}", tFanart.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.Trakt_Poster:

                Trakt_ImagePoster tPoster = RepoFactory.Trakt_ImagePoster.GetByID(int.Parse(ImageID));
                if (tPoster == null)
                {
                    return(null);
                }

                path = tPoster.FullImagePath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Poster image: {0}", tPoster.FullImagePath);
                    return(BlankImage());
                }

            case JMMImageType.Trakt_Episode:
            case JMMImageType.Trakt_WatchedEpisode:

                Trakt_Episode tEpisode = RepoFactory.Trakt_Episode.GetByID(int.Parse(ImageID));
                if (tEpisode == null)
                {
                    return(null);
                }

                path = tEpisode.FullImagePath;
                if (File.Exists(path))
                {
                    FileStream fs = File.OpenRead(path);
                    contentType = MimeTypes.GetMimeType(path);
                    return(fs);
                }
                else
                {
                    logger.Trace("Could not find Trakt_Episode image: {0}", tEpisode.FullImagePath);
                    return(BlankImage());
                }

            default:

                return(BlankImage());
            }
        }