Example #1
0
        /// <summary>
        /// Search a movie by name
        /// </summary>
        /// <param name="name">Search string (Title of movie)</param>
        /// <returns>List of Metadata objects representing the match found</returns>
        public async Task <List <LimeOpus> > SearchVideoAsync(string name)
        {
            Connect();

            SearchContainer <SearchMovie> results = await TmdbClient.SearchMovieAsync(name, _Language, 0, Adult);

            // TODO: Retrieve TvShow if a number is mentioned
            //var tvshow = await TmdbClient.SearchTvShowAsync(name);

            var ret = new List <LimeOpus>(results.Results.Count);

            if (results.Results.Count == 0)
            {
                return(ret);
            }

            foreach (SearchMovie result in results.Results)
            {
                var genres = await GetGenresAsync(result.GenreIds, result.Adult);

                Uri imageUri = null;
                if (result.PosterPath != null)
                {
                    imageUri = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), result.PosterPath);
                }

                var meta = new LimeOpus(LimeOpusType.Movie, result.Id, result.Title ?? "")
                {
                    OriginalTitle    = result?.OriginalTitle ?? "",
                    OriginalLanguage = result?.OriginalLanguage ?? "",
                    Description      = CleanupDescription.Replace(result.Overview ?? "").Trim(),
                    Score            = result.VoteAverage > 0 ? result.VoteAverage / 2.0 : 0.0,
                    Released         = result.ReleaseDate != null ? (uint)result.ReleaseDate.Value.Year : 0,
                    Genres           = genres,
                    PosterUrl        = imageUri?.AbsoluteUri
                };

                meta.BuildToolTip();

                ret.Add(meta);
            }

            return(ret);
        }
Example #2
0
        /// <summary>
        /// Update a Person data from TMDb
        /// </summary>
        /// <param name="person">Person to be updated</param>
        /// <returns>true if updated</returns>
        public async Task <bool> GetPersonAsync(LimePerson person)
        {
            Connect();

            // Retrieve person-ID by name
            if (person.TmdbId == 0)
            {
                var search = await TmdbClient.SearchPersonAsync(person.Name, 0, Adult);

                if (search.Results != null && search.Results.Count > 0 &&
                    string.Equals(search.Results[0].Name, person.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    person.TmdbId = search.Results[0].Id;
                }
            }

            // Retrieve person by ID
            if (person.TmdbId != 0)
            {
                var db = await TmdbClient.GetPersonAsync(
                    person.TmdbId,
                    TMDbLib.Objects.People.PersonMethods.Images |
                    TMDbLib.Objects.People.PersonMethods.MovieCredits
                    );

                if (db == null)
                {
                    return(false);
                }

                var pics = new List <LimePicture>(10);
                foreach (var img in db.Images.Profiles)
                {
                    DownloadPic(ref pics, img.FilePath, PictureType.Artist);
                }
                person.Pictures = pics.ToArray();

                person.ImdbId    = db.ImdbId;
                person.TmdbPage  = db.ProfilePath;
                person.Name      = db.Name;
                person.Alias     = db.AlsoKnownAs?.ToArray();
                person.Gender    = (LimePerson.PersonGender)db.Gender;
                person.Adult     = db.Adult;
                person.Birthday  = db.Birthday;
                person.Deathday  = db.Deathday;
                person.Biography = CleanupDescription.Replace(db.Biography).Trim();
                person.Homepage  = db.Homepage;

                // Build Opus

                var opus = new List <LimeOpus>();
                if (db.MovieCredits?.Cast != null)
                {
                    foreach (var cast in db.MovieCredits.Cast)
                    {
                        // Avoid duplicates
                        var op = opus.Find(o => o.TmdbId == cast.Id);
                        if (op != null)
                        {
                            if (!op.Roles.Contains(cast.Character))
                            {
                                op.Roles.Add(cast.Character);
                            }
                        }
                        else
                        {
                            op = new LimeOpus(LimeOpusType.Movie, cast.Id, cast.Title, cast.Character)
                            {
                                OriginalTitle = cast.OriginalTitle,
                                Adult         = cast.Adult,
                                Released      = cast.ReleaseDate != null ? (uint)cast.ReleaseDate.Value.Year : 0
                            };
                            if (cast.PosterPath != null)
                            {
                                op.PosterUrl = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), cast.PosterPath)?.AbsoluteUri;
                            }
                            opus.Add(op);
                        }
                    }
                }

                if (db.TvCredits?.Cast != null)
                {
                    foreach (var cast in db.TvCredits.Cast)
                    {
                        // Avoid duplicates
                        var op = opus.Find(o => o.TmdbId == cast.Id);
                        if (op != null)
                        {
                            if (!op.Roles.Contains(cast.Character))
                            {
                                op.Roles.Add(cast.Character);
                            }
                        }
                        else
                        {
                            op = new LimeOpus(LimeOpusType.TvShow, cast.Id, cast.Name, cast.Character)
                            {
                                OriginalTitle = cast.OriginalName,
                                Released      = cast.FirstAirDate != null ? (uint)cast.FirstAirDate.Value.Year : 0
                            };
                            if (cast.PosterPath != null)
                            {
                                op.PosterUrl = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), cast.PosterPath)?.AbsoluteUri;
                            }
                            opus.Add(op);
                        }
                    }
                }

                if (db.MovieCredits?.Crew != null)
                {
                    foreach (var cast in db.MovieCredits.Crew)
                    {
                        // Avoid duplicates
                        var op = opus.Find(o => o.TmdbId == cast.Id);
                        if (op != null)
                        {
                            if (!op.Roles.Contains(cast.Department))
                            {
                                op.Roles.Add(cast.Department);
                            }
                        }
                        else
                        {
                            op = new LimeOpus(LimeOpusType.Movie, cast.Id, cast.Title, cast.Department)
                            {
                                OriginalTitle = cast.OriginalTitle,
                                Adult         = cast.Adult,
                                Released      = cast.ReleaseDate != null ? (uint)cast.ReleaseDate.Value.Year : 0
                            };
                            if (cast.PosterPath != null)
                            {
                                op.PosterUrl = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), cast.PosterPath)?.AbsoluteUri;
                            }
                            opus.Add(op);
                        }
                    }
                }


                if (db.TvCredits?.Crew != null)
                {
                    foreach (var cast in db.TvCredits.Crew)
                    {
                        // Avoid duplicates
                        var op = opus.Find(o => o.TmdbId == cast.Id);
                        if (op != null)
                        {
                            if (!op.Roles.Contains(cast.Department))
                            {
                                op.Roles.Add(cast.Department);
                            }
                        }
                        else
                        {
                            op = new LimeOpus(LimeOpusType.TvShow, cast.Id, cast.Name, cast.Department)
                            {
                                OriginalTitle = cast.OriginalName,
                                Released      = cast.FirstAirDate != null ? (uint)cast.FirstAirDate.Value.Year : 0
                            };
                            if (cast.PosterPath != null)
                            {
                                op.PosterUrl = TmdbClient.GetImageUrl(TmdbClient.Config.Images.PosterSizes.Last(), cast.PosterPath)?.AbsoluteUri;
                            }
                            opus.Add(op);
                        }
                    }
                }

                // Set genres
                foreach (var op in opus)
                {
                    if (op.Adult)
                    {
                        op.Genres = new string[] { LimeLanguage.Translate(IniLanguageSection, "GenreAdult", "GenreAdult") }
                    }
                    ;
                    op.BuildToolTip();
                }

                person.Opus = opus.ToArray();

                return(true);
            }

            return(false);
        }