Skip to content

Commit 0856ae7

Browse files
STalukder20michelle0927
authored andcommitted
[Action] Spotify - Get currently playing track (#14625)
* Fix two broken links in docs * Spotify action component to retrieve currently playing track for user. * Set action version to 0.0.1 * Added support for action to retrive currently playing podcast episodes. * Undo unrelated change. * Added error handling, response is now structured, and formatting fixes. * Set action version to 0.0.1 * Fixed typo * package version, doc link, formatting * pnpm-lock.yaml * lodash dependency * pnpm-lock.yaml --------- Co-authored-by: michelle0927 <[email protected]>
1 parent f8f94de commit 0856ae7

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { axios } from "@pipedream/platform";
2+
import spotify from "../../spotify.app.mjs";
3+
import { ITEM_TYPES } from "../../consts.mjs";
4+
5+
export default {
6+
name: "Get currently playing track",
7+
description:
8+
"Get the object currently being played on the user's Spotify account. [See the documentation](https://developer.spotify.com/documentation/web-api/reference/get-the-users-currently-playing-track)",
9+
key: "spotify-get-currently-playing-track",
10+
version: "0.0.1",
11+
type: "action",
12+
props: {
13+
spotify,
14+
market: {
15+
propDefinition: [
16+
spotify,
17+
"market",
18+
],
19+
optional: true,
20+
},
21+
},
22+
async run({ $ }) {
23+
const { market } = this;
24+
25+
try {
26+
const res = await axios(
27+
$,
28+
this.spotify._getAxiosParams({
29+
method: "GET",
30+
path: "/me/player/currently-playing",
31+
params: {
32+
market,
33+
additional_types: [
34+
ITEM_TYPES.TRACK,
35+
ITEM_TYPES.EPISODE,
36+
].join(","),
37+
},
38+
}),
39+
);
40+
41+
const itemType = res?.currently_playing_type || "track";
42+
const itemName = res?.item?.name || "Nothing";
43+
$.export("$summary", `Currently playing ${itemType}: ${itemName}`);
44+
45+
return {
46+
playing: !!res,
47+
type: res?.currently_playing_type,
48+
item: res?.item,
49+
progress_ms: res?.progress_ms,
50+
is_playing: res?.is_playing,
51+
};
52+
} catch (error) {
53+
throw new Error(`Failed to get currently playing track for user: ${error.message}`);
54+
}
55+
},
56+
};

components/spotify/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/spotify",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "Pipedream Spotify Components",
55
"main": "spotify.app.js",
66
"keywords": [
@@ -14,6 +14,7 @@
1414
"access": "public"
1515
},
1616
"dependencies": {
17-
"@pipedream/platform": "^1.4.0"
17+
"@pipedream/platform": "^3.0.3",
18+
"lodash": "^4.17.21"
1819
}
1920
}

pnpm-lock.yaml

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)