@bzenky/spoti 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -13
- package/dist/app.d.ts +2 -4
- package/dist/app.js +119 -76
- package/dist/app.js.map +1 -1
- package/dist/services/catalog.service.d.ts +2 -0
- package/dist/services/catalog.service.js +29 -4
- package/dist/services/catalog.service.js.map +1 -1
- package/dist/services/library.service.d.ts +2 -0
- package/dist/services/library.service.js +16 -2
- package/dist/services/library.service.js.map +1 -1
- package/dist/services/pagination.d.ts +20 -0
- package/dist/services/pagination.js +11 -0
- package/dist/services/pagination.js.map +1 -0
- package/dist/services/player.service.d.ts +1 -0
- package/dist/services/player.service.js +10 -7
- package/dist/services/player.service.js.map +1 -1
- package/dist/services/playlist.service.d.ts +4 -0
- package/dist/services/playlist.service.js +26 -14
- package/dist/services/playlist.service.js.map +1 -1
- package/dist/services/recent.service.d.ts +2 -0
- package/dist/services/recent.service.js +52 -2
- package/dist/services/recent.service.js.map +1 -1
- package/dist/spotify/client.js +9 -4
- package/dist/spotify/client.js.map +1 -1
- package/dist/ui/completions.js +23 -16
- package/dist/ui/completions.js.map +1 -1
- package/dist/ui/pagination.d.ts +30 -0
- package/dist/ui/pagination.js +72 -0
- package/dist/ui/pagination.js.map +1 -0
- package/dist/ui/prompts.d.ts +17 -8
- package/dist/ui/prompts.js +57 -35
- package/dist/ui/prompts.js.map +1 -1
- package/dist/utils/errors.js +15 -2
- package/dist/utils/errors.js.map +1 -1
- package/package.json +1 -1
package/dist/ui/completions.js
CHANGED
|
@@ -4,7 +4,7 @@ _spoti_completion() {
|
|
|
4
4
|
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
5
5
|
command="\${COMP_WORDS[1]}"
|
|
6
6
|
|
|
7
|
-
local commands="setup login logout status config interactive now pause resume next previous devices device seek volume queue shuffle repeat album artist playlists playlist liked like unlike recent update search play completion i p pa r np q s vol dev devs pl pls rep rec n prev"
|
|
7
|
+
local commands="setup login logout status config interactive now pause resume next previous devices device seek volume queue shuffle repeat album artist playlists playlist liked like unlike recent update search play completion i p pa r np q s vol dev devs pl pls rep rec n prev sk alb art"
|
|
8
8
|
local global_options="-h --help -V --version"
|
|
9
9
|
|
|
10
10
|
if (( COMP_CWORD == 1 )); then
|
|
@@ -28,7 +28,7 @@ _spoti_completion() {
|
|
|
28
28
|
now|np)
|
|
29
29
|
COMPREPLY=( $(compgen -W "-w --watch -h --help" -- "$cur") )
|
|
30
30
|
;;
|
|
31
|
-
queue|q|album|artist|playlist|pl)
|
|
31
|
+
queue|q|album|alb|artist|art|playlist|pl)
|
|
32
32
|
COMPREPLY=( $(compgen -W "--first -h --help" -- "$cur") )
|
|
33
33
|
;;
|
|
34
34
|
playlists|pls|liked|recent|rec|search|s)
|
|
@@ -75,18 +75,21 @@ _spoti() {
|
|
|
75
75
|
'devices:list available Spotify Connect devices'
|
|
76
76
|
'device:transfer playback to a Spotify Connect device'
|
|
77
77
|
'seek:seek within the current track'
|
|
78
|
-
'
|
|
78
|
+
'sk:alias for seek'
|
|
79
|
+
'volume:show, set, or adjust the active device volume'
|
|
79
80
|
'queue:show the playback queue or add a searched track'
|
|
80
81
|
'shuffle:show or change the playback shuffle state'
|
|
81
82
|
'repeat:show or change the playback repeat mode'
|
|
82
83
|
'album:search for and show an album'
|
|
84
|
+
'alb:alias for album'
|
|
83
85
|
'artist:search for and show an artist'
|
|
84
|
-
'
|
|
86
|
+
'art:alias for artist'
|
|
87
|
+
'playlists:browse and optionally play your Spotify playlists'
|
|
85
88
|
'playlist:show one of your Spotify playlists'
|
|
86
|
-
'liked:
|
|
89
|
+
'liked:browse and optionally play your liked tracks'
|
|
87
90
|
'like:add the current track to your Spotify library'
|
|
88
91
|
'unlike:remove the current track from your Spotify library'
|
|
89
|
-
'recent:
|
|
92
|
+
'recent:browse and optionally play recently played tracks'
|
|
90
93
|
'update:check for or install the latest spoti version'
|
|
91
94
|
'search:search Spotify tracks'
|
|
92
95
|
'play:play a track, album, artist, or playlist'
|
|
@@ -142,10 +145,13 @@ _spoti() {
|
|
|
142
145
|
now|np)
|
|
143
146
|
_arguments '(-w --watch)'{-w,--watch}'[continuously refresh playback information]'
|
|
144
147
|
;;
|
|
145
|
-
queue|q|album|artist|playlist|pl)
|
|
148
|
+
queue|q|album|alb|artist|art|playlist|pl)
|
|
146
149
|
_arguments '--first[select the first result without prompting]' '*:query:'
|
|
147
150
|
;;
|
|
148
|
-
playlists|pls|liked|recent|rec
|
|
151
|
+
playlists|pls|liked|recent|rec)
|
|
152
|
+
_arguments '(-l --limit)'{-l,--limit}'[number of items per page]:number:'
|
|
153
|
+
;;
|
|
154
|
+
search|s)
|
|
149
155
|
_arguments '(-l --limit)'{-l,--limit}'[maximum number of results]:number:' '*:query:'
|
|
150
156
|
;;
|
|
151
157
|
update)
|
|
@@ -173,7 +179,7 @@ complete -c spoti -s h -l help -d 'Display help'
|
|
|
173
179
|
complete -c spoti -s V -l version -d 'Display version'
|
|
174
180
|
|
|
175
181
|
function __spoti_needs_command
|
|
176
|
-
not __fish_seen_subcommand_from setup login logout status config interactive now pause resume next previous devices device seek volume queue shuffle repeat album artist playlists playlist liked like unlike recent update search play completion i p pa r np q s vol dev devs pl pls rep rec n prev
|
|
182
|
+
not __fish_seen_subcommand_from setup login logout status config interactive now pause resume next previous devices device seek volume queue shuffle repeat album artist playlists playlist liked like unlike recent update search play completion i p pa r np q s vol dev devs pl pls rep rec n prev sk alb art
|
|
177
183
|
end
|
|
178
184
|
complete -c spoti -n __spoti_needs_command -a setup -d 'Save your Spotify application client ID'
|
|
179
185
|
complete -c spoti -n __spoti_needs_command -a login -d 'Log in to Spotify'
|
|
@@ -189,30 +195,31 @@ complete -c spoti -n __spoti_needs_command -a previous -d 'Return to the previou
|
|
|
189
195
|
complete -c spoti -n __spoti_needs_command -a devices -d 'List Spotify Connect devices'
|
|
190
196
|
complete -c spoti -n __spoti_needs_command -a device -d 'Transfer playback to a device'
|
|
191
197
|
complete -c spoti -n __spoti_needs_command -a seek -d 'Seek within the current track'
|
|
192
|
-
complete -c spoti -n __spoti_needs_command -a volume -d '
|
|
198
|
+
complete -c spoti -n __spoti_needs_command -a volume -d 'Show, set, or adjust volume'
|
|
193
199
|
complete -c spoti -n __spoti_needs_command -a queue -d 'Show or add to the queue'
|
|
194
200
|
complete -c spoti -n __spoti_needs_command -a shuffle -d 'Show or change playback shuffle state'
|
|
195
201
|
complete -c spoti -n __spoti_needs_command -a repeat -d 'Show or change playback repeat mode'
|
|
196
202
|
complete -c spoti -n __spoti_needs_command -a album -d 'Search for an album'
|
|
197
203
|
complete -c spoti -n __spoti_needs_command -a artist -d 'Search for an artist'
|
|
198
|
-
complete -c spoti -n __spoti_needs_command -a playlists -d '
|
|
204
|
+
complete -c spoti -n __spoti_needs_command -a playlists -d 'Browse and optionally play your playlists'
|
|
199
205
|
complete -c spoti -n __spoti_needs_command -a playlist -d 'Show a playlist'
|
|
200
|
-
complete -c spoti -n __spoti_needs_command -a liked -d '
|
|
206
|
+
complete -c spoti -n __spoti_needs_command -a liked -d 'Browse and optionally play liked tracks'
|
|
201
207
|
complete -c spoti -n __spoti_needs_command -a like -d 'Like the current track'
|
|
202
208
|
complete -c spoti -n __spoti_needs_command -a unlike -d 'Unlike the current track'
|
|
203
|
-
complete -c spoti -n __spoti_needs_command -a recent -d '
|
|
209
|
+
complete -c spoti -n __spoti_needs_command -a recent -d 'Browse and optionally play recently played tracks'
|
|
204
210
|
complete -c spoti -n __spoti_needs_command -a update -d 'Check for or install updates'
|
|
205
211
|
complete -c spoti -n __spoti_needs_command -a search -d 'Search Spotify tracks'
|
|
206
212
|
complete -c spoti -n __spoti_needs_command -a play -d 'Play a track, album, artist, or playlist'
|
|
207
213
|
complete -c spoti -n __spoti_needs_command -a completion -d 'Print a shell completion script'
|
|
208
|
-
complete -c spoti -n __spoti_needs_command -a 'i p pa r np q s vol dev devs pl pls rep rec n prev' -d 'Command alias'
|
|
214
|
+
complete -c spoti -n __spoti_needs_command -a 'i p pa r np q s vol dev devs pl pls rep rec n prev sk alb art' -d 'Command alias'
|
|
209
215
|
|
|
210
216
|
complete -c spoti -n '__fish_seen_subcommand_from config; and not __fish_seen_subcommand_from get set reset path unset' -a 'get set reset path unset'
|
|
211
217
|
complete -c spoti -n '__fish_seen_subcommand_from config; and __fish_seen_subcommand_from get set unset' -a 'spotifyClientId watchAfterPlay refreshIntervalMs'
|
|
212
218
|
complete -c spoti -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish'
|
|
213
219
|
complete -c spoti -n '__fish_seen_subcommand_from now np' -s w -l watch -d 'Continuously refresh playback information'
|
|
214
|
-
complete -c spoti -n '__fish_seen_subcommand_from queue q album artist playlist pl' -l first -d 'Select the first result without prompting'
|
|
215
|
-
complete -c spoti -n '__fish_seen_subcommand_from playlists pls liked recent rec
|
|
220
|
+
complete -c spoti -n '__fish_seen_subcommand_from queue q album alb artist art playlist pl' -l first -d 'Select the first result without prompting'
|
|
221
|
+
complete -c spoti -n '__fish_seen_subcommand_from playlists pls liked recent rec' -s l -l limit -r -d 'Number of items per page'
|
|
222
|
+
complete -c spoti -n '__fish_seen_subcommand_from search s' -s l -l limit -r -d 'Maximum number of results'
|
|
216
223
|
complete -c spoti -n '__fish_seen_subcommand_from update' -l check -d 'Check without installing'
|
|
217
224
|
complete -c spoti -n '__fish_seen_subcommand_from play p' -l first -d 'Play the first result without prompting'
|
|
218
225
|
complete -c spoti -n '__fish_seen_subcommand_from play p' -l watch -d 'Continuously refresh playback information'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.js","sourceRoot":"","sources":["../../src/ui/completions.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDtB,CAAC;AAEF,MAAM,aAAa,GAAG
|
|
1
|
+
{"version":3,"file":"completions.js","sourceRoot":"","sources":["../../src/ui/completions.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDtB,CAAC;AAEF,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsHrB,CAAC;AAEF,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsDtB,CAAC;AAEF,mFAAmF;AACnF,MAAM,UAAU,wBAAwB,CAAC,KAAsB;IAC7D,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,MAAM;YACT,OAAO,cAAc,CAAC;QACxB,KAAK,KAAK;YACR,OAAO,aAAa,CAAC;QACvB,KAAK,MAAM;YACT,OAAO,cAAc,CAAC;QACxB;YACE,MAAM,IAAI,KAAK,CAAC,sBAAsB,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Page } from '../services/pagination.js';
|
|
2
|
+
export interface PageView<Item> {
|
|
3
|
+
items: Item[];
|
|
4
|
+
pageNumber: number;
|
|
5
|
+
startIndex: number;
|
|
6
|
+
total?: number;
|
|
7
|
+
hasNext: boolean;
|
|
8
|
+
hasPrevious: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type PageAction = {
|
|
11
|
+
type: 'cancel';
|
|
12
|
+
} | {
|
|
13
|
+
type: 'next';
|
|
14
|
+
} | {
|
|
15
|
+
type: 'previous';
|
|
16
|
+
} | {
|
|
17
|
+
type: 'select';
|
|
18
|
+
index: number;
|
|
19
|
+
};
|
|
20
|
+
export type PageActionPrompt<Item> = (view: PageView<Item>) => Promise<PageAction>;
|
|
21
|
+
export interface PageBrowser<Item> {
|
|
22
|
+
select(): Promise<Item | null>;
|
|
23
|
+
}
|
|
24
|
+
interface PageBrowserOptions<Item, Token> {
|
|
25
|
+
loadPage(token?: Token): Promise<Page<Item, Token>>;
|
|
26
|
+
renderPage(view: PageView<Item>): void;
|
|
27
|
+
chooseAction: PageActionPrompt<Item>;
|
|
28
|
+
}
|
|
29
|
+
export declare function createPageBrowser<Item, Token>(options: PageBrowserOptions<Item, Token>): PageBrowser<Item>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export function createPageBrowser(options) {
|
|
2
|
+
const pages = [];
|
|
3
|
+
const loadedTokens = new Set();
|
|
4
|
+
let currentPageIndex = 0;
|
|
5
|
+
const loadPage = async (index) => {
|
|
6
|
+
const cached = pages[index];
|
|
7
|
+
if (cached)
|
|
8
|
+
return cached;
|
|
9
|
+
const previous = pages[index - 1];
|
|
10
|
+
const token = previous?.page.nextToken ?? undefined;
|
|
11
|
+
if (index > 0 && token === undefined)
|
|
12
|
+
return null;
|
|
13
|
+
const tokenKey = stableTokenKey(token);
|
|
14
|
+
if (loadedTokens.has(tokenKey)) {
|
|
15
|
+
if (previous)
|
|
16
|
+
previous.page.nextToken = null;
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
loadedTokens.add(tokenKey);
|
|
20
|
+
const page = await options.loadPage(token);
|
|
21
|
+
const loaded = {
|
|
22
|
+
page,
|
|
23
|
+
startIndex: previous
|
|
24
|
+
? previous.startIndex + previous.page.items.length
|
|
25
|
+
: 0,
|
|
26
|
+
};
|
|
27
|
+
pages[index] = loaded;
|
|
28
|
+
return loaded;
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
async select() {
|
|
32
|
+
while (true) {
|
|
33
|
+
const current = await loadPage(currentPageIndex);
|
|
34
|
+
if (!current)
|
|
35
|
+
return null;
|
|
36
|
+
const view = {
|
|
37
|
+
items: current.page.items,
|
|
38
|
+
pageNumber: currentPageIndex + 1,
|
|
39
|
+
startIndex: current.startIndex,
|
|
40
|
+
...(current.page.total === undefined ? {} : { total: current.page.total }),
|
|
41
|
+
hasPrevious: currentPageIndex > 0,
|
|
42
|
+
hasNext: current.page.nextToken !== null,
|
|
43
|
+
};
|
|
44
|
+
options.renderPage(view);
|
|
45
|
+
if (view.items.length === 0 && !view.hasPrevious && !view.hasNext)
|
|
46
|
+
return null;
|
|
47
|
+
const action = await options.chooseAction(view);
|
|
48
|
+
if (action.type === 'cancel')
|
|
49
|
+
return null;
|
|
50
|
+
if (action.type === 'previous') {
|
|
51
|
+
if (view.hasPrevious)
|
|
52
|
+
currentPageIndex -= 1;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (action.type === 'next') {
|
|
56
|
+
if (view.hasNext)
|
|
57
|
+
currentPageIndex += 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
return current.page.items[action.index] ?? null;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function stableTokenKey(token) {
|
|
66
|
+
if (token === undefined)
|
|
67
|
+
return 'first-page';
|
|
68
|
+
if (typeof token !== 'object' || token === null)
|
|
69
|
+
return `${typeof token}:${String(token)}`;
|
|
70
|
+
return JSON.stringify(Object.entries(token).sort(([left], [right]) => left.localeCompare(right)));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../../src/ui/pagination.ts"],"names":[],"mappings":"AAkCA,MAAM,UAAU,iBAAiB,CAC/B,OAAwC;IAExC,MAAM,KAAK,GAAmC,EAAE,CAAC;IACjD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IACvC,IAAI,gBAAgB,GAAG,CAAC,CAAC;IAEzB,MAAM,QAAQ,GAAG,KAAK,EAAE,KAAa,EAA2C,EAAE;QAChF,MAAM,MAAM,GAAG,KAAK,CAAC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IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC3F,OAAO,IAAI,CAAC,SAAS,CACnB,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,CACxE,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAC1B,CACF,CAAC;AACJ,CAAC"}
|
package/dist/ui/prompts.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import type { Album, Artist, Playlist,
|
|
1
|
+
import type { Album, Artist, Playlist, Track } from '../services/models.js';
|
|
2
|
+
import type { PageAction, PageView } from './pagination.js';
|
|
2
3
|
export declare function selectTrack(tracks: Track[]): Promise<Track | null>;
|
|
3
|
-
export declare function selectAlbum(albums: Album[]
|
|
4
|
+
export declare function selectAlbum(albums: Album[], options?: {
|
|
5
|
+
emptyAction?: 'cancel' | 'go back';
|
|
6
|
+
}): Promise<Album | null>;
|
|
4
7
|
export declare function selectArtist(artists: Artist[]): Promise<Artist | null>;
|
|
5
8
|
export declare function selectPlaylist(playlists: Playlist[]): Promise<Playlist | null>;
|
|
6
|
-
export
|
|
7
|
-
export declare function selectLikedTrack(items: SavedTrack[]): Promise<Track | null>;
|
|
8
|
-
export declare function selectListedPlaylist(playlists: Playlist[]): Promise<Playlist | null>;
|
|
9
|
-
export type AlbumAction = 'play-album' | 'play-track';
|
|
9
|
+
export type AlbumAction = 'play-album' | 'play-track' | 'back';
|
|
10
10
|
export type ArtistAction = 'play-artist' | 'select-album';
|
|
11
|
-
export type PlaylistAction = 'play-playlist';
|
|
12
|
-
export declare function selectAlbumAction(
|
|
11
|
+
export type PlaylistAction = 'play-playlist' | 'select-track';
|
|
12
|
+
export declare function selectAlbumAction(options?: {
|
|
13
|
+
allowBack?: boolean;
|
|
14
|
+
}): Promise<AlbumAction | null>;
|
|
13
15
|
export declare function selectArtistAction(): Promise<ArtistAction | null>;
|
|
14
16
|
export declare function selectPlaylistAction(): Promise<PlaylistAction | null>;
|
|
15
17
|
export declare function promptSpotifyClientId(): Promise<string | null>;
|
|
@@ -20,4 +22,11 @@ export type SelectionInput = {
|
|
|
20
22
|
status: 'selected';
|
|
21
23
|
index: number;
|
|
22
24
|
};
|
|
25
|
+
export type PageSelectionInput = PageAction | {
|
|
26
|
+
type: 'invalid';
|
|
27
|
+
};
|
|
28
|
+
export declare function parsePageSelectionInput(value: string, view: Pick<PageView<unknown>, 'hasNext' | 'hasPrevious' | 'items' | 'startIndex'>): PageSelectionInput;
|
|
29
|
+
export declare function selectPageAction<Item>(view: PageView<Item>, options?: {
|
|
30
|
+
emptyAction?: string;
|
|
31
|
+
}): Promise<PageAction>;
|
|
23
32
|
export declare function parseSelectionInput(value: string, itemCount: number): SelectionInput;
|
package/dist/ui/prompts.js
CHANGED
|
@@ -5,9 +5,9 @@ export async function selectTrack(tracks) {
|
|
|
5
5
|
const styles = createOutputStyles(Boolean(stdout.isTTY), process.env);
|
|
6
6
|
return selectItem(tracks, (track, index) => formatTrack(track, index, styles));
|
|
7
7
|
}
|
|
8
|
-
export async function selectAlbum(albums) {
|
|
8
|
+
export async function selectAlbum(albums, options = {}) {
|
|
9
9
|
const styles = createOutputStyles(Boolean(stdout.isTTY), process.env);
|
|
10
|
-
return selectItem(albums, (album, index) => formatAlbum(album, index, styles));
|
|
10
|
+
return selectItem(albums, (album, index) => formatAlbum(album, index, styles), options.emptyAction);
|
|
11
11
|
}
|
|
12
12
|
export async function selectArtist(artists) {
|
|
13
13
|
const styles = createOutputStyles(Boolean(stdout.isTTY), process.env);
|
|
@@ -17,29 +17,14 @@ export async function selectPlaylist(playlists) {
|
|
|
17
17
|
const styles = createOutputStyles(Boolean(stdout.isTTY), process.env);
|
|
18
18
|
return selectItem(playlists, (playlist, index) => formatPlaylist(playlist, index, styles));
|
|
19
19
|
}
|
|
20
|
-
export async function
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
export async function selectLikedTrack(items) {
|
|
24
|
-
return selectDisplayedTrack(items.map((item) => item.track), 'liked');
|
|
25
|
-
}
|
|
26
|
-
export async function selectListedPlaylist(playlists) {
|
|
27
|
-
if (playlists.length === 0 || !stdin.isTTY || !stdout.isTTY)
|
|
28
|
-
return null;
|
|
29
|
-
const prompt = createInterface({ input: stdin, output: stdout });
|
|
30
|
-
try {
|
|
31
|
-
const index = await promptForSelection(prompt, `\nPlay a playlist [1-${playlists.length}] (Enter to keep current playback): `, playlists.length);
|
|
32
|
-
return index === null ? null : (playlists[index] ?? null);
|
|
33
|
-
}
|
|
34
|
-
finally {
|
|
35
|
-
prompt.close();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export async function selectAlbumAction() {
|
|
39
|
-
return selectAction([
|
|
20
|
+
export async function selectAlbumAction(options = {}) {
|
|
21
|
+
const actions = [
|
|
40
22
|
{ value: 'play-album', label: 'Play the entire album' },
|
|
41
23
|
{ value: 'play-track', label: 'Select a track' },
|
|
42
|
-
]
|
|
24
|
+
];
|
|
25
|
+
if (options.allowBack)
|
|
26
|
+
actions.push({ value: 'back', label: 'Back to albums' });
|
|
27
|
+
return selectAction(actions);
|
|
43
28
|
}
|
|
44
29
|
export async function selectArtistAction() {
|
|
45
30
|
return selectAction([
|
|
@@ -48,7 +33,10 @@ export async function selectArtistAction() {
|
|
|
48
33
|
]);
|
|
49
34
|
}
|
|
50
35
|
export async function selectPlaylistAction() {
|
|
51
|
-
return selectAction([
|
|
36
|
+
return selectAction([
|
|
37
|
+
{ value: 'play-playlist', label: 'Play the playlist' },
|
|
38
|
+
{ value: 'select-track', label: 'Select a track' },
|
|
39
|
+
]);
|
|
52
40
|
}
|
|
53
41
|
export async function promptSpotifyClientId() {
|
|
54
42
|
if (!stdin.isTTY || !stdout.isTTY)
|
|
@@ -89,33 +77,67 @@ async function selectAction(actions) {
|
|
|
89
77
|
prompt.close();
|
|
90
78
|
}
|
|
91
79
|
}
|
|
92
|
-
async function
|
|
93
|
-
if (
|
|
80
|
+
async function selectItem(items, format, emptyAction = 'cancel') {
|
|
81
|
+
if (items.length === 0)
|
|
94
82
|
return null;
|
|
83
|
+
if (!stdin.isTTY || !stdout.isTTY)
|
|
84
|
+
return items[0] ?? null;
|
|
85
|
+
stdout.write(`${items.map((item, index) => format(item, index)).join('\n')}\n\n`);
|
|
95
86
|
const prompt = createInterface({ input: stdin, output: stdout });
|
|
96
87
|
try {
|
|
97
|
-
const index = await promptForSelection(prompt,
|
|
98
|
-
return index === null ? null : (
|
|
88
|
+
const index = await promptForSelection(prompt, `Select [1-${items.length}] (Enter to ${emptyAction}): `, items.length);
|
|
89
|
+
return index === null ? null : (items[index] ?? null);
|
|
99
90
|
}
|
|
100
91
|
finally {
|
|
101
92
|
prompt.close();
|
|
102
93
|
}
|
|
103
94
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
export function parsePageSelectionInput(value, view) {
|
|
96
|
+
const normalized = value.trim().toLocaleLowerCase();
|
|
97
|
+
if (!normalized)
|
|
98
|
+
return { type: 'cancel' };
|
|
99
|
+
if (normalized === 'n')
|
|
100
|
+
return view.hasNext ? { type: 'next' } : { type: 'invalid' };
|
|
101
|
+
if (normalized === 'p') {
|
|
102
|
+
return view.hasPrevious ? { type: 'previous' } : { type: 'invalid' };
|
|
103
|
+
}
|
|
104
|
+
if (!/^\d+$/.test(normalized))
|
|
105
|
+
return { type: 'invalid' };
|
|
106
|
+
const index = Number(normalized) - view.startIndex - 1;
|
|
107
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= view.items.length) {
|
|
108
|
+
return { type: 'invalid' };
|
|
109
|
+
}
|
|
110
|
+
return { type: 'select', index };
|
|
111
|
+
}
|
|
112
|
+
export async function selectPageAction(view, options = {}) {
|
|
107
113
|
if (!stdin.isTTY || !stdout.isTTY)
|
|
108
|
-
return
|
|
109
|
-
stdout.write(`${items.map((item, index) => format(item, index)).join('\n')}\n\n`);
|
|
114
|
+
return { type: 'cancel' };
|
|
110
115
|
const prompt = createInterface({ input: stdin, output: stdout });
|
|
116
|
+
const choices = pageChoices(view);
|
|
111
117
|
try {
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
while (true) {
|
|
119
|
+
const answer = await prompt.question(`Select ${choices} (Enter to ${options.emptyAction ?? 'cancel'}): `);
|
|
120
|
+
const selection = parsePageSelectionInput(answer, view);
|
|
121
|
+
if (selection.type !== 'invalid')
|
|
122
|
+
return selection;
|
|
123
|
+
stdout.write(`Choose ${choices}, or press Enter to ${options.emptyAction ?? 'cancel'}.\n`);
|
|
124
|
+
}
|
|
114
125
|
}
|
|
115
126
|
finally {
|
|
116
127
|
prompt.close();
|
|
117
128
|
}
|
|
118
129
|
}
|
|
130
|
+
function pageChoices(view) {
|
|
131
|
+
const choices = [];
|
|
132
|
+
if (view.items.length > 0) {
|
|
133
|
+
choices.push(`[${view.startIndex + 1}-${view.startIndex + view.items.length}]`);
|
|
134
|
+
}
|
|
135
|
+
if (view.hasNext)
|
|
136
|
+
choices.push('n for next');
|
|
137
|
+
if (view.hasPrevious)
|
|
138
|
+
choices.push('p for previous');
|
|
139
|
+
return choices.join(', ') || 'an available action';
|
|
140
|
+
}
|
|
119
141
|
export function parseSelectionInput(value, itemCount) {
|
|
120
142
|
const normalized = value.trim();
|
|
121
143
|
if (!normalized)
|
package/dist/ui/prompts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/ui/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/ui/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM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qB,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,SAAiB;IAClE,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAChC,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAChD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC5D,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,SAAS,EAAE,CAAC;QACpE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC/B,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACvC,CAAC;AAED,KAAK,UAAU,kBAAkB,CAC/B,MAAiB,EACjB,QAAgB,EAChB,SAAiB;IAEjB,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,MAAM,GAAG,mBAAmB,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC;QAC/E,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC/C,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC;QACtD,MAAM,CAAC,KAAK,CAAC,4CAA4C,SAAS,KAAK,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
|
package/dist/utils/errors.js
CHANGED
|
@@ -28,11 +28,24 @@ export class PremiumRequiredError extends AppError {
|
|
|
28
28
|
export class RateLimitedError extends AppError {
|
|
29
29
|
retryAfterSeconds;
|
|
30
30
|
constructor(retryAfterSeconds) {
|
|
31
|
-
|
|
32
|
-
super(`Spotify rate limit reached. Try again in ${retryAfterSeconds} ${unit}.`);
|
|
31
|
+
super(`Spotify rate limit reached. Try again in ${formatRetryDuration(retryAfterSeconds)}.`);
|
|
33
32
|
this.retryAfterSeconds = retryAfterSeconds;
|
|
34
33
|
}
|
|
35
34
|
}
|
|
35
|
+
function formatRetryDuration(seconds) {
|
|
36
|
+
if (seconds < 60)
|
|
37
|
+
return `${seconds} ${seconds === 1 ? 'second' : 'seconds'}`;
|
|
38
|
+
const totalMinutes = Math.ceil(seconds / 60);
|
|
39
|
+
if (totalMinutes < 60) {
|
|
40
|
+
return `${totalMinutes} ${totalMinutes === 1 ? 'minute' : 'minutes'}`;
|
|
41
|
+
}
|
|
42
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
43
|
+
const minutes = totalMinutes % 60;
|
|
44
|
+
const hoursText = `${hours} ${hours === 1 ? 'hour' : 'hours'}`;
|
|
45
|
+
return minutes === 0
|
|
46
|
+
? hoursText
|
|
47
|
+
: `${hoursText} ${minutes} ${minutes === 1 ? 'minute' : 'minutes'}`;
|
|
48
|
+
}
|
|
36
49
|
export class SpotifyApiError extends AppError {
|
|
37
50
|
status;
|
|
38
51
|
constructor(message, status) {
|
package/dist/utils/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGf;IAFlB,YACE,OAAe,EACC,WAAW,CAAC;QAE5B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,aAAQ,GAAR,QAAQ,CAAI;QAG5B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,QAAQ;CAAG;AAEnD,MAAM,OAAO,2BAA4B,SAAQ,QAAQ;IACvD,YAAY,OAAO,GAAG,4CAA4C;QAChE,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