public void SearchByLocation(string keyword, int maxResult, int locationRadius, float latitude, float longitude, YoutubeSearchOrderFilter order, YoutubeSafeSearchFilter safeSearch, Action <YoutubeData[]> callback)
 {
     StartCoroutine(YoutubeSearchByLocation(keyword, maxResult, locationRadius, latitude, longitude, order, safeSearch, callback));
 }
 public void SearchForChannels(string keyword, int maxResult, YoutubeSearchOrderFilter order, YoutubeSafeSearchFilter safeSearch, Action <YoutubeChannel[]> callback)
 {
     StartCoroutine(YoutubeSearchChannel(keyword, maxResult, order, safeSearch, callback));
 }
 public void SearchByCategory(string keyword, string category, int maxResult, YoutubeSearchOrderFilter order, YoutubeSafeSearchFilter safeSearch, Action <YoutubeData[]> callback)
 {
     StartCoroutine(YoutubeSearchUsingCategory(keyword, category, maxResult, order, safeSearch, callback));
 }
    IEnumerator YoutubeSearchByLocation(string keyword, int maxResult, int locationRadius, float latitude, float longitude, YoutubeSearchOrderFilter order, YoutubeSafeSearchFilter safeSearch, Action <YoutubeData[]> callback)
    {
        keyword = keyword.Replace(" ", "%20");
        string orderFilter, safeSearchFilter;

        orderFilter = "";
        if (order != YoutubeSearchOrderFilter.none)
        {
            orderFilter = "&order=" + order.ToString();
        }
        safeSearchFilter = "&safeSearch=" + safeSearch.ToString();
        WWW call = new WWW("https://www.googleapis.com/youtube/v3/search/?type=video&q=" + keyword + "&type=video&locationRadius=" + locationRadius + "mi&location=" + latitude + "%2C" + longitude + "&part=snippet,id&maxResults=" + maxResult + "&key=" + APIKey + "" + orderFilter + "" + safeSearchFilter);

        yield return(call);

        Debug.Log(call.url);
        JSONNode result = JSON.Parse(call.text);

        searchResults = new YoutubeData[result["items"].Count];
        Debug.Log(searchResults.Length);
        for (int itemsCounter = 0; itemsCounter < searchResults.Length; itemsCounter++)
        {
            searchResults[itemsCounter]    = new YoutubeData();
            searchResults[itemsCounter].id = result["items"][itemsCounter]["id"]["videoId"];
            SetSnippet(result["items"][itemsCounter]["snippet"], out searchResults[itemsCounter].snippet);
        }
        callback.Invoke(searchResults);
    }
    IEnumerator YoutubeSearchChannel(string keyword, int maxresult, YoutubeSearchOrderFilter order, YoutubeSafeSearchFilter safeSearch, Action <YoutubeChannel[]> callback)
    {
        keyword = keyword.Replace(" ", "%20");

        string orderFilter, safeSearchFilter;

        orderFilter = "";
        if (order != YoutubeSearchOrderFilter.none)
        {
            orderFilter = "&order=" + order.ToString();
        }
        safeSearchFilter = "&safeSearch=" + safeSearch.ToString();


        WWW call = new WWW("https://www.googleapis.com/youtube/v3/search/?q=" + keyword + "&type=channel&maxResults=" + maxresult + "&part=snippet,id&key=" + APIKey + "" + orderFilter + "" + safeSearchFilter);

        yield return(call);

        Debug.Log(call.url);
        JSONNode result = JSON.Parse(call.text);

        channels = new YoutubeChannel[result["items"].Count];
        for (int itemsCounter = 0; itemsCounter < channels.Length; itemsCounter++)
        {
            channels[itemsCounter]             = new YoutubeChannel();
            channels[itemsCounter].id          = result["items"][itemsCounter]["id"]["channelId"];
            channels[itemsCounter].title       = result["items"][itemsCounter]["snippet"]["title"];
            channels[itemsCounter].description = result["items"][itemsCounter]["snippet"]["description"];
            channels[itemsCounter].thumbnail   = result["items"][itemsCounter]["snippet"]["thumbnails"]["high"]["url"];
        }
        callback.Invoke(channels);
    }
 public void Search(string keyword, int maxResult, YoutubeSearchOrderFilter order, YoutubeSafeSearchFilter safeSearch, string customFilters, Action <YoutubeData[]> callback)
 {
     StartCoroutine(YoutubeSearch(keyword, maxResult, order, safeSearch, customFilters, callback));
 }
    IEnumerator YoutubeSearch(string keyword, int maxresult, YoutubeSearchOrderFilter order, YoutubeSafeSearchFilter safeSearch, string customFilters, Action <YoutubeData[]> callback)
    {
        keyword = keyword.Replace(" ", "%20");

        string orderFilter, safeSearchFilter;

        orderFilter = "";
        if (order != YoutubeSearchOrderFilter.none)
        {
            orderFilter = "&order=" + order.ToString();
        }
        safeSearchFilter = "&safeSearch=" + safeSearch.ToString();

        string newurl = WWW.EscapeURL("https://www.googleapis.com/youtube/v3/search/?q=" + keyword + "&type=video&maxResults=" + maxresult + "&part=snippet,id&key=" + APIKey + "" + orderFilter + "" + safeSearchFilter + "" + customFilters);

        Debug.Log(newurl);
        WWW call = new WWW(WWW.UnEscapeURL(newurl));

        yield return(call);

        Debug.Log(call.url);
        JSONNode result = JSON.Parse(call.text);

        searchResults = new YoutubeData[result["items"].Count];
        Debug.Log(searchResults.Length);
        for (int itemsCounter = 0; itemsCounter < searchResults.Length; itemsCounter++)
        {
            searchResults[itemsCounter]    = new YoutubeData();
            searchResults[itemsCounter].id = result["items"][itemsCounter]["id"]["videoId"];
            SetSnippet(result["items"][itemsCounter]["snippet"], out searchResults[itemsCounter].snippet);
        }
        callback.Invoke(searchResults);
    }
    IEnumerator YoutubeSearchUsingCategory(string keyword, string category, int maxresult, YoutubeSearchOrderFilter order, YoutubeSafeSearchFilter safeSearch, Action <YoutubeData[]> callback)
    {
        keyword  = keyword.Replace(" ", "%20");
        category = category.Replace(" ", "%20");

        string orderFilter, safeSearchFilter;

        orderFilter = "";
        if (order != YoutubeSearchOrderFilter.none)
        {
            orderFilter = "&order=" + order.ToString();
        }
        safeSearchFilter = "&safeSearch=" + safeSearch.ToString();

        UnityWebRequest request = UnityWebRequest.Get("https://www.googleapis.com/youtube/v3/search/?q=" + keyword + "&videoCategoryId=" + category + "&maxResults=" + maxresult + "&type=video&part=snippet,id&key=" + APIKey + "" + orderFilter + "" + safeSearchFilter);

        yield return(request.SendWebRequest());

        Debug.Log(request.url);
        JSONNode result = JSON.Parse(request.downloadHandler.text);

        searchResults = new YoutubeData[result["items"].Count];
        Debug.Log(searchResults.Length);
        for (int itemsCounter = 0; itemsCounter < searchResults.Length; itemsCounter++)
        {
            searchResults[itemsCounter]    = new YoutubeData();
            searchResults[itemsCounter].id = result["items"][itemsCounter]["id"]["videoId"];
            SetSnippet(result["items"][itemsCounter]["snippet"], out searchResults[itemsCounter].snippet);
        }
        callback.Invoke(searchResults);
    }