Example #1
0
        private static ListViewItem NewLvi([NotNull] CachedMovieInfo si, int num, string show, bool numberMatch)
        {
            ListViewItem lvi = new ListViewItem {
                Text = num.ToString()
            };

            lvi.SubItems.Add(show);
            if (si.FirstAired.HasValue)
            {
                lvi.SubItems.Add(si.FirstAired.Value.Year.ToString());
            }
            else
            {
                lvi.SubItems.Add(string.Empty);
            }

            lvi.SubItems.Add(si.ContentRating);
            lvi.SubItems.Add(si.ShowLanguage);

            lvi.ToolTipText = si.Overview;
            lvi.Tag         = si;
            if (numberMatch)
            {
                lvi.Selected = true;
            }

            return(lvi);
        }
Example #2
0
        private int?ValidateOnTMDB(int?tmdbId, string language, bool showErrorMsgBox)
        {
            if (tmdbId.HasValue)
            {
                try
                {
                    CachedMovieInfo series = TMDB.LocalCache.Instance.GetMovieAndDownload(tmdbId.Value, language, showErrorMsgBox);
                    return(series.TmdbCode);
                }
                catch (MediaNotFoundException)
                {
                    //continue to try the next method
                }
            }

            return(null);
        }
Example #3
0
        private static string CreateHtml([NotNull] MovieConfiguration si)
        {
            CachedMovieInfo cachedSeries = si.CachedMovie;

            if (cachedSeries is null)
            {
                return(string.Empty);
            }

            string yearRange  = cachedSeries.Year?.ToString() ?? "";
            string stars      = ShowHtmlHelper.StarRating(cachedSeries.SiteRating / 2);
            string genreIcons = string.Join(" ", cachedSeries.Genres.Select(ShowHtmlHelper.GenreIconHtml));
            string siteRating = cachedSeries.SiteRating > 0 ? cachedSeries.SiteRating + "/10" : "";

            string poster      = ShowHtmlHelper.CreatePosterHtml(cachedSeries);
            string runTimeHtml = string.IsNullOrWhiteSpace(cachedSeries.Runtime) ? string.Empty : $"<br/> {cachedSeries.Runtime} min";

            return($@"<div class=""card card-body"">
            <div class=""row"">
            <div class=""col-md-4"">
                {poster}
</div>
            <div class=""col-md-8 d-flex flex-column"">
                <div class=""row"">
                    <div class=""col-md-8""><h1>{si.ShowName}</h1><small class=""text-muted"">{cachedSeries.TagLine}</small></div>
                    <div class=""col-md-4 text-right""><h6>{yearRange} ({cachedSeries.Status})</h6>
<small class=""text-muted"">{cachedSeries.ShowLanguage} - {cachedSeries.Type}</small>
                        <small class=""text-muted"">{runTimeHtml}</small></div>
</div>
                
            <div><blockquote>{cachedSeries.Overview}</blockquote></div>
            <div><blockquote>{cachedSeries.GetActorNames().ToCsv()}</blockquote></div>
            <div class=""row align-items-bottom flex-grow-1"">
                <div class=""col-md-4 align-self-end"">{stars}<br>{siteRating}{ShowHtmlHelper.AddRatingCount(cachedSeries.SiteRatingVotes)}</div>
                <div class=""col-md-4 align-self-end text-center"">{cachedSeries.ContentRating}<br>{cachedSeries.Network}</div>
                <div class=""col-md-4 align-self-end text-right"">{genreIcons}<br>{cachedSeries.Genres.ToCsv()}</div>
            </div>
            </div></div></div>");
        }
Example #4
0
        // ReSharper disable once FunctionComplexityOverflow
        public void Merge([NotNull] CachedMovieInfo o)
        {
            if (o.IsSearchResultOnly && !IsSearchResultOnly)
            {
                return;
            }

            if (o.TvdbCode != TvdbCode && o.TvMazeCode != TvMazeCode)
            {
                return; // that's not us!
            }

            if (o.TvMazeCode != -1 && TvMazeCode != o.TvMazeCode)
            {
                TvMazeCode = o.TvMazeCode;
            }

            if (o.TvdbCode != -1 && TvdbCode != o.TvdbCode)
            {
                TvdbCode = o.TvdbCode;
            }

            if (o.TmdbCode != -1 && TmdbCode != o.TmdbCode)
            {
                TmdbCode = o.TmdbCode;
            }

            if (o.SrvLastUpdated != 0 && o.SrvLastUpdated < SrvLastUpdated)
            {
                return; // older!?
            }

            if (!o.IsSearchResultOnly)
            {
                IsSearchResultOnly = false;
            }
            bool     currentLanguageNotSet = LanguageId == -1;
            string   bestLanguageCode      = TargetLanguageCode ?? TVSettings.Instance.PreferredLanguageCode;
            Language optimaLanguage        = LocalCache.Instance.GetLanguageFromCode(bestLanguageCode);
            bool     newLanguageOptimal    = !(optimaLanguage is null) && o.LanguageId == optimaLanguage.Id;
            bool     useNewDataOverOld     = currentLanguageNotSet || newLanguageOptimal;

            SrvLastUpdated = o.SrvLastUpdated;

            // take the best bits of "o"
            // "o" is always newer/better than us, if there is a choice
            Name           = ChooseBetter(Name, useNewDataOverOld, o.Name);
            Imdb           = ChooseBetter(Imdb, useNewDataOverOld, o.Imdb);
            WebUrl         = ChooseBetter(WebUrl, useNewDataOverOld, o.WebUrl);
            OfficialUrl    = ChooseBetter(OfficialUrl, useNewDataOverOld, o.OfficialUrl);
            ShowLanguage   = ChooseBetter(ShowLanguage, useNewDataOverOld, o.ShowLanguage);
            Type           = ChooseBetter(Type, useNewDataOverOld, o.Type);
            Overview       = ChooseBetter(Overview, useNewDataOverOld, o.Overview);
            PosterUrl      = ChooseBetter(PosterUrl, useNewDataOverOld, o.PosterUrl);
            FanartUrl      = ChooseBetter(FanartUrl, useNewDataOverOld, o.FanartUrl);
            TrailerUrl     = ChooseBetter(TrailerUrl, useNewDataOverOld, o.TrailerUrl);
            Network        = ChooseBetter(Network, useNewDataOverOld, o.Network);
            Runtime        = ChooseBetter(Runtime, useNewDataOverOld, o.Runtime);
            SeriesId       = ChooseBetter(SeriesId, useNewDataOverOld, o.SeriesId);
            Status         = ChooseBetterStatus(Status, useNewDataOverOld, o.Status);
            ContentRating  = ChooseBetter(ContentRating, useNewDataOverOld, o.ContentRating);
            Slug           = ChooseBetter(Slug, useNewDataOverOld, o.Slug);
            CollectionName = ChooseBetter(CollectionName, useNewDataOverOld, o.CollectionName);
            TwitterId      = ChooseBetter(TwitterId, useNewDataOverOld, o.TwitterId);
            InstagramId    = ChooseBetter(InstagramId, useNewDataOverOld, o.InstagramId);
            FacebookId     = ChooseBetter(FacebookId, useNewDataOverOld, o.FacebookId);
            TagLine        = ChooseBetter(TagLine, useNewDataOverOld, o.TagLine);

            if (useNewDataOverOld && o.CollectionId.HasValue)
            {
                CollectionId = o.CollectionId;
            }

            if (o.FirstAired.HasValue && (useNewDataOverOld || !FirstAired.HasValue))
            {
                FirstAired = o.FirstAired;
            }

            if (useNewDataOverOld && o.SiteRating > 0)
            {
                SiteRating = o.SiteRating;
            }

            if (useNewDataOverOld && o.SiteRatingVotes > 0)
            {
                SiteRatingVotes = o.SiteRatingVotes;
            }

            bool useNewAliases = o.Aliases.Any() && useNewDataOverOld;

            if (!Aliases.Any() || useNewAliases)
            {
                Aliases = o.Aliases;
            }

            bool useNewGenres = o.Genres.Any() && useNewDataOverOld;

            if (!Genres.Any() || useNewGenres)
            {
                Genres = o.Genres;
            }

            if (useNewDataOverOld)
            {
                LanguageId = o.LanguageId;
            }

            Dirty = o.Dirty;
            IsSearchResultOnly = o.IsSearchResultOnly;
        }
Example #5
0
        protected override ActionOutcome UpdateFile()
        {
            XDocument doc  = XDocument.Load(Where.FullName);
            XElement? root = doc.Root;

            if (root is null)
            {
                return(new ActionOutcome($"Could not load {Where.FullName}"));
            }

            CachedMovieInfo cachedSeries = Movie !.CachedMovie;

            root.UpdateElement("title", Movie.ShowName);

            float?showRating = cachedSeries?.SiteRating;

            if (showRating.HasValue)
            {
                UpdateRatings(root, showRating.Value.ToString(CultureInfo.InvariantCulture), cachedSeries.SiteRatingVotes);
            }

            string lang = TVSettings.Instance.PreferredLanguageCode;

            if (Movie.UseCustomLanguage && Movie.PreferredLanguage != null)
            {
                lang = Movie.PreferredLanguage.Abbreviation;
            }

            //https://forum.kodi.tv/showthread.php?tid=323588
            //says that we need a format like this:
            //<episodeguide><url post="yes" cache="auth.json">https://api.thetvdb.com/login?{&quot;apikey&quot;:&quot;((API-KEY))&quot;,&quot;id&quot;:((ID))}|Content-Type=application/json</url></episodeguide>

            XElement episodeGuideNode = root.GetOrCreateElement("episodeguide");
            XElement urlNode          = episodeGuideNode.GetOrCreateElement("url");

            urlNode.UpdateAttribute("post", "yes");
            urlNode.UpdateAttribute("cache", "auth.json");
            urlNode.SetValue(TheTVDB.API.BuildUrl(Movie.TvdbCode, lang));

            if (!(cachedSeries is null))
            {
                root.UpdateElement("originaltitle", Movie.ShowName);
                UpdateAmongstElements(root, "studio", cachedSeries.Network);
                root.UpdateElement("id", Movie.Code);
                root.UpdateElement("runtime", cachedSeries.Runtime, true);
                root.UpdateElement("mpaa", cachedSeries.ContentRating, true);
                root.UpdateElement("premiered", cachedSeries.FirstAired);
                if (cachedSeries.Year.HasValue)
                {
                    root.UpdateElement("year", cachedSeries.Year.Value);
                }
                root.UpdateElement("status", cachedSeries.Status);
                root.UpdateElement("plot", cachedSeries.Overview);
                root.UpdateElement("outline", cachedSeries.Overview);
                root.UpdateElement("tagline", cachedSeries.TagLine);
                root.UpdateElement("set", cachedSeries.CollectionName);
                root.UpdateElement("trailer", cachedSeries.TrailerUrl);

                UpdateId(root, "tvdb", "false", cachedSeries.TvdbCode);
                UpdateId(root, "imdb", "false", cachedSeries.Imdb);
                UpdateId(root, "tmdb", "true", cachedSeries.TmdbCode);
            }

            root.ReplaceElements("genre", Movie.Genres);

            ReplaceActors(root, Movie.Actors);

            doc.Save(Where.FullName);
            return(ActionOutcome.Success());
        }