private string getUserID(string title) { string json = HTTP.GET("https://www.googleapis.com/youtube/v3/channels?part=snippet&forUsername="******"&fields=items%2Fid&key=AIzaSyAa33VM7zG0hnceZEEGdroB6DerP8fRJ6o"); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); var result = jsSerializer.DeserializeObject(json); Dictionary <string, object> obj2 = new Dictionary <string, object>(); obj2 = (Dictionary <string, object>)(result); System.Object[] val = (System.Object[])obj2["items"]; string response = null; try { Dictionary <string, object> id = (Dictionary <string, object>)val.GetValue(0); response = id["id"].ToString(); } catch { MessageBox.Show("Wystąpił jakiś błąd, lub link do kanału jest niepoprawny", "Powerful YouTube DL", MessageBoxButton.OK, MessageBoxImage.Error); } return(response); }
public static void getParamsOfVideos() { //string IDs = ""; List <string> IDs = new List <string>(); IDs.Add(""); int ktoryJuz = 0; for (int i = 0; i < videoIDsToGetParams.Count; i++) { int index = IDs.Count - 1; if (ktoryJuz == 0) { IDs[index] = videoIDsToGetParams[i].videoID; } else { IDs[index] += @"%2C" + videoIDsToGetParams[i].videoID; } ktoryJuz++; if (ktoryJuz == 50) { IDs.Add(""); ktoryJuz = 0; } } for (int j = 0; j < IDs.Count; j++) { string json = HTTP.GET("https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails&id=" + IDs[j] + "&fields=items(contentDetails%2Fduration%2Cid%2Csnippet%2Ftitle)&key=AIzaSyAa33VM7zG0hnceZEEGdroB6DerP8fRJ6o"); JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); var result = jsSerializer.DeserializeObject(json); Dictionary <string, object> obj2 = new Dictionary <string, object>(); obj2 = (Dictionary <string, object>)(result); System.Object[] val = (System.Object[])obj2["items"]; for (int i = 0; i < val.Length; i++) { int current = -1; int current2 = -1; Dictionary <string, object> vid = (Dictionary <string, object>)val[i]; string id = vid["id"].ToString(); for (int d = 0; d < _listOfVideos.Count; d++) { if (_listOfVideos[d].videoID == id) { current = d; break; } } for (int d = 0; d < videoIDsToGetParams.Count; d++) { if (videoIDsToGetParams[d].videoID == id) { current2 = d; break; } } Dictionary <string, object> temp = (Dictionary <string, object>)vid["snippet"]; Dictionary <string, object> temp2 = (Dictionary <string, object>)vid["contentDetails"]; videoIDsToGetParams[current2].videoTitle = temp["title"].ToString(); _listOfVideos[current].videoTitle = temp["title"].ToString(); _listOfVideos[current].videoDuration = decryptDuration(temp2["duration"].ToString()); if (_listOfVideos[current].position == null) { _listOfVideos[current].position = new ListViewItemMy { title = _listOfVideos[current].position.title , duration = _listOfVideos[current].position.duration , status = "---" }; } _listOfVideos[current].position.title = _listOfVideos[current].videoTitle; _listOfVideos[current].position.duration = _listOfVideos[current].videoDuration; } } removeNotWorkingVideos(); }