Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions components/spotify/actions/search/search.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { ConfigurationError } from "@pipedream/platform";
import spotify from "../../spotify.app.mjs";
import {
ITEM_TYPES_LIST, ITEM_TYPES,
} from "../../consts.mjs";

export default {
key: "spotify-search",
name: "Search",
description: "Search for items on Spotify (tracks, albums, artists, playlists, shows, or episodes). [See the docs here](https://developer.spotify.com/documentation/web-api/reference/search)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
spotify,
query: {
type: "string",
label: "Search Query",
description: "Search query keywords and optional field filters. [See the Spotify docs for query syntax](https://developer.spotify.com/documentation/web-api/reference/search)",
},
type: {
type: "string[]",
label: "Search Type",
description: "Type(s) of items to search for",
options: ITEM_TYPES_LIST,
default: [
ITEM_TYPES.TRACK,
],
},
market: {
propDefinition: [
spotify,
"market",
],
optional: true,
},
limit: {
propDefinition: [
spotify,
"limit",
],
description: "The maximum number of results to return per type.",
default: 20,
max: 50,
},
offset: {
propDefinition: [
spotify,
"offset",
],
},
includeExternal: {
type: "string",
label: "Include External",
description: "If `audio` is specified, the response will include any relevant audio content that is hosted externally.",
optional: true,
options: [
"audio",
],
},
},
async run({ $ }) {
if (!this.query || this.query.trim().length === 0) {
throw new ConfigurationError("Search `query` cannot be empty");
}

if (!this.type) {
throw new ConfigurationError("Select at least one search type");
}

const res = await this.spotify.search({
q: this.query,
type: this.type.join(","),
market: this.market,
limit: this.limit,
offset: this.offset,
include_external: this.includeExternal,
});

$.export("$summary", `Successfully retrieved results matching query: "${this.query}"`);

return res;
},
};
27 changes: 27 additions & 0 deletions components/spotify/consts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@ export const ITEM_TYPES = {
EPISODE: "episode",
};

export const ITEM_TYPES_LIST = [
{
label: "Album",
value: ITEM_TYPES.ALBUM,
},
{
label: "Artist",
value: ITEM_TYPES.ARTIST,
},
{
label: "Playlist",
value: ITEM_TYPES.PLAYLIST,
},
{
label: "Track",
value: ITEM_TYPES.TRACK,
},
{
label: "Show",
value: ITEM_TYPES.SHOW,
},
{
label: "Episode",
value: ITEM_TYPES.EPISODE,
},
];

export const ITEM_TYPES_RESULT_NAME = {
[ITEM_TYPES.ALBUM]: "albums",
[ITEM_TYPES.ARTIST]: "artists",
Expand Down
2 changes: 1 addition & 1 deletion components/spotify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/spotify",
"version": "0.7.3",
"version": "0.7.4",
"description": "Pipedream Spotify Components",
"main": "spotify.app.mjs",
"keywords": [
Expand Down
4 changes: 4 additions & 0 deletions components/spotify/spotify.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ export default {
const { data } = await this._makeRequest("GET", "/recommendations", params);
return data;
},
async search(params) {
const { data } = await this._makeRequest("GET", "/search", params);
return data;
},
async fetchChunksOfAlbumsIds({
artistId,
market,
Expand Down
Loading