File tree 3 files changed +60
-0
lines changed
3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 8
8
PlaySpecificList ,
9
9
PlaySpecificTracks ,
10
10
PreviousSong ,
11
+ QueueItem ,
11
12
SeekPosition ,
12
13
SkipSong ,
13
14
TransferPlayback ,
@@ -20,6 +21,7 @@ export enum ActionId {
20
21
PlaySpecificList = 'playSpecificList' ,
21
22
PlaySpecificTracks = 'playSpecificTracks' ,
22
23
Pause = 'pause' ,
24
+ QueueItem = 'queueItem' ,
23
25
VolumeUp = 'volumeUp' ,
24
26
VolumeDown = 'volumeDown' ,
25
27
VolumeSpecific = 'volumeSpecific' ,
@@ -347,6 +349,29 @@ export function GetActionsList(executeAction: (fcn: DoAction) => Promise<void>):
347
349
} )
348
350
} ,
349
351
} ,
352
+ [ ActionId . QueueItem ] : {
353
+ name : 'Add Track to Queue' ,
354
+ options : [
355
+ {
356
+ tooltip : 'Provide the ID for the track' ,
357
+ required : true ,
358
+ type : 'textinput' ,
359
+ label : 'Track ID' ,
360
+ id : 'context_uri' ,
361
+ useVariables : true ,
362
+ } ,
363
+ ] ,
364
+ callback : async ( action , context ) => {
365
+ if ( typeof action . options . context_uri === 'string' ) {
366
+ const context_uri_portion = await context . parseVariablesInString ( String ( action . options . context_uri ) )
367
+ const context_uri = `spotify:track:${ context_uri_portion } `
368
+
369
+ await executeAction ( async ( instance , deviceId ) => {
370
+ if ( deviceId ) await QueueItem ( instance , deviceId , context_uri )
371
+ } )
372
+ }
373
+ } ,
374
+ } ,
350
375
}
351
376
352
377
return actions
Original file line number Diff line number Diff line change @@ -9,6 +9,19 @@ import {
9
9
BodyParameters ,
10
10
} from './util.js'
11
11
12
+ export async function addItemToQueue (
13
+ reqOptions : RequestOptionsBase ,
14
+ context_uri : string ,
15
+ options ?: DeviceOptions ,
16
+ ) : Promise < Response < void > > {
17
+ const params : QueryParameters = {
18
+ uri : context_uri ,
19
+ }
20
+ if ( options && 'deviceId' in options ) params . device_id = options . deviceId
21
+
22
+ return doPostRequest ( reqOptions , '/v1/me/player/queue' , params )
23
+ }
24
+
12
25
export async function getMyCurrentPlaybackState (
13
26
reqOptions : RequestOptionsBase ,
14
27
) : Promise < Response < SpotifyApi . CurrentPlaybackResponse | undefined > > {
Original file line number Diff line number Diff line change 1
1
import { getMyDevices , setVolume } from './api/device.js'
2
2
import {
3
+ addItemToQueue ,
3
4
getMyCurrentPlaybackState ,
4
5
pause ,
5
6
play ,
@@ -53,6 +54,27 @@ export async function ChangeVolume(
53
54
}
54
55
}
55
56
57
+ export async function QueueItem (
58
+ instance : SpotifyInstanceBase ,
59
+ deviceId : string ,
60
+ context_uri : string ,
61
+ attempt = 0 ,
62
+ ) : Promise < void > {
63
+ const reqOptions = instance . getRequestOptionsBase ( )
64
+ if ( ! reqOptions ) return
65
+
66
+ try {
67
+ await addItemToQueue ( reqOptions , context_uri , { deviceId } )
68
+ } catch ( err ) {
69
+ const retry = await instance . checkIfApiErrorShouldRetry ( err )
70
+ if ( retry && attempt <= MAX_ATTEMPTS ) {
71
+ return QueueItem ( instance , deviceId , context_uri , attempt + 1 )
72
+ } else {
73
+ throw err
74
+ }
75
+ }
76
+ }
77
+
56
78
export async function SkipSong ( instance : SpotifyInstanceBase , deviceId : string , attempt = 0 ) : Promise < void > {
57
79
const reqOptions = instance . getRequestOptionsBase ( )
58
80
if ( ! reqOptions ) return
You can’t perform that action at this time.
0 commit comments