private List <DBProgram> DownloadPrograms(IEnumerable <string> programIDs) { const int kBatchSize = 5000; List <string> currentBatch = new List <string>(); List <DBProgram> fetchedPrograms = new List <DBProgram>(); Func <int> FetchCurrentBatch = new Func <int>(() => { Console.WriteLine("Downloading program info from SchedulesDirect"); List <object> response = JSONClient.GetJSONResponse <List <object> >( UrlBuilder.BuildWithAPIPrefix("/programs"), currentBatch, SDTokenManager.token_manager.token); List <DBProgram> programsThisBatch = new List <DBProgram>(); // Only include programs fetched successfully, so any errors do not replace good data. List <SDProgram> successfulResponses = new List <SDProgram>(); foreach (object genericJson in response) { SDProgram sdProgram = null; try { sdProgram = JSONClient.Deserialize <SDProgram>(genericJson.ToString()); } catch (Exception exc) { Console.WriteLine("Failed to deserialize program JSON: {0}", genericJson); Misc.OutputException(exc); continue; } if (sdProgram.code > 0) { Console.WriteLine("Failed to download updated program info for programID {0}, response {1}, message: {2}", sdProgram.programID, sdProgram.response, sdProgram.message); continue; } successfulResponses.Add(sdProgram); var dbProgram = new DBProgram(sdProgram); fetchedPrograms.Add(dbProgram); programsThisBatch.Add(dbProgram); } DBManager.instance.SaveRawSDProgramResponses(successfulResponses); DBManager.instance.SaveProgramData(programsThisBatch); currentBatch.Clear(); return(0); }); foreach (string id in programIDs) { currentBatch.Add(id); if (currentBatch.Count >= kBatchSize) { FetchCurrentBatch(); } } if (currentBatch.Count > 0) { FetchCurrentBatch(); } return(fetchedPrograms); }
internal DBCastMember(SDProgram.SDCastMember sdCastMember) { id = string.Format("{0}|{1}", sdCastMember.personID ?? string.Empty, sdCastMember.nameID ?? string.Empty); name = sdCastMember.name; if (string.IsNullOrEmpty(id)) id = name; roleType = RoleType.Producer; // Default until we figure out more appropriate role foreach (var kv in roleSubstringMapping_) if (sdCastMember.role.Contains(kv.Key)) roleType = kv.Value; billingOrder = int.Parse(sdCastMember.billingOrder); PersonCache.instance.AddPerson(id, name); }
public DBProgram(SDProgram sdProgram) { programID = sdProgram.programID; // First title from SD used as primary, longest and shortest kept if different to use // in SeriesInfo. title = sdProgram.GetFirstTitle(); string sTitle = sdProgram.GetShortTitle(); if (sTitle != null && sTitle != title) { shortTitle = sTitle; } string lTitle = sdProgram.GetLongTitle(); if (lTitle != null && lTitle != title) { longTitle = lTitle; } episodeTitle = sdProgram.episodeTitle150; // There may be many SchedulesDirect descriptions, but WMC supports 1 short & 1 long, so we // use the first 100 char description and first 1000 char description. var sdDescriptions = sdProgram.descriptions; if (sdDescriptions != null) { if (sdDescriptions.description1000s?.Count > 0) { description = sdDescriptions.description1000s[0].description; } if (sdDescriptions.description100s?.Count > 0) { shortDescription = sdDescriptions.description100s[0].description; } } language = sdProgram.GetLanguage(); originalAirDate = sdProgram.originalAirDate; seasonNumber = sdProgram.GetSeasonNumber(); episodeNumber = sdProgram.GetEpisodeNumber(); keyWords = sdProgram.keyWords; showType = sdProgram.showType; entityType = sdProgram.entityType; if (sdProgram?.movie?.qualityRating?.Length > 0) { var qualityRating = sdProgram.movie.qualityRating[0]; double rating = double.Parse(qualityRating.rating); double minRating = double.Parse(qualityRating.minRating); double maxRating = double.Parse(qualityRating.maxRating); double unitRating = (1.0 * (rating - minRating)) / (maxRating - minRating); halfStars = 1 + (int)(unitRating * 7 + 0.5); } mpaaRating = sdProgram.GetMpaaRating(); if (sdProgram.genres?.Length > 0) { genres = new HashSet <string>(sdProgram.genres); } if (sdProgram.contentAdvisory?.Length > 0) { contentAdvisory = new HashSet <string>(sdProgram.contentAdvisory); } hasImages = sdProgram.hasImageArtwork; List <SDProgram.SDCastMember> castMembers = new List <SDProgram.SDCastMember>(); if (sdProgram.cast != null) { castMembers.AddRange(sdProgram.cast); } if (sdProgram.crew != null) { castMembers.AddRange(sdProgram.crew); } if (castMembers.Count > 0) { castAndCrew = new List <DBCastMember>(); foreach (var castMember in castMembers) { castAndCrew.Add(new DBCastMember(castMember)); } } md5 = sdProgram.md5; }
public DBProgram(SDProgram sdProgram) { programID = sdProgram.programID; // First title from SD used as primary, longest and shortest kept if different to use // in SeriesInfo. title = sdProgram.GetFirstTitle(); string sTitle = sdProgram.GetShortTitle(); if (sTitle != null && sTitle != title) { shortTitle = sTitle; } string lTitle = sdProgram.GetLongTitle(); if (lTitle != null && lTitle != title) { longTitle = lTitle; } episodeTitle = sdProgram.episodeTitle150; // There may be many SchedulesDirect descriptions, but WMC supports 1 short & 1 long, so we // use the first 100 char description and first 1000 char description. var sdDescriptions = sdProgram.descriptions; if (sdDescriptions != null) { if (sdDescriptions.description1000s?.Count > 0) description = sdDescriptions.description1000s[0].description; if (sdDescriptions.description100s?.Count > 0) shortDescription = sdDescriptions.description100s[0].description; } language = sdProgram.GetLanguage(); originalAirDate = sdProgram.originalAirDate; seasonNumber = sdProgram.GetSeasonNumber(); episodeNumber = sdProgram.GetEpisodeNumber(); keyWords = sdProgram.keyWords; showType = sdProgram.showType; entityType = sdProgram.entityType; if (sdProgram?.movie?.qualityRating?.Length > 0) { var qualityRating = sdProgram.movie.qualityRating[0]; double rating = double.Parse(qualityRating.rating); double minRating = double.Parse(qualityRating.minRating); double maxRating = double.Parse(qualityRating.maxRating); double unitRating = (1.0 * (rating - minRating)) / (maxRating - minRating); halfStars = 1 + (int)(unitRating * 7 + 0.5); } mpaaRating = sdProgram.GetMpaaRating(); if (sdProgram.genres?.Length > 0) genres = new HashSet<string>(sdProgram.genres); if (sdProgram.contentAdvisory?.Length > 0) contentAdvisory = new HashSet<string>(sdProgram.contentAdvisory); hasImages = sdProgram.hasImageArtwork; List<SDProgram.SDCastMember> castMembers = new List<SDProgram.SDCastMember>(); if (sdProgram.cast != null) castMembers.AddRange(sdProgram.cast); if (sdProgram.crew != null) castMembers.AddRange(sdProgram.crew); if (castMembers.Count > 0) { castAndCrew = new List<DBCastMember>(); foreach (var castMember in castMembers) { castAndCrew.Add(new DBCastMember(castMember)); } } md5 = sdProgram.md5; }