Edits history of script submission #20422 for ' Search for tracks (shutterstock)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Shutterstock = {
      token: string;
    };
    /**
     * Search for tracks
     * This endpoint searches for tracks. If you specify more than one search parameter, the API uses an AND condition. Array parameters can be specified multiple times; in this case, the API uses an AND or an OR condition with those values, depending on the parameter.
     */
    export async function main(
      auth: Shutterstock,
      artists: string | undefined,
      bpm: string | undefined,
      bpm_from: string | undefined,
      bpm_to: string | undefined,
      duration: string | undefined,
      duration_from: string | undefined,
      duration_to: string | undefined,
      genre: string | undefined,
      is_instrumental: string | undefined,
      instruments: string | undefined,
      moods: string | undefined,
      page: string | undefined,
      per_page: string | undefined,
      query: string | undefined,
      sort:
        | "score"
        | "ranking_all"
        | "artist"
        | "title"
        | "bpm"
        | "freshness"
        | "duration"
        | undefined,
      sort_order: "asc" | "desc" | undefined,
      vocal_description: string | undefined,
      view: "minimal" | "full" | undefined,
      fields: string | undefined,
      library: "shutterstock" | "premier" | undefined,
      language: string | undefined,
    ) {
      const url = new URL(`https://api.shutterstock.com/v2/audio/search`);
      for (const [k, v] of [
        ["artists", artists],
        ["bpm", bpm],
        ["bpm_from", bpm_from],
        ["bpm_to", bpm_to],
        ["duration", duration],
        ["duration_from", duration_from],
        ["duration_to", duration_to],
        ["genre", genre],
        ["is_instrumental", is_instrumental],
        ["instruments", instruments],
        ["moods", moods],
        ["page", page],
        ["per_page", per_page],
        ["query", query],
        ["sort", sort],
        ["sort_order", sort_order],
        ["vocal_description", vocal_description],
        ["view", view],
        ["fields", fields],
        ["library", library],
        ["language", language],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago