public void YoutubePlaylistSearch(string keyword, string pageToken) { string url = "https://www.googleapis.com/youtube/v3/search?part=snippet&type=playlist&q=" + keyword + "&maxResults=" + maxResults + "&pageToken=" + pageToken + "&key=" + YOUTUBE_API_KEY; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string result = reader.ReadToEnd(); stream.Close(); response.Close(); JObject parsedResult = JObject.Parse(result); JArray items = (JArray)parsedResult["items"]; ArrayList dataList = new ArrayList(); String token = null; try { token = parsedResult["nextPageToken"].ToString(); } catch (Exception ex) { token = NOT_NEXT_TOKEN; } foreach (JObject resultOne in items) { try { SearchPlaylistModel searchPlaylistModel = new SearchPlaylistModel { id = resultOne["id"]["playlistId"].ToString(), title = resultOne["snippet"]["title"].ToString(), thumbnail = resultOne["snippet"]["thumbnails"]["default"]["url"].ToString(), size = YoutubePlaylistSize(resultOne["id"]["playlistId"].ToString()), type = YOUTUBE_TYPE }; dataList.Add(searchPlaylistModel); } catch (Exception e) { } } Context.Response.ContentType = "application/json; charset=utf-8"; Context.Response.Write(RESULT_FIRST_STRING + RESULT_NEXT_TOKEN_STRING + "\"" + token + "\"," + RESULT_LIST_STRING + JsonConvert.SerializeObject(dataList) + RESULT_LAST_STRING); //return RESULT_FIRST_STRING + JsonConvert.SerializeObject(dataList) + RESULT_LAST_STRING; } catch (Exception ex) { Context.Response.ContentType = "application/json; charset=utf-8"; Context.Response.Write(FAIL_STRING); //return RESULT_FIRST_STRING + JsonConvert.SerializeObject(dataList) + RESULT_LAST_STRING; } }
public SearchViewModel() { SearchTracks = new SearchTrackModel(); FanburstTracks = new FanburstSearchModel(); SearchPlaylists = new SearchPlaylistModel(); SearchUsers = new SearchUserModel(); YouTubeTracks = new YouTubeSearchModel(); }
public void SoundcloudPlaylistSearch(string keyword, int index) { string url = "https://api.soundcloud.com/playlists.json?client_id=" + SOUNDCLOUD_CLIENT_KEY + "&q= " + keyword + "&limit=" + maxResults + "&offset=" + ((index - 1) * maxResults); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string result = reader.ReadToEnd(); stream.Close(); response.Close(); JArray items = JArray.Parse(result); ArrayList dataList = new ArrayList(); foreach (JObject resultOne in items) { try { SearchPlaylistModel searchPlaylistModel = new SearchPlaylistModel { id = resultOne["id"].ToString(), title = resultOne["title"].ToString(), thumbnail = resultOne["tracks"][0]["artwork_url"].ToString(), size = resultOne["track_count"].ToString(), type = SOUND_CLOUD_TYPE }; dataList.Add(searchPlaylistModel); } catch (Exception e) { } } Context.Response.ContentType = "application/json; charset=utf-8"; Context.Response.Write(RESULT_FIRST_STRING + RESULT_NEXT_TOKEN_STRING + "\"" + (index + 1) + "\"," + RESULT_LIST_STRING + JsonConvert.SerializeObject(dataList) + RESULT_LAST_STRING); //return RESULT_FIRST_STRING + JsonConvert.SerializeObject(dataList) + RESULT_LAST_STRING; } catch (Exception ex) { Context.Response.ContentType = "application/json; charset=utf-8"; Context.Response.Write(FAIL_STRING); //return RESULT_FIRST_STRING + JsonConvert.SerializeObject(dataList) + RESULT_LAST_STRING; } }
public string YoutubePlaylistSearch(string keyword, int index) { string url = "https://gdata.youtube.com/feeds/api/playlists/snippets?&q=" + keyword + "&max-results=" + maxResults + "&alt=jsonc&v=2&start-index=" + (((index - 1) * maxResults) + 1); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string result = reader.ReadToEnd(); stream.Close(); response.Close(); JObject parsedResult = JObject.Parse(result); JArray items = (JArray)parsedResult["data"]["items"]; ArrayList dataList = new ArrayList(); foreach (JObject resultOne in items) { try { SearchPlaylistModel searchPlaylistModel = new SearchPlaylistModel { id = resultOne["id"].ToString(), title = resultOne["title"].ToString(), thumbnail = resultOne["thumbnail"]["sqDefault"].ToString(), size = resultOne["size"].ToString(), type = YOUTUBE_TYPE }; dataList.Add(searchPlaylistModel); } catch (Exception e) { } } return(RESULT_FIRST_STRING + JsonConvert.SerializeObject(dataList) + RESULT_LAST_STRING); } catch (Exception ex) { return(FAIL_STRING); } }