private void getPlayListVideos(string json) { 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"]; foreach (object item in val) { licznik++; Dictionary <string, object> vid = (Dictionary <string, object>)item; Dictionary <string, object> temp = (Dictionary <string, object>)vid["snippet"]; string title = temp["title"].ToString(); // resourceId -> videoId Dictionary <string, object> vid2 = (Dictionary <string, object>)temp["resourceId"]; string id = vid2["videoId"].ToString(); Video toAdd = new Video(id); toAdd.playList._listOfVideosInPlayList.Remove(toAdd); toAdd.playList = this; _listOfVideosInPlayList.Add(toAdd); } try { string nextPage = obj2["nextPageToken"].ToString(); getPlayListVideos(HTTP.GET("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&pageToken=" + nextPage + "&playlistId=" + playListID + "&fields=items(snippet(resourceId%2FvideoId%2Ctitle))%2CnextPageToken&key=AIzaSyAa33VM7zG0hnceZEEGdroB6DerP8fRJ6o")); } catch { } }
public PlayList(string link) { string id = link.Substring(link.IndexOf("list=") + 5, 34); //34 playListID = id; bool isPlayListExisting = false; foreach (PlayList exists in _listOfPlayLists) { if (exists.playListID == playListID) { isPlayListExisting = true; break; } } if (!isPlayListExisting) { playListURL = link; playListTitle = getTitle(id); check = new CheckBox(); check.Click += new RoutedEventHandler(checkChanged); check.Content = playListTitle; getPlayListVideos(HTTP.GET("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=" + playListID + "&fields=items(snippet(resourceId%2FvideoId%2Ctitle))%2CnextPageToken&key=AIzaSyAa33VM7zG0hnceZEEGdroB6DerP8fRJ6o")); _listOfPlayListsCheckBox.Add(check); _listOfPlayLists.Add(this); // if (((MainWindow)System.Windows.Application.Current.MainWindow).playlist.SelectedIndex == -1) ((MainWindow)System.Windows.Application.Current.MainWindow).playlist.SelectedItem = check; } else { MainWindow.Error("Ta playlista jest już dodana!"); } }
private void getUserPlayLists(string json) { 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"]; foreach (object item in val) { Dictionary <string, object> vid = (Dictionary <string, object>)item; Dictionary <string, object> temp = (Dictionary <string, object>)vid["snippet"]; string playlistid = vid["id"].ToString(); string playlistTitle = temp["title"].ToString(); PlayList toAdd = new PlayList(playlistid, playlistTitle); } try { string nextPage = obj2["nextPageToken"].ToString(); getUserPlayLists(HTTP.GET("https://www.googleapis.com/youtube/v3/playlists?part=snippet&" + userID + "&maxResults=50&pageToken=" + nextPage + "&fields=items(id%2Csnippet%2Ftitle)&key=AIzaSyAa33VM7zG0hnceZEEGdroB6DerP8fRJ6o")); } catch { } }
private string getTitle(string id) { string html = HTTP.GET("https://www.youtube.com/playlist?list=" + id); int start = html.IndexOf("<title>") + 7; int end = html.IndexOf(@" - YouTube</title>") - start; return(html.Substring(start, end)); }
public PlayList(string id, string title) { playListID = id; playListTitle = title; check = new CheckBox(); check.Click += new RoutedEventHandler(checkChanged); check.Content = playListTitle; getPlayListVideos(HTTP.GET("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=" + playListID + "&fields=items(snippet(resourceId%2FvideoId%2Ctitle))%2CnextPageToken&key=AIzaSyAa33VM7zG0hnceZEEGdroB6DerP8fRJ6o")); _listOfPlayListsCheckBox.Add(check); _listOfPlayLists.Add(this); // if (((MainWindow)System.Windows.Application.Current.MainWindow).playlist.SelectedIndex == -1) ((MainWindow)System.Windows.Application.Current.MainWindow).playlist.SelectedItem = check; }
public User(string link, int status) //(status) 0 - playlisty 1 - dodane { string id = ""; if (link.Contains("/channel/")) { int start = link.IndexOf("nnel/") + 5; int finish = link.Substring(start).IndexOf("?"); if (finish > 0) { userID = link.Substring(start, finish); } else { userID = link.Substring(start); } id = "id=" + userID; } else { string title; int start = link.IndexOf("user/") + 5; int finish = link.Substring(start).IndexOf("/"); if (finish > 0) { title = link.Substring(start, finish); } else { title = link.Substring(start); } id = "forUsername="******"https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=" + userID + "&maxResults=50&fields=items(id%2Csnippet%2Ftitle)&key=AIzaSyAa33VM7zG0hnceZEEGdroB6DerP8fRJ6o"; string ResponseYouTubeAPI = HTTP.GET(zapytanie); getUserPlayLists(ResponseYouTubeAPI); } else if (status == 1) { string ResponseYouTubeAPI = HTTP.GET("https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails&" + id + "&maxResults=50&fields=items(contentDetails%2FrelatedPlaylists%2Fuploads%2Cid%2Csnippet%2Ftitle)%2CnextPageToken%2CpageInfo&key=AIzaSyAa33VM7zG0hnceZEEGdroB6DerP8fRJ6o"); getUserUploadedVideos(ResponseYouTubeAPI); } }
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(); }