public void getYouTubeData() { YTTemboo yttb = new YTTemboo((YouTube)this); ListMyChannels listMyChannelsChoreo = new ListMyChannels(session); string s_channels = yttb.getTembooData(listMyChannelsChoreo); JObject json_channels = JObject.Parse(s_channels); string no_records = (string)json_channels["pageInfo"]["totalResults"]; string subscribers = (string)json_channels["items"][0]["statistics"]["subscriberCount"]; string comments = (string)json_channels["items"][0]["statistics"]["commentCount"]; string channel_id = (string)json_channels["items"][0]["id"]; ListMySubscribers listMySubscribersChoreo = new ListMySubscribers(session); // Set inputs listMySubscribersChoreo.setMaxResults("50"); string s_subscribers = yttb.getTembooData(listMySubscribersChoreo); JObject json_subscribers = JObject.Parse(s_subscribers); string no_subscr = (string)json_subscribers["totalResults"]; int k = 0; string subscr_name = (string)json_subscribers["items"][k]["snippet"]["title"]; while (subscr_name != null) { //get subscriber fields from JSON string googlep_id = (string)json_subscribers["items"][k]["contentDetails"]["googlePlusUserId"]; string subscr_id = (string)json_subscribers["items"][k]["id"]; //add to youtube_subscribers db table amDB.upsertYouTubeSubscriber(subscr_id, subscr_name, "", "", "Unknown", googlep_id); k++; try { subscr_name = (string)json_subscribers["items"][k]["snippet"]["title"]; } catch { subscr_name = null; } } ListSearchResults listSearchResultsChoreo = new ListSearchResults(session); // Set inputs listSearchResultsChoreo.setChannelID(channel_id); listSearchResultsChoreo.setType("video"); listSearchResultsChoreo.setMaxResults("50"); string s_videos = yttb.getTembooData(listSearchResultsChoreo);//listSearchResultsResults.Response; JObject json_videos = JObject.Parse(s_videos); //Get # videos int i = 0; int num_videos = 0; string s_video_ids = ""; Dictionary<string, string> d_videos = new Dictionary<string,string>(); JArray vid_array = JArray.Parse(json_videos["items"].ToString()); //create comma list of video ids foreach(JToken vt in vid_array) { string tmp = ""; tmp = vt["id"]["videoId"].ToString(); string title = vt["snippet"]["title"].ToString(); d_videos.Add(tmp, title); if (vt == vid_array.Last) s_video_ids += tmp; else s_video_ids += tmp + ","; i++; } num_videos = i; //list video statistics ListVideosByID listVideosByIDChoreo = new ListVideosByID(session); // Set inputs listVideosByIDChoreo.setVideoID(s_video_ids); listVideosByIDChoreo.setPart("statistics"); //loop on videos //tally comments, views, likes, favorites, dislikes string s_statistics = yttb.getTembooData(listVideosByIDChoreo); //listVideosByIDResults.Response; JObject json_statistics = JObject.Parse(s_statistics); for (i = 0; i < num_videos; i++) { string s_video_id = (string)json_statistics["items"][i]["id"]; string s_video_name = d_videos[s_video_id]; int viewCount = int.Parse((string)json_statistics["items"][i]["statistics"]["viewCount"]); int likeCount = int.Parse((string)json_statistics["items"][i]["statistics"]["likeCount"]); int dislikeCount = int.Parse((string)json_statistics["items"][i]["statistics"]["dislikeCount"]); int favoriteCount = int.Parse((string)json_statistics["items"][i]["statistics"]["favoriteCount"]); int commentCount = int.Parse((string)json_statistics["items"][i]["statistics"]["commentCount"]); string country = "Unknown"; amDB.upsertYouTubeCounts(channel_id, s_video_id, s_video_name, viewCount, likeCount, dislikeCount, favoriteCount, 0, commentCount, country); } amDB.youtube_aggregate(); }
public string getVideoTitleById(string video_id) { YTTemboo yttb = new YTTemboo((YouTube)this); ListVideosByID listVideosByIDChoreo = new ListVideosByID(session); // Set inputs listVideosByIDChoreo.setVideoID(video_id); listVideosByIDChoreo.setFields("items/snippet/title"); // Execute Choreo //ListVideosByIDResultSet listVideosByIDResults = listVideosByIDChoreo.execute(); string resultSet = yttb.getTembooData(listVideosByIDChoreo); JObject json_title = JObject.Parse(resultSet); string title = json_title["items"][0]["snippet"]["title"].ToString(); return title; }