public override int DiscoverSubCategories(Category parentCategory) { parentCategory.SubCategories = new List <Category>(); List <Category> nhlCategories = new List <Category>(); List <Category> otherCategories = new List <Category>(); if (parentCategory.Name.Equals(liveGamesCategoryStr)) { string authTokenString = getAuthToken(); // get Live games string getLiveGamesUrl = string.Format("{0}?token={1}", apiUrl_getLive, authTokenString); string jsonResponse = GetWebData(getLiveGamesUrl, null, null, null, null, false, false, useragent, null, null, false); Log.Debug("Discover Sub Categories - Live Games: \\n" + jsonResponse); JObject jsonVideoList = JObject.Parse(jsonResponse); JToken jsonSchedule = jsonVideoList["schedule"]; foreach (JToken game in jsonSchedule) { string feedType = game.Value <string>("feedType"); if (string.IsNullOrEmpty(feedType) || feedType.Equals("null")) { feedType = "singleFeed"; } LiveGame liveGame = new LiveGame(); // encode ID into other string status = ""; if (game.Value <string>("period").Length == 0) { status = game.Value <string>("startTime"); } else { status = game.Value <string>("period"); } liveGame.Other = game.Value <int>("id"); liveGame.Name = string.Format("{0} - {1} {2} at {3} {4} - {5} - {6}", game.Value <string>("event"), game.Value <string>("awayTeam"), game.Value <string>("awayScore"), game.Value <string>("homeTeam"), game.Value <string>("homeScore"), status, feedType); liveGame.ParentCategory = parentCategory; if (game.Value <string>("event").Equals("NHL")) { liveGame.Thumb = image_nhl_url; nhlCategories.Add(liveGame); } else { liveGame.Thumb = image_hs_url; otherCategories.Add(liveGame); } } } else if (parentCategory.Name.Equals(archivedGamesCategoryStr)) { string authTokenString = getAuthToken(); // get archived games for today, yesterday and the day before that for DateTime loopDate = DateTime.Now; for (int i = 0; i < archivedGamesDaysBackwards; i++) { // date string is formatted like this: MM/DD/YYYY string dateString = string.Format("{0:MM/dd/yyyy}", loopDate); loopDate = loopDate.AddDays(-1); string apiUrl = apiUrl_getOnDemand; if (parentCategory.Name.Equals(condensedGamesCategoryStr)) { apiUrl = apiUrl_getCondensedGames; } else if (parentCategory.Name.Equals(highlightsCategoryStr)) { apiUrl = apiUrl_getHighlights; } string fullUrl = string.Format("{0}?date={1}&token={2}", apiUrl, dateString, authTokenString); string jsonResponse = GetWebData(fullUrl, null, null, null, null, false, false, useragent, null, null, false); if (jsonResponse.Length == 0) { continue; } Log.Debug("Discover Sub Categories - " + parentCategory.Name + ": \\n" + jsonResponse); JObject jsonVideoList = JObject.Parse(jsonResponse); JToken jsonSchedule = jsonVideoList["ondemand"]; if (parentCategory.Name.Equals(condensedGamesCategoryStr)) { jsonSchedule = jsonVideoList["condensed"]; } else if (parentCategory.Name.Equals(highlightsCategoryStr)) { jsonSchedule = jsonVideoList["highlights"]; } // condensed games and highlights get treated the same as archived games foreach (JToken game in jsonSchedule) { ArchivedGame archivedGame = new ArchivedGame(); archivedGame.Other = game.Value <int>("id"); // encode ID into other archivedGame.Name = string.Format("{0} - {1} - {2} at {3}", game.Value <string>("event"), game.Value <string>("date"), game.Value <string>("awayTeam"), game.Value <string>("homeTeam") ); archivedGame.ParentCategory = parentCategory; if (game.Value <string>("event").Equals("NHL")) { archivedGame.Thumb = image_nhl_url; nhlCategories.Add(archivedGame); } else { archivedGame.Thumb = image_hs_url; otherCategories.Add(archivedGame); } } } } else { // highlights and condensed games /* * * structure of json doc * * {"status":"Success","condensed":[ * {"id":"9981","date":"03\/30\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Toronto Maple Leafs", * "homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0513\/2_513_tor__1213_h_condensed_1600K_16x9_1.mp4","0": * "awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0513\/2_513_tor__1213_a_condensed_1600K_16x9_1.mp4"}, * {"id":"9931","date":"03\/28\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"New York Rangers","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0495\/2_495_nyr__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0495\/2_495_nyr__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9838","date":"03\/25\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"New Jersey Devils","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0473\/2_473_njd__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0473\/2_473_njd__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9762","date":"03\/23\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Tampa Bay Lightning","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0456\/2_456_tbl__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0456\/2_456_tbl__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9713","date":"03\/21\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Boston Bruins","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0447\/2_447_bos__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0447\/2_447_bos__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9676","date":"03\/19\/2013","event":"NHL","homeTeam":"New York Islanders","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0430\/2_430_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0430\/2_430_ott__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9646","date":"03\/17\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Winnipeg Jets","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0419\/2_419_wpg__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0419\/2_419_wpg__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9585","date":"03\/16\/2013","event":"NHL","homeTeam":"Buffalo Sabres","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0407\/2_407_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0407\/2_407_ott__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9511","date":"03\/13\/2013","event":"NHL","homeTeam":"Montreal Canadiens","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0388\/2_388_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0388\/2_388_ott__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9510","date":"03\/13\/2013","event":"NHL","homeTeam":"Montreal Canadiens","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0388\/2_388_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0388\/2_388_ott__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9471","date":"03\/11\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Boston Bruins","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0375\/2_375_bos__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0375\/2_375_bos__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9358","date":"03\/08\/2013","event":"NHL","homeTeam":"New York Rangers","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0350\/2_350_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0350\/2_350_ott__1213_a_condensed_1600K_16x9_1.mp4"}]} */ string authTokenString = getAuthToken(); // get archived games for today, yesterday and the day before that for DateTime loopDate = DateTime.Now; for (int i = 0; i < archivedGamesDaysBackwards; i++) { // date string is formatted like this: MM/DD/YYYY string dateString = string.Format("{0:MM/dd/yyyy}", loopDate); loopDate = loopDate.AddDays(-1); string apiUrl = apiUrl_getOnDemand; apiUrl = apiUrl_getCondensedGames; string fullUrl = string.Format("{0}?date={1}&token={2}", apiUrl, dateString, authTokenString); string jsonResponse = GetWebData(fullUrl, null, null, null, null, false, false, useragent, null, null, false); if (jsonResponse.Length == 0) { continue; } Log.Debug("Discover Sub Categories - " + parentCategory.Name + ": \\n" + jsonResponse); JObject jsonVideoList = JObject.Parse(jsonResponse); JToken jsonSchedule = ""; if (parentCategory.Name.Equals(condensedGamesCategoryStr)) { jsonSchedule = jsonVideoList["condensed"]; } else if (parentCategory.Name.Equals(highlightsCategoryStr)) { jsonSchedule = jsonVideoList["highlights"]; } // condensed games and highlights get treated the same as archived games foreach (JToken game in jsonSchedule) { DirectVideo dv = new DirectVideo(); dv.Other = game.Value <int>("id"); // encode ID into other dv.Name = string.Format("{0} - {1} - {2} at {3}", game.Value <string>("event"), game.Value <string>("date"), game.Value <string>("awayTeam"), game.Value <string>("homeTeam") ); dv.ParentCategory = parentCategory; dv.homeUrl = game.Value <string>("homeSrc"); dv.awayUrl = game.Value <string>("awaySrc"); if (game.Value <string>("event").Equals("NHL")) { dv.Thumb = image_nhl_url; nhlCategories.Add(dv); } else { dv.Thumb = image_hs_url; otherCategories.Add(dv); } } } } // put NHL games first parentCategory.SubCategories.AddRange(nhlCategories); parentCategory.SubCategories.AddRange(otherCategories); Settings.DynamicCategoriesDiscovered = false; return(parentCategory.SubCategories.Count); }
public override int DiscoverSubCategories(Category parentCategory) { parentCategory.SubCategories = new List<Category>(); List<Category> nhlCategories = new List<Category>(); List<Category> otherCategories = new List<Category>(); if (parentCategory.Name.Equals(liveGamesCategoryStr)) { string authTokenString = getAuthToken(); // get Live games string getLiveGamesUrl = string.Format("{0}?token={1}", apiUrl_getLive, authTokenString); string jsonResponse = GetWebData(getLiveGamesUrl,null,null,null,null, false, false, useragent, null, null, false); Log.Debug("Discover Sub Categories - Live Games: \\n" + jsonResponse); JObject jsonVideoList = JObject.Parse(jsonResponse); JToken jsonSchedule = jsonVideoList["schedule"]; foreach (JToken game in jsonSchedule) { string feedType = game.Value<string>("feedType"); if (string.IsNullOrEmpty(feedType) || feedType.Equals("null")) { feedType = "singleFeed"; } LiveGame liveGame = new LiveGame(); // encode ID into other string status = ""; if (game.Value<string>("period").Length == 0) { status = game.Value<string>("startTime"); } else { status = game.Value<string>("period"); } liveGame.Other = game.Value<int>("id"); liveGame.Name = string.Format("{0} - {1} {2} at {3} {4} - {5} - {6}", game.Value<string>("event"), game.Value<string>("awayTeam"), game.Value<string>("awayScore"), game.Value<string>("homeTeam"), game.Value<string>("homeScore"), status, feedType); liveGame.ParentCategory = parentCategory; if (game.Value<string>("event").Equals("NHL")) { liveGame.Thumb = image_nhl_url; nhlCategories.Add(liveGame); } else { liveGame.Thumb = image_hs_url; otherCategories.Add(liveGame); } } } else if (parentCategory.Name.Equals(archivedGamesCategoryStr)){ string authTokenString = getAuthToken(); // get archived games for today, yesterday and the day before that for DateTime loopDate = DateTime.Now; for (int i = 0; i < archivedGamesDaysBackwards; i++) { // date string is formatted like this: MM/DD/YYYY string dateString = string.Format("{0:MM/dd/yyyy}", loopDate); loopDate = loopDate.AddDays(-1); string apiUrl = apiUrl_getOnDemand; if (parentCategory.Name.Equals(condensedGamesCategoryStr)) { apiUrl = apiUrl_getCondensedGames; } else if (parentCategory.Name.Equals(highlightsCategoryStr)) { apiUrl = apiUrl_getHighlights; } string fullUrl = string.Format("{0}?date={1}&token={2}", apiUrl, dateString, authTokenString); string jsonResponse = GetWebData(fullUrl,null,null,null,null, false, false, useragent, null, null, false); if (jsonResponse.Length == 0) { continue; } Log.Debug("Discover Sub Categories - "+ parentCategory.Name + ": \\n" + jsonResponse); JObject jsonVideoList = JObject.Parse(jsonResponse); JToken jsonSchedule = jsonVideoList["ondemand"]; if (parentCategory.Name.Equals(condensedGamesCategoryStr)) { jsonSchedule = jsonVideoList["condensed"]; } else if (parentCategory.Name.Equals(highlightsCategoryStr)) { jsonSchedule = jsonVideoList["highlights"]; } // condensed games and highlights get treated the same as archived games foreach (JToken game in jsonSchedule) { ArchivedGame archivedGame = new ArchivedGame(); archivedGame.Other = game.Value<int>("id"); // encode ID into other archivedGame.Name = string.Format("{0} - {1} - {2} at {3}", game.Value<string>("event"), game.Value<string>("date"), game.Value<string>("awayTeam"), game.Value<string>("homeTeam") ); archivedGame.ParentCategory = parentCategory; if (game.Value<string>("event").Equals("NHL")) { archivedGame.Thumb = image_nhl_url; nhlCategories.Add(archivedGame); } else { archivedGame.Thumb = image_hs_url; otherCategories.Add(archivedGame); } } } } else { // highlights and condensed games /* * * structure of json doc * * {"status":"Success","condensed":[ * {"id":"9981","date":"03\/30\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Toronto Maple Leafs", * "homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0513\/2_513_tor__1213_h_condensed_1600K_16x9_1.mp4","0": * "awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0513\/2_513_tor__1213_a_condensed_1600K_16x9_1.mp4"}, * {"id":"9931","date":"03\/28\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"New York Rangers","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0495\/2_495_nyr__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0495\/2_495_nyr__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9838","date":"03\/25\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"New Jersey Devils","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0473\/2_473_njd__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0473\/2_473_njd__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9762","date":"03\/23\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Tampa Bay Lightning","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0456\/2_456_tbl__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0456\/2_456_tbl__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9713","date":"03\/21\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Boston Bruins","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0447\/2_447_bos__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0447\/2_447_bos__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9676","date":"03\/19\/2013","event":"NHL","homeTeam":"New York Islanders","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0430\/2_430_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0430\/2_430_ott__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9646","date":"03\/17\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Winnipeg Jets","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0419\/2_419_wpg__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0419\/2_419_wpg__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9585","date":"03\/16\/2013","event":"NHL","homeTeam":"Buffalo Sabres","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0407\/2_407_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0407\/2_407_ott__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9511","date":"03\/13\/2013","event":"NHL","homeTeam":"Montreal Canadiens","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0388\/2_388_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0388\/2_388_ott__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9510","date":"03\/13\/2013","event":"NHL","homeTeam":"Montreal Canadiens","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0388\/2_388_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0388\/2_388_ott__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9471","date":"03\/11\/2013","event":"NHL","homeTeam":"Ottawa Senators","awayTeam":"Boston Bruins","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0375\/2_375_bos__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0375\/2_375_bos__1213_a_condensed_1600K_16x9_1.mp4"},{"id":"9358","date":"03\/08\/2013","event":"NHL","homeTeam":"New York Rangers","awayTeam":"Ottawa Senators","homeSrc":"http:\/\/h264.nhl.com\/20122013\/02\/0350\/2_350_ott__1213_h_condensed_1600K_16x9_1.mp4","0":"awaySrc => http:\/\/h264.nhl.com\/20122013\/02\/0350\/2_350_ott__1213_a_condensed_1600K_16x9_1.mp4"}]} */ string authTokenString = getAuthToken(); // get archived games for today, yesterday and the day before that for DateTime loopDate = DateTime.Now; for (int i = 0; i < archivedGamesDaysBackwards; i++) { // date string is formatted like this: MM/DD/YYYY string dateString = string.Format("{0:MM/dd/yyyy}", loopDate); loopDate = loopDate.AddDays(-1); string apiUrl = apiUrl_getOnDemand; apiUrl = apiUrl_getCondensedGames; string fullUrl = string.Format("{0}?date={1}&token={2}", apiUrl, dateString, authTokenString); string jsonResponse = GetWebData(fullUrl,null,null,null,null, false, false, useragent, null, null, false); if (jsonResponse.Length == 0) { continue; } Log.Debug("Discover Sub Categories - "+ parentCategory.Name + ": \\n" + jsonResponse); JObject jsonVideoList = JObject.Parse(jsonResponse); JToken jsonSchedule = ""; if (parentCategory.Name.Equals(condensedGamesCategoryStr)) { jsonSchedule = jsonVideoList["condensed"]; } else if (parentCategory.Name.Equals(highlightsCategoryStr)) { jsonSchedule = jsonVideoList["highlights"]; } // condensed games and highlights get treated the same as archived games foreach (JToken game in jsonSchedule) { DirectVideo dv = new DirectVideo(); dv.Other = game.Value<int>("id"); // encode ID into other dv.Name = string.Format("{0} - {1} - {2} at {3}", game.Value<string>("event"), game.Value<string>("date"), game.Value<string>("awayTeam"), game.Value<string>("homeTeam") ); dv.ParentCategory = parentCategory; dv.homeUrl = game.Value<string>("homeSrc"); dv.awayUrl = game.Value<string>("awaySrc"); if (game.Value<string>("event").Equals("NHL")) { dv.Thumb = image_nhl_url; nhlCategories.Add(dv); } else { dv.Thumb = image_hs_url; otherCategories.Add(dv); } } } } // put NHL games first parentCategory.SubCategories.AddRange(nhlCategories); parentCategory.SubCategories.AddRange(otherCategories); Settings.DynamicCategoriesDiscovered = false; return parentCategory.SubCategories.Count; }