Пример #1
0
        private void LoadJson(JObject bestLanguageR, JObject backupLanguageR)
        {
            //Here we have two pieces of JSON. One in local language and one in the default language (English).
            //We will populate with the best language frst and then fill in any gaps with the backup Language
            LoadJson(bestLanguageR);

            //backupLanguageR should be a series of name/value pairs (ie a JArray of JPropertes)
            //TVDB asserts that name and overview are the fields that are localised

            if ((string.IsNullOrWhiteSpace(Name) && ((string)backupLanguageR["seriesName"] != null)))
            {
                Name = (string)backupLanguageR["seriesName"];
                items["seriesName"] = System.Web.HttpUtility.HtmlDecode(Name);
            }

            if ((string.IsNullOrWhiteSpace(items["overview"]) && ((string)backupLanguageR["overview"] != null)))
            {
                items["overview"] = System.Web.HttpUtility.HtmlDecode((string)backupLanguageR["overview"]);
            }

            //Looking at the data then the aliases, banner and runtime are also different by language

            if ((string.IsNullOrWhiteSpace(items["aliases"])))
            {
                items["aliases"] = JsonHelper.Flatten(backupLanguageR["aliases"], "|");
            }

            if ((string.IsNullOrWhiteSpace(items["runtime"])))
            {
                items["runtime"] = (string)backupLanguageR["runtime"];
            }

            if ((string.IsNullOrWhiteSpace(items["banner"])))
            {
                items["banner"] = (string)backupLanguageR["banner"];
            }
        }
Пример #2
0
        private void LoadJson(int seriesId, JObject r)
        {
            //r should be a series of name/value pairs (ie a JArray of JPropertes)
            //save them all into the Items array for safe keeping
            foreach (JProperty episodeItems in r.Children <JProperty>())
            {
                try
                {
                    JToken currentData = episodeItems.Value;
                    if (currentData.Type == JTokenType.Array)
                    {
                        items[episodeItems.Name] = JsonHelper.Flatten(currentData);
                    }
                    else if (currentData.Type != JTokenType.Object
                             ) //Ignore objects here as it is always the 'language' attribute that we do not need
                    {
                        JValue currentValue = (JValue)episodeItems.Value;
                        items[episodeItems.Name] = currentValue.ToObject <string>();
                    }
                }
                catch (ArgumentException ae)
                {
                    Logger.Error("Could not parse Json for " + episodeItems.Name + " :" + ae.Message);
                    //ignore as probably a cast exception
                }
                catch (NullReferenceException ae)
                {
                    Logger.Error("Could not parse Json for " + episodeItems.Name + " :" + ae.Message);
                    //ignore as probably a cast exception
                }
                catch (InvalidCastException ae)
                {
                    Logger.Error("Could not parse Json for " + episodeItems.Name + " :" + ae.Message);
                    //ignore as probably a cast exception
                }
            }

            SeriesId = seriesId;
            try
            {
                EpisodeId = (int)r["id"];

                if ((string)r["airedSeasonID"] != null)
                {
                    SeasonId = (int)r["airedSeasonID"];
                }
                else
                {
                    Logger.Error("Issue with episode " + EpisodeId + " for series " + seriesId + " no airedSeasonID ");
                    Logger.Error(r.ToString());
                }

                AiredEpNum = (int)r["airedEpisodeNumber"];

                string dvdEpNumString = (string)r["dvdEpisodeNumber"];

                if (string.IsNullOrWhiteSpace(dvdEpNumString))
                {
                    DvdEpNum = 0;
                }
                else if (!int.TryParse(dvdEpNumString, out DvdEpNum))
                {
                    DvdEpNum = 0;
                }

                SrvLastUpdated = (long)r["lastUpdated"];
                Overview       = System.Web.HttpUtility.HtmlDecode((string)r["overview"]);
                EpisodeRating  = (string)r["siteRating"];
                Name           = System.Web.HttpUtility.HtmlDecode((string)r["episodeName"]);

                string sn = (string)r["airedSeason"];
                if (sn == null)
                {
                    Logger.Error("Issue with episode " + EpisodeId + " for series " + seriesId + " airedSeason = null");
                    Logger.Error(r.ToString());
                }
                else
                {
                    int.TryParse(sn, out ReadAiredSeasonNum);
                }

                string dsn = (string)r["dvdSeason"];
                if (string.IsNullOrWhiteSpace(dsn))
                {
                    ReadDvdSeasonNum = 0;
                }
                else if (!int.TryParse(dsn, out ReadDvdSeasonNum))
                {
                    ReadDvdSeasonNum = 0;
                }

                EpisodeGuestStars = JsonHelper.Flatten(r["guestStars"], "|");
                EpisodeDirector   = JsonHelper.Flatten(r["directors"], "|");
                Writer            = JsonHelper.Flatten(r["writers"], "|");

                try
                {
                    string contents = (string)r["firstAired"];
                    if (string.IsNullOrEmpty(contents))
                    {
                        FirstAired = null;
                    }
                    else
                    {
                        FirstAired = DateTime.ParseExact(contents, "yyyy-MM-dd",
                                                         new System.Globalization.CultureInfo(""));
                    }
                }
                catch (Exception e)
                {
                    Logger.Debug(e, "Failed to parse firstAired");
                    FirstAired = null;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, $"Failed to parse : {r}");
            }
        }
Пример #3
0
        private void LoadJson(int seriesId, [NotNull] JObject r)
        {
            SeriesId = seriesId;
            try
            {
                EpisodeId = (int)r["id"];

                if (EpisodeId == 0)
                {
                    return;
                }

                if ((string)r["airedSeasonID"] != null)
                {
                    SeasonId = (int)r["airedSeasonID"];
                }
                else
                {
                    Logger.Error("Issue with episode (loadJSON) " + EpisodeId + " for series " + seriesId + " no airedSeasonID ");
                    Logger.Error(r.ToString());
                }

                AiredEpNum = (int)r["airedEpisodeNumber"];

                SrvLastUpdated = (long)r["lastUpdated"];
                Overview       = System.Net.WebUtility.HtmlDecode((string)r["overview"]);
                EpisodeRating  = (string)r["siteRating"];
                mName          = System.Net.WebUtility.HtmlDecode((string)r["episodeName"]);

                AirsBeforeEpisode = (int?)r["airsBeforeEpisode"];
                AirsBeforeSeason  = (int?)r["airsBeforeSeason"];
                AirsAfterSeason   = (int?)r["airsAfterSeason"];
                SiteRatingCount   = (int?)r["siteRatingCount"];
                AbsoluteNumber    = (int?)r["absoluteNumber"];
                Filename          = (string)r["filename"];
                ImdbCode          = (string)r["imdbId"];
                ShowUrl           = (string)r["showUrl"];
                ProductionCode    = (string)r["productionCode"];
                DvdChapter        = (int?)r["dvdChapter"];
                DvdDiscId         = (string)r["dvdDiscid"];

                string sn = (string)r["airedSeason"];
                if (sn is null)
                {
                    Logger.Error("Issue with episode " + EpisodeId + " for series " + seriesId + " airedSeason = null");
                    Logger.Error(r.ToString());
                }
                else
                {
                    int.TryParse(sn, out ReadAiredSeasonNum);
                }

                DvdEpNum         = ExtractStringToInt(r, "dvdEpisodeNumber");
                ReadDvdSeasonNum = ExtractStringToInt(r, "dvdSeason");

                EpisodeGuestStars = JsonHelper.Flatten(r["guestStars"], "|");
                EpisodeDirector   = JsonHelper.Flatten(r["directors"], "|");
                Writer            = JsonHelper.Flatten(r["writers"], "|");

                FirstAired = GetFirstAired(r);
            }
            catch (Exception e)
            {
                Logger.Error(e, $"Failed to parse : {r}");
            }
        }
Пример #4
0
        private void LoadJson(JObject r)
        {
            //r should be a series of name/value pairs (ie a JArray of JPropertes)
            //save them all into the Items array for safe keeping
            foreach (JProperty seriesItems in r.Children <JProperty>())
            {
                if (seriesItems.Name == "aliases")
                {
                    items[seriesItems.Name] = JsonHelper.Flatten(seriesItems.Value, "|");
                }
                else if (seriesItems.Name == "genre")
                {
                    items[seriesItems.Name] = JsonHelper.Flatten(seriesItems.Value, "|");
                }
                else if (seriesItems.Name == "overview")
                {
                    items[seriesItems.Name] = System.Web.HttpUtility.HtmlDecode((string)seriesItems.Value);
                }
                else
                {
                    try
                    {
                        if (seriesItems.Value != null)
                        {
                            items[seriesItems.Name] = (string)seriesItems.Value;
                        }
                    }
                    catch (ArgumentException ae) {
                        Logger.Warn("Could not parse Json for " + seriesItems.Name + " :" + ae.Message);
                    }
                }
            }

            TvdbCode = (int)r["id"];
            if ((string)r["seriesName"] != null)
            {
                Name = System.Web.HttpUtility.HtmlDecode((string)r["seriesName"]);
            }

            if (long.TryParse((string)r["lastUpdated"], out long updateTime))
            {
                SrvLastUpdated = updateTime;
            }
            else
            {
                SrvLastUpdated = 0;
            }

            string theDate = (string)r["firstAired"];

            try
            {
                if (!string.IsNullOrEmpty(theDate))
                {
                    FirstAired          = DateTime.ParseExact(theDate, "yyyy-MM-dd", new System.Globalization.CultureInfo(""));
                    items["firstAired"] = FirstAired.Value.ToString("yyyy-MM-dd");
                    items["Year"]       = FirstAired.Value.ToString("yyyy");
                }
                else
                {
                    FirstAired          = null;
                    items["firstAired"] = "";
                    items["Year"]       = "";
                }
            }
            catch
            {
                FirstAired          = null;
                items["firstAired"] = "";
                items["Year"]       = "";
            }

            AirsTime = ParseAirTime((string)r["airsTime"]);
        }