Compare commits

...

1 Commits

Author SHA1 Message Date
Ian Wijma 0641921fec Volume up and down 2023-11-18 01:18:52 +11:00
4 changed files with 107 additions and 1 deletions

View File

@ -5,7 +5,7 @@ const {nanoid} = require("nanoid");
const express = require('express') const express = require('express')
const {spotify, spotifyCredentialsFile, hasSpotifyCredentials, saveSpotifyCredentials} = require("../utilities/spotify"); const {spotify, spotifyCredentialsFile, hasSpotifyCredentials, saveSpotifyCredentials} = require("../utilities/spotify");
exports.command = 'authenticate' exports.command = ['authenticate', 'auth']
exports.description = 'starts the Spotity authentication process' exports.description = 'starts the Spotity authentication process'
exports.builder = (argv) => argv exports.builder = (argv) => argv
.option('client-id', { .option('client-id', {

View File

@ -0,0 +1,17 @@
const { spotify} = require('../utilities/spotify')
exports.command = 'volume-down'
exports.handler = async () => {
try {
await spotify.ensure();
const { body } = await spotify.getMyCurrentPlaybackState();
const { device = {} } = body
const { supports_volume = false, volume_percent = 100 } = device;
if (supports_volume) {
await spotify.setVolume(Math.min(Math.max(volume_percent - 10, 0), 100));
}
} catch (e) {
console.error(e.message);
}
};

17
src/commands/volumeUp.js Normal file
View File

@ -0,0 +1,17 @@
const { spotify} = require('../utilities/spotify')
exports.command = 'volume-up'
exports.handler = async () => {
try {
await spotify.ensure();
const { body } = await spotify.getMyCurrentPlaybackState();
const { device = {} } = body
const { supports_volume = false, volume_percent = 100 } = device;
if (supports_volume) {
await spotify.setVolume(Math.min(Math.max(volume_percent + 10, 0), 100));
}
} catch (e) {
console.error(e.message);
}
};

72
tmp/state-data Normal file
View File

@ -0,0 +1,72 @@
{
device: {
id: 'acc9f0df86034061b5d026e606ea1a6976f09298',
is_active: true,
is_private_session: false,
is_restricted: false,
name: 'pop-os',
supports_volume: true,
type: 'Computer',
volume_percent: 46
},
shuffle_state: true,
repeat_state: 'off',
timestamp: 1700230542949,
context: {
external_urls: { spotify: 'https://open.spotify.com/collection/tracks' },
href: 'https://api.spotify.com/v1/me/tracks',
type: 'collection',
uri: 'spotify:user:1150564340:collection'
},
progress_ms: 96296,
item: {
album: {
album_type: 'single',
artists: [Array],
available_markets: [Array],
external_urls: [Object],
href: 'https://api.spotify.com/v1/albums/57d2Ti8vswyMFDpz4xauZw',
id: '57d2Ti8vswyMFDpz4xauZw',
images: [Array],
name: 'Wall Of Bass',
release_date: '2018-04-13',
release_date_precision: 'day',
total_tracks: 1,
type: 'album',
uri: 'spotify:album:57d2Ti8vswyMFDpz4xauZw'
},
artists: [ [Object], [Object] ],
available_markets: [
'AR', 'AU', 'AT', 'BE', 'BO', 'BR', 'BG', 'CA', 'CL', 'CO',
'CR', 'CY', 'CZ', 'DK', 'DO', 'DE', 'EC', 'EE', 'SV', 'FI',
'FR', 'GR', 'GT', 'HN', 'HK', 'HU', 'IS', 'IE', 'IT', 'LV',
'LT', 'LU', 'MY', 'MT', 'MX', 'NL', 'NZ', 'NI', 'NO', 'PA',
'PY', 'PE', 'PH', 'PL', 'PT', 'SG', 'SK', 'ES', 'SE', 'CH',
'TW', 'TR', 'UY', 'US', 'GB', 'AD', 'LI', 'MC', 'ID', 'JP',
'TH', 'VN', 'RO', 'IL', 'ZA', 'SA', 'AE', 'BH', 'QA', 'OM',
'KW', 'EG', 'MA', 'DZ', 'TN', 'LB', 'JO', 'PS', 'IN', 'BY',
'KZ', 'MD', 'UA', 'AL', 'BA', 'HR', 'ME', 'MK', 'RS', 'SI',
'KR', 'BD', 'PK', 'LK', 'GH', 'KE', 'NG', 'TZ', 'UG', 'AG',
... 84 more items
],
disc_number: 1,
duration_ms: 264736,
explicit: true,
external_ids: { isrc: 'NLQS91800057' },
external_urls: {
spotify: 'https://open.spotify.com/track/6MM8Rkumhy4RguXgtHCVk3'
},
href: 'https://api.spotify.com/v1/tracks/6MM8Rkumhy4RguXgtHCVk3',
id: '6MM8Rkumhy4RguXgtHCVk3',
is_local: false,
name: 'Wall Of Bass',
popularity: 37,
preview_url: 'https://p.scdn.co/mp3-preview/7c27853ef9f45167de007e32a3ad39750c90ba4e?cid=0974061c80f44d3b9a3bc9b6b42b5820',
track_number: 1,
type: 'track',
uri: 'spotify:track:6MM8Rkumhy4RguXgtHCVk3'
},
currently_playing_type: 'track',
actions: { disallows: { resuming: true } },
is_playing: true
}