songbirdcli 0.2.3__tar.gz → 0.2.4__tar.gz
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.
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/PKG-INFO +1 -1
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/pyproject.toml +5 -2
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli/cli.py +149 -43
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli/helpers.py +55 -24
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli/requirements.txt.blank +2 -1
- songbirdcli-0.2.4/songbirdcli/version.py +1 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli.egg-info/PKG-INFO +1 -1
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/tests/unit/test_cli.py +37 -11
- songbirdcli-0.2.4/tests/unit/test_helpers.py +162 -0
- songbirdcli-0.2.3/songbirdcli/version.py +0 -1
- songbirdcli-0.2.3/tests/unit/test_helpers.py +0 -103
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/.dockerignore +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/.github/workflows/docker.yml +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/.github/workflows/pages.yaml +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/.github/workflows/pypi-publish.yaml +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/.github/workflows/style.yml +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/.github/workflows/tests.yaml +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/.gitignore +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/Dockerfile +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/LICENSE +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/Makefile +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/README.md +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/docs/index.md +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/docs/songbirdcli/cli.md +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/docs/songbirdcli/helpers.md +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/docs/songbirdcli/settings.md +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/markdownlint.yaml +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/mkdocs.yml +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/setup.cfg +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli/requirements.txt +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli/settings.py +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli.egg-info/SOURCES.txt +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli.egg-info/dependency_links.txt +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli.egg-info/requires.txt +0 -0
- {songbirdcli-0.2.3 → songbirdcli-0.2.4}/songbirdcli.egg-info/top_level.txt +0 -0
|
@@ -7,7 +7,7 @@ name = "songbirdcli"
|
|
|
7
7
|
authors = [
|
|
8
8
|
{name = "Christian Boin"},
|
|
9
9
|
]
|
|
10
|
-
version = "0.2.
|
|
10
|
+
version = "0.2.4"
|
|
11
11
|
description = "Songbird's cli."
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
requires-python = ">=3.11"
|
|
@@ -42,4 +42,7 @@ package = [
|
|
|
42
42
|
]
|
|
43
43
|
|
|
44
44
|
[tool.setuptools.packages.find]
|
|
45
|
-
exclude = ["app", "junit"]
|
|
45
|
+
exclude = ["app", "junit"]
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
log_cli_level="INFO"
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import datetime
|
|
3
3
|
from enum import Enum
|
|
4
|
-
from typing import Optional, List
|
|
4
|
+
from typing import Optional, List, Union
|
|
5
|
+
import requests
|
|
5
6
|
import os, sys, shutil
|
|
6
7
|
|
|
7
8
|
from songbirdcli import settings
|
|
@@ -114,6 +115,7 @@ def run_download_process(
|
|
|
114
115
|
render_wait: float,
|
|
115
116
|
render_retries: int,
|
|
116
117
|
render_sleep: int,
|
|
118
|
+
quit_str: str = "q",
|
|
117
119
|
) -> str:
|
|
118
120
|
"""Download a song from youtube.
|
|
119
121
|
|
|
@@ -129,18 +131,40 @@ def run_download_process(
|
|
|
129
131
|
render_sleep (int): the amount of time to wait after rendering
|
|
130
132
|
|
|
131
133
|
Returns:
|
|
132
|
-
str: the path on disk that the file was saved to
|
|
134
|
+
str: the path on disk that the file was saved to, None if failure occured, quit_str if user quit
|
|
133
135
|
"""
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
is_valid_url = False
|
|
137
|
+
while not is_valid_url:
|
|
138
|
+
# obtain video selection from user
|
|
139
|
+
video_url = helpers.get_input(
|
|
140
|
+
prompt=f"Enter a URL, or hit enter to use '{youtube_query_payload}' as a query to youtube: ",
|
|
141
|
+
out_type=str,
|
|
142
|
+
quit_str=quit_str,
|
|
143
|
+
)
|
|
144
|
+
# if user hits enter, bypass url checks
|
|
145
|
+
if video_url == "":
|
|
146
|
+
break
|
|
139
147
|
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
if video_url == quit_str:
|
|
149
|
+
return quit_str
|
|
142
150
|
|
|
143
|
-
|
|
151
|
+
if video_url is None:
|
|
152
|
+
return None
|
|
153
|
+
try:
|
|
154
|
+
response = requests.get(video_url)
|
|
155
|
+
except Exception as e:
|
|
156
|
+
logger.error(f"exception occured testing your url: {e}")
|
|
157
|
+
continue
|
|
158
|
+
|
|
159
|
+
# only continue if url was valid
|
|
160
|
+
if response.status_code == 200:
|
|
161
|
+
is_valid_url = True
|
|
162
|
+
else:
|
|
163
|
+
logger.error(
|
|
164
|
+
f"URL is valid, but could not receive 200 status from {video_url}, is internet down?"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
# empty str (enter) query youtube
|
|
144
168
|
if video_url == "":
|
|
145
169
|
link_list, links = youtube.get_video_links(
|
|
146
170
|
youtube_home_url,
|
|
@@ -164,6 +188,9 @@ def run_download_process(
|
|
|
164
188
|
1,
|
|
165
189
|
return_value=False,
|
|
166
190
|
)
|
|
191
|
+
if video_selection_idx == quit_str:
|
|
192
|
+
return quit_str
|
|
193
|
+
|
|
167
194
|
if video_selection_idx is None or len(video_selection_idx) == 0:
|
|
168
195
|
return None
|
|
169
196
|
|
|
@@ -176,13 +203,17 @@ def run_for_song(
|
|
|
176
203
|
config: settings.SongbirdCliConfig,
|
|
177
204
|
song_name: str,
|
|
178
205
|
song_properties: Optional[itunes_api.ItunesApiSongModel],
|
|
179
|
-
|
|
206
|
+
quit_str: str = "q",
|
|
207
|
+
) -> Union[bool, None, str]:
|
|
180
208
|
"""Run a cycle of the application given a song.
|
|
181
209
|
|
|
182
210
|
Args:
|
|
183
211
|
config (settings.SongbirdConfig): the songbird config
|
|
184
212
|
song_name (str): the name of the song to run the app for
|
|
185
213
|
song_properties (Optional[itunes_api.ItunesApiSongModel]): optionally include song properties. Including these skips the itunes api parser.
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
Union[bool, None, str]: returns boolean indicating success/failure. None indicated error occurred, quit_str indicates user quit
|
|
186
217
|
"""
|
|
187
218
|
logger.info(f"Searching for: {song_name}")
|
|
188
219
|
file_itunes = []
|
|
@@ -207,15 +238,18 @@ def run_for_song(
|
|
|
207
238
|
inp = helpers.get_input(
|
|
208
239
|
"Do you want to proceed with download anyway?", choices=["y", "n"]
|
|
209
240
|
)
|
|
241
|
+
# user quits or selects no
|
|
242
|
+
if inp == quit_str or inp == "n":
|
|
243
|
+
return quit_str
|
|
210
244
|
|
|
211
|
-
if inp is None
|
|
245
|
+
if inp is None:
|
|
212
246
|
return
|
|
213
247
|
|
|
214
248
|
if song_properties is None:
|
|
215
249
|
song_properties = helpers.parse_itunes_search_api(song_name, modes.Modes.SONG)
|
|
216
250
|
|
|
217
|
-
if song_properties
|
|
218
|
-
return
|
|
251
|
+
if song_properties == quit_str:
|
|
252
|
+
return quit_str
|
|
219
253
|
|
|
220
254
|
file_path_no_format = os.path.join(config.get_local_folder_path(), song_name)
|
|
221
255
|
file_path = file_path_no_format + "." + file_format
|
|
@@ -251,11 +285,21 @@ def run_for_song(
|
|
|
251
285
|
render_wait=config.youtube_render_wait,
|
|
252
286
|
render_retries=config.youtube_render_retries,
|
|
253
287
|
render_sleep=config.youtube_render_sleep,
|
|
288
|
+
quit_str=quit_str,
|
|
254
289
|
)
|
|
290
|
+
if downloaded_file_path == quit_str:
|
|
291
|
+
return quit_str
|
|
255
292
|
|
|
256
293
|
if downloaded_file_path is None:
|
|
257
294
|
return
|
|
258
295
|
|
|
296
|
+
# perform sanity check in case no file exists and yt-dlp didnt throw an error
|
|
297
|
+
if not os.path.exists(downloaded_file_path):
|
|
298
|
+
logger.error(
|
|
299
|
+
f"yt-dlp reported no error downloading file, but file does not exist. Cannot proceed with tagging as no file exists."
|
|
300
|
+
)
|
|
301
|
+
return
|
|
302
|
+
|
|
259
303
|
if song_properties != False:
|
|
260
304
|
# tag file if user specified song properties
|
|
261
305
|
tag_successful = False
|
|
@@ -294,6 +338,8 @@ def run_for_song(
|
|
|
294
338
|
if not config.itunes_enabled and not config.gdrive_enabled:
|
|
295
339
|
inp = "l"
|
|
296
340
|
|
|
341
|
+
if inp == quit_str:
|
|
342
|
+
return quit_str
|
|
297
343
|
if inp is None:
|
|
298
344
|
return
|
|
299
345
|
|
|
@@ -346,6 +392,53 @@ def run_for_song(
|
|
|
346
392
|
return True
|
|
347
393
|
|
|
348
394
|
|
|
395
|
+
def get_songs_from_user(
|
|
396
|
+
current_mode: modes.Modes, quit_str: str = "q"
|
|
397
|
+
) -> Optional[Union[str, List[str]]]:
|
|
398
|
+
# launch album mode to collect songs
|
|
399
|
+
if current_mode == modes.Modes.ALBUM:
|
|
400
|
+
album_name = helpers.get_input(
|
|
401
|
+
f"Enter an album name.", out_type=str, quit_str=quit_str
|
|
402
|
+
)
|
|
403
|
+
# quit condition
|
|
404
|
+
if album_name == quit_str:
|
|
405
|
+
return quit_str
|
|
406
|
+
if album_name is None:
|
|
407
|
+
return None
|
|
408
|
+
|
|
409
|
+
mode = resolve_mode(album_name, current_mode=current_mode)
|
|
410
|
+
# detect mode change and return to main menu
|
|
411
|
+
if mode is not None:
|
|
412
|
+
return mode
|
|
413
|
+
|
|
414
|
+
album_song_properties = helpers.launch_album_mode(album_name)
|
|
415
|
+
# quit iteration to main menu
|
|
416
|
+
if album_song_properties == quit_str:
|
|
417
|
+
return quit_str
|
|
418
|
+
if album_song_properties is None:
|
|
419
|
+
return None
|
|
420
|
+
return [song.trackName for song in album_song_properties]
|
|
421
|
+
|
|
422
|
+
# launch song mode to collect songs
|
|
423
|
+
elif current_mode == modes.Modes.SONG:
|
|
424
|
+
songs = helpers.get_input_list(
|
|
425
|
+
"Please input song(s), separated by ';'. E.g. song1; song2; song3.",
|
|
426
|
+
out_type=str,
|
|
427
|
+
sep="; ",
|
|
428
|
+
)
|
|
429
|
+
# quit iteration to main menu
|
|
430
|
+
if songs == quit_str:
|
|
431
|
+
return quit_str
|
|
432
|
+
if songs is None:
|
|
433
|
+
return None
|
|
434
|
+
|
|
435
|
+
mode = resolve_mode(songs[0], current_mode=current_mode)
|
|
436
|
+
# detect mode change and return to main menu
|
|
437
|
+
if mode is not None:
|
|
438
|
+
return mode
|
|
439
|
+
return songs
|
|
440
|
+
|
|
441
|
+
|
|
349
442
|
def run(config: settings.SongbirdCliConfig):
|
|
350
443
|
"""main entrypoint for songbirdcli. Expects the songbirdcli config object.
|
|
351
444
|
|
|
@@ -353,6 +446,8 @@ def run(config: settings.SongbirdCliConfig):
|
|
|
353
446
|
config (settings.SongbirdCliConfig): songbirdcli settings pydantic model
|
|
354
447
|
|
|
355
448
|
"""
|
|
449
|
+
# setup quit str for user
|
|
450
|
+
quit_str = "q"
|
|
356
451
|
try:
|
|
357
452
|
common.set_logger_config_globally(log_level=config.log_level)
|
|
358
453
|
common.name_plate(entries=[f"--cli {config.version}"])
|
|
@@ -376,43 +471,54 @@ def run(config: settings.SongbirdCliConfig):
|
|
|
376
471
|
|
|
377
472
|
song_properties = None
|
|
378
473
|
album_song_properties = None
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
mode = resolve_mode(album_name, current_mode=current_mode)
|
|
386
|
-
# detect mode change and return to main menu
|
|
387
|
-
if mode is not None:
|
|
388
|
-
current_mode = mode
|
|
389
|
-
continue
|
|
390
|
-
|
|
391
|
-
album_song_properties = helpers.launch_album_mode(album_name)
|
|
392
|
-
if album_song_properties is None:
|
|
393
|
-
break
|
|
394
|
-
|
|
395
|
-
songs = [song.trackName for song in album_song_properties]
|
|
396
|
-
elif current_mode == modes.Modes.SONG:
|
|
397
|
-
songs = helpers.get_input_list(
|
|
398
|
-
"Please input song(s), separated by ';'. E.g. song1; song2; song3.",
|
|
474
|
+
result = get_songs_from_user(current_mode=current_mode, quit_str=quit_str)
|
|
475
|
+
# user quits
|
|
476
|
+
if result == quit_str:
|
|
477
|
+
return_to_menu = helpers.get_input(
|
|
478
|
+
prompt=f"Are you sure you want to quit?",
|
|
479
|
+
choices=["y", "n"],
|
|
399
480
|
out_type=str,
|
|
400
|
-
|
|
481
|
+
quit_str=quit_str,
|
|
401
482
|
)
|
|
402
|
-
#
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
mode = resolve_mode(songs[0], current_mode=current_mode)
|
|
406
|
-
# detect mode change and return to main menu
|
|
407
|
-
if mode is not None:
|
|
408
|
-
current_mode = mode
|
|
483
|
+
# allow user to return to main menu before
|
|
484
|
+
# full shutdown
|
|
485
|
+
if return_to_menu == "n":
|
|
409
486
|
continue
|
|
410
487
|
|
|
488
|
+
return quit_str
|
|
489
|
+
|
|
490
|
+
# user changed mode
|
|
491
|
+
if isinstance(result, modes.Modes):
|
|
492
|
+
current_mode = result
|
|
493
|
+
continue
|
|
494
|
+
|
|
495
|
+
# error occurred
|
|
496
|
+
if result is None:
|
|
497
|
+
continue
|
|
498
|
+
# set songs to result and continue otherwise
|
|
499
|
+
songs = result
|
|
411
500
|
logger.info(f"Searching for songs: {songs}")
|
|
412
501
|
for i, song in enumerate(songs):
|
|
413
502
|
if album_song_properties is not None:
|
|
414
503
|
song_properties = album_song_properties[i]
|
|
415
|
-
success = run_for_song(config, song, song_properties)
|
|
504
|
+
success = run_for_song(config, song, song_properties, quit_str)
|
|
505
|
+
|
|
506
|
+
# detect if more songs are queued, and asks if user wants to continue with other songs
|
|
507
|
+
if (success == quit_str or success == None) and i + 1 < len(songs):
|
|
508
|
+
songs_remaining = songs[i + 1 :]
|
|
509
|
+
common.pretty_lst_printer(songs_remaining)
|
|
510
|
+
return_to_menu = helpers.get_input(
|
|
511
|
+
prompt=f"You have {len(songs_remaining)} songs (above) in queue. Would you like to continue?",
|
|
512
|
+
choices=["y", "n"],
|
|
513
|
+
out_type=str,
|
|
514
|
+
quit_str=quit_str,
|
|
515
|
+
)
|
|
516
|
+
# only return to main menu if user opts to, otherwise enter next iteration
|
|
517
|
+
# to preserve list of selections
|
|
518
|
+
if return_to_menu == "n" or return_to_menu == quit_str:
|
|
519
|
+
break
|
|
520
|
+
if return_to_menu == "y":
|
|
521
|
+
continue
|
|
416
522
|
|
|
417
523
|
except KeyboardInterrupt as e:
|
|
418
524
|
logger.info("\nReceived keyboard interrupt :o")
|
|
@@ -10,19 +10,26 @@ import logging
|
|
|
10
10
|
logger = logging.getLogger(__name__)
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
def launch_album_mode(artist_album_string=""):
|
|
13
|
+
def launch_album_mode(artist_album_string="", quit_str="q"):
|
|
14
14
|
"""
|
|
15
15
|
Args:
|
|
16
16
|
artist_album_string (str): the album/artist to search for.
|
|
17
17
|
|
|
18
|
-
Returns: the list of song properties gathered from the search
|
|
18
|
+
Returns: the list of song properties gathered from the search, None if error occured, quit_str if user quit
|
|
19
19
|
|
|
20
20
|
"""
|
|
21
21
|
while True:
|
|
22
22
|
album_props = parse_itunes_search_api(
|
|
23
|
-
search_variable=artist_album_string,
|
|
23
|
+
search_variable=artist_album_string,
|
|
24
|
+
mode=modes.Modes.ALBUM,
|
|
25
|
+
lookup=False,
|
|
26
|
+
# disable no selection here, user must select album properties.
|
|
27
|
+
no_selection_value=None,
|
|
24
28
|
)
|
|
25
29
|
# check if user quit
|
|
30
|
+
if album_props == quit_str:
|
|
31
|
+
return quit_str
|
|
32
|
+
|
|
26
33
|
if album_props is None:
|
|
27
34
|
return None
|
|
28
35
|
|
|
@@ -33,12 +40,21 @@ def launch_album_mode(artist_album_string=""):
|
|
|
33
40
|
mode=modes.Modes.SONG,
|
|
34
41
|
lookup=True,
|
|
35
42
|
)
|
|
43
|
+
# api error occurred
|
|
36
44
|
if songs_in_album_props == None:
|
|
37
|
-
|
|
45
|
+
return None
|
|
46
|
+
# no songs found for album
|
|
47
|
+
if len(songs_in_album_props) == 0:
|
|
48
|
+
logger.error(
|
|
49
|
+
"Sorry. Cant seem to find any details for this album in itunes api! Please select a different album."
|
|
50
|
+
)
|
|
51
|
+
return None
|
|
38
52
|
|
|
39
53
|
songs_in_album_props = remove_songs_selected(
|
|
40
|
-
song_properties_list=songs_in_album_props
|
|
54
|
+
song_properties_list=songs_in_album_props, quit_str=quit_str
|
|
41
55
|
)
|
|
56
|
+
if songs_in_album_props == quit_str:
|
|
57
|
+
return quit_str
|
|
42
58
|
if songs_in_album_props is None:
|
|
43
59
|
return None
|
|
44
60
|
|
|
@@ -47,8 +63,15 @@ def launch_album_mode(artist_album_string=""):
|
|
|
47
63
|
|
|
48
64
|
# entity is usually song for searching songs
|
|
49
65
|
def parse_itunes_search_api(
|
|
50
|
-
search_variable: str,
|
|
51
|
-
|
|
66
|
+
search_variable: str,
|
|
67
|
+
mode: modes.Modes,
|
|
68
|
+
limit: int = 20,
|
|
69
|
+
lookup: bool = False,
|
|
70
|
+
no_selection_value: Optional[int] = -1,
|
|
71
|
+
quit_str: str = "q",
|
|
72
|
+
) -> Optional[
|
|
73
|
+
Union[bool, itunes_api.ItunesApiSongModel, itunes_api.ItunesApiAlbumKeys]
|
|
74
|
+
]:
|
|
52
75
|
"""perform a query of the items api, allowing user to select
|
|
53
76
|
an item from the returned list of options
|
|
54
77
|
|
|
@@ -57,9 +80,11 @@ def parse_itunes_search_api(
|
|
|
57
80
|
mode (modes.Modes): the mode to run
|
|
58
81
|
limit (int, optional): number of results. Defaults to 20.
|
|
59
82
|
lookup (bool, optional): whether to enable 'lookup' mode in itunes api. Defaults to False.
|
|
83
|
+
no_selection_value (int, optional): whether to set an option for 'no selection' from stdin
|
|
84
|
+
quit_str (str, optional): str value used to determine whether to quit the song selection process
|
|
60
85
|
|
|
61
86
|
Returns:
|
|
62
|
-
Optional[Union[itunes_api.ItunesApiSongModel]]: returns the selected song properties, a bool=False if use continues without selection,
|
|
87
|
+
Optional[Union[itunes_api.ItunesApiSongModel]]: returns the selected song properties, a bool=False if use continues without selection, None if error occurred, or quit_str if user quit.
|
|
63
88
|
"""
|
|
64
89
|
parsed_results_list = itunes.query_api(search_variable, limit, mode, lookup=lookup)
|
|
65
90
|
|
|
@@ -68,16 +93,17 @@ def parse_itunes_search_api(
|
|
|
68
93
|
logger.info("Searched for: %s" % (search_variable))
|
|
69
94
|
# Only one item can be selected
|
|
70
95
|
user_selection = select_items_from_list(
|
|
71
|
-
"Select the number for the properties you want",
|
|
72
|
-
parsed_results_list,
|
|
73
|
-
1,
|
|
74
|
-
|
|
96
|
+
prompt="Select the number for the properties you want",
|
|
97
|
+
lyst=parsed_results_list,
|
|
98
|
+
n_choices=1,
|
|
99
|
+
quit_str=quit_str,
|
|
100
|
+
no_selection_value=no_selection_value,
|
|
75
101
|
)
|
|
76
102
|
|
|
77
103
|
# user has quit
|
|
78
|
-
if user_selection
|
|
104
|
+
if user_selection == quit_str:
|
|
79
105
|
logger.info("Quitting.")
|
|
80
|
-
return
|
|
106
|
+
return quit_str
|
|
81
107
|
if len(user_selection) == 0:
|
|
82
108
|
logger.info("Continuing without properties.")
|
|
83
109
|
return False
|
|
@@ -89,7 +115,7 @@ def parse_itunes_search_api(
|
|
|
89
115
|
return user_selection[0]
|
|
90
116
|
|
|
91
117
|
|
|
92
|
-
def remove_songs_selected(song_properties_list) -> Optional[List]:
|
|
118
|
+
def remove_songs_selected(song_properties_list, quit_str: str = "q") -> Optional[List]:
|
|
93
119
|
"""Given a list of songs properties, allow the user to remove
|
|
94
120
|
via stdio
|
|
95
121
|
|
|
@@ -106,10 +132,13 @@ def remove_songs_selected(song_properties_list) -> Optional[List]:
|
|
|
106
132
|
song_properties_list,
|
|
107
133
|
n_choices=len(song_properties_list) - 1,
|
|
108
134
|
sep=" ",
|
|
135
|
+
quit_str=quit_str,
|
|
109
136
|
opposite=True,
|
|
110
137
|
no_selection_value=-1,
|
|
111
138
|
)
|
|
112
139
|
# user has quit
|
|
140
|
+
if user_input == quit_str:
|
|
141
|
+
return quit_str
|
|
113
142
|
if user_input == None:
|
|
114
143
|
return None
|
|
115
144
|
# user selects all songs
|
|
@@ -131,7 +160,7 @@ def get_input(
|
|
|
131
160
|
choices (Optional[List], optional): valid character options to parse as input. Defaults to None.
|
|
132
161
|
|
|
133
162
|
Returns:
|
|
134
|
-
Optional[Any]: the typed user input,
|
|
163
|
+
Optional[Any]: the typed user input, None if error occured, quit_str if use quit
|
|
135
164
|
"""
|
|
136
165
|
while True:
|
|
137
166
|
built_prompt = prompt
|
|
@@ -140,7 +169,7 @@ def get_input(
|
|
|
140
169
|
built_prompt += " ['q' quits]: "
|
|
141
170
|
inp = input(built_prompt)
|
|
142
171
|
if inp == quit_str:
|
|
143
|
-
return
|
|
172
|
+
return quit_str
|
|
144
173
|
|
|
145
174
|
# initialize type to be empty by default
|
|
146
175
|
typed = None
|
|
@@ -176,12 +205,12 @@ def get_input_list(prompt: str, sep: str, out_type=int, quit_str="q") -> List[in
|
|
|
176
205
|
ValueError: If the input does not match the given type.
|
|
177
206
|
|
|
178
207
|
Returns:
|
|
179
|
-
Optional[List[int]]: the typed list, or
|
|
208
|
+
Optional[List[int]]: the typed list, or the quit_str value if user quits
|
|
180
209
|
"""
|
|
181
210
|
while True:
|
|
182
211
|
inp = input(prompt + f" ['{quit_str}' quits]: ")
|
|
183
212
|
if inp == quit_str:
|
|
184
|
-
return
|
|
213
|
+
return quit_str
|
|
185
214
|
|
|
186
215
|
str_list = inp.split(sep)
|
|
187
216
|
typed_list = []
|
|
@@ -213,7 +242,7 @@ def select_items_from_list(
|
|
|
213
242
|
sep: Optional[str] = None,
|
|
214
243
|
quit_str: str = "q",
|
|
215
244
|
opposite: bool = False,
|
|
216
|
-
no_selection_value=None,
|
|
245
|
+
no_selection_value: int = None,
|
|
217
246
|
return_value: bool = True,
|
|
218
247
|
) -> List:
|
|
219
248
|
"""Input validation against a list.
|
|
@@ -225,11 +254,11 @@ def select_items_from_list(
|
|
|
225
254
|
n_choices (int): the number of choices allowed
|
|
226
255
|
quit_str (str): The string to cancel validation and exit. Defaults to "q".
|
|
227
256
|
opposite (bool): return everything BUT the user selection
|
|
228
|
-
no_selection_value (
|
|
257
|
+
no_selection_value (int, optional): value to indicate no selection wanted from the user
|
|
229
258
|
return_value (bool): if true, return the value, otherwise return the indicies of selections
|
|
230
259
|
|
|
231
260
|
Returns:
|
|
232
|
-
Optiona[List]:
|
|
261
|
+
Optiona[List]: quit_str if user quits, [] if user selects nothing, otherwise a list of the users selections are returned.
|
|
233
262
|
"""
|
|
234
263
|
tries = 0
|
|
235
264
|
low = 0
|
|
@@ -260,10 +289,12 @@ def select_items_from_list(
|
|
|
260
289
|
inp = get_input_list(
|
|
261
290
|
prompt + f"{range_display} {no_selection_prompt}",
|
|
262
291
|
sep,
|
|
292
|
+
quit_str=quit_str,
|
|
263
293
|
out_type=int,
|
|
264
294
|
)
|
|
265
|
-
if inp
|
|
266
|
-
return
|
|
295
|
+
if inp == quit_str:
|
|
296
|
+
return quit_str
|
|
297
|
+
|
|
267
298
|
if len(inp) == 0:
|
|
268
299
|
logger.info("You selected nothing.")
|
|
269
300
|
return []
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
version = "0.2.4"
|
|
@@ -5,6 +5,8 @@ from io import StringIO
|
|
|
5
5
|
import os, sys, shutil
|
|
6
6
|
import pytest
|
|
7
7
|
|
|
8
|
+
# cli_inputs defined vectors that a user would
|
|
9
|
+
# input as they navigate through the app
|
|
8
10
|
cli_inputs = [
|
|
9
11
|
[
|
|
10
12
|
"jolene", # user enters jolene
|
|
@@ -13,32 +15,56 @@ cli_inputs = [
|
|
|
13
15
|
"0", # user selects first song
|
|
14
16
|
"i", # save to local itunes folder
|
|
15
17
|
"q", # user quits
|
|
18
|
+
"y", # user quits via y/n selection
|
|
16
19
|
],
|
|
17
20
|
[
|
|
18
21
|
"jolene", # user enters jolene
|
|
19
22
|
"0", # user selects first song
|
|
23
|
+
"https://s" # user enter invalid download url
|
|
20
24
|
"https://www.youtube.com/watch?v=Ixrje2rXLMA", # user opts to direct download
|
|
21
25
|
"l", # save locally
|
|
22
26
|
"q", # user quits
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"billy joel", # user enters billy joel
|
|
26
|
-
"-1", # user selects continue without properties
|
|
27
|
-
"", # user opts to search youtube
|
|
27
|
+
"n", # user selects to continue
|
|
28
|
+
"billy", # user searches billy
|
|
28
29
|
"0", # user selects first song
|
|
29
|
-
"
|
|
30
|
-
"q", # user quits
|
|
30
|
+
"q", # user quits to main menu
|
|
31
|
+
"q", # user quits app
|
|
32
|
+
"q", # user confirms quit
|
|
31
33
|
],
|
|
32
34
|
[
|
|
33
|
-
"john
|
|
34
|
-
"", # user
|
|
35
|
-
"0", # user continues by selecting property 0
|
|
35
|
+
"billy joel; john lennon", # user enters billy joel and john lennon
|
|
36
|
+
"-1", # user selects continue without properties
|
|
36
37
|
"", # user opts to search youtube
|
|
37
38
|
"", # user hits enter by accident
|
|
38
39
|
"800", # user enters invalid input
|
|
39
40
|
"0", # user selects first song
|
|
40
41
|
"l", # user selects save locally
|
|
41
|
-
"q", # user quits
|
|
42
|
+
"q", # user accidentally quits
|
|
43
|
+
"y", # user selects to resume
|
|
44
|
+
"0", # user selects property 0
|
|
45
|
+
"q", # user quits to main menu
|
|
46
|
+
"q", # user quits app
|
|
47
|
+
"y", # user quits app
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"album", # user enters album mode
|
|
51
|
+
"billy joel the stranger", # user enters billy joel
|
|
52
|
+
"", # validation for empty input
|
|
53
|
+
"-5", # user enters invalid value
|
|
54
|
+
"0", # user selects album 0
|
|
55
|
+
"-1", # user selects keep all songs
|
|
56
|
+
"-5", # user enters invalid input
|
|
57
|
+
"0", # user selects song property 0 for first song
|
|
58
|
+
"", # user hits enter to search youtube
|
|
59
|
+
"0", # user selects song 0
|
|
60
|
+
"l", # save locally
|
|
61
|
+
"q", # select quit
|
|
62
|
+
"y", # continue with queued songs
|
|
63
|
+
"0", # select property 0
|
|
64
|
+
"q", # quit queued songs
|
|
65
|
+
"n", # do not continue queue
|
|
66
|
+
"q", # quit application
|
|
67
|
+
"y", # set yes to are you sure message
|
|
42
68
|
],
|
|
43
69
|
]
|
|
44
70
|
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
from songbirdcli import helpers
|
|
4
|
+
from songbirdcore.models import modes, itunes_api
|
|
5
|
+
from songbirdcore import itunes
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.mark.parametrize(
|
|
9
|
+
"search_variable,mode,lookup,inp,expected",
|
|
10
|
+
[
|
|
11
|
+
# album style parameters, select no album
|
|
12
|
+
("billy joel", modes.Modes.ALBUM, False, ["-1"], False),
|
|
13
|
+
# enable lookup mode, passing in a collection id (billy joel the stranger)
|
|
14
|
+
# enter an invalid input, and then no selection
|
|
15
|
+
("158617952", modes.Modes.SONG, True, ["500", "-1"], False),
|
|
16
|
+
# test traditional songmode
|
|
17
|
+
("jolene", modes.Modes.SONG, False, ["500", "-1"], False),
|
|
18
|
+
],
|
|
19
|
+
)
|
|
20
|
+
def test_parse_itunes_search_api_no_selection(
|
|
21
|
+
monkeypatch, search_variable, mode, lookup, inp, expected
|
|
22
|
+
):
|
|
23
|
+
"""test parse_itunes_search_api for a variety of parameters
|
|
24
|
+
and no_selection_value enabled.
|
|
25
|
+
"""
|
|
26
|
+
inputs_iter = iter(inp)
|
|
27
|
+
monkeypatch.setattr("builtins.input", lambda _: next(inputs_iter))
|
|
28
|
+
result = helpers.parse_itunes_search_api(
|
|
29
|
+
search_variable=search_variable,
|
|
30
|
+
mode=mode,
|
|
31
|
+
limit=5,
|
|
32
|
+
lookup=lookup,
|
|
33
|
+
no_selection_value=-1,
|
|
34
|
+
)
|
|
35
|
+
assert result == expected
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.mark.parametrize(
|
|
39
|
+
"search_variable,mode,lookup,inp,expected_type",
|
|
40
|
+
[
|
|
41
|
+
# album style parameters, select no album
|
|
42
|
+
(
|
|
43
|
+
"billy joel",
|
|
44
|
+
modes.Modes.ALBUM,
|
|
45
|
+
False,
|
|
46
|
+
["-1", "500", "0"],
|
|
47
|
+
itunes_api.ItunesApiAlbumKeys,
|
|
48
|
+
),
|
|
49
|
+
# enable lookup mode, passing in a collection id (billy joel the stranger)
|
|
50
|
+
("158617952", modes.Modes.SONG, True, ["0"], itunes_api.ItunesApiSongModel),
|
|
51
|
+
("jolene", modes.Modes.SONG, False, ["0"], itunes_api.ItunesApiSongModel),
|
|
52
|
+
],
|
|
53
|
+
)
|
|
54
|
+
def test_parse_itunes_search_api(
|
|
55
|
+
monkeypatch, search_variable, mode, lookup, inp, expected_type
|
|
56
|
+
):
|
|
57
|
+
"""tests parse_itunes_search_api() for a variety of parameters
|
|
58
|
+
and no_selection_value set to None
|
|
59
|
+
"""
|
|
60
|
+
inputs_iter = iter(inp)
|
|
61
|
+
monkeypatch.setattr("builtins.input", lambda _: next(inputs_iter))
|
|
62
|
+
result = helpers.parse_itunes_search_api(
|
|
63
|
+
search_variable=search_variable,
|
|
64
|
+
mode=mode,
|
|
65
|
+
limit=5,
|
|
66
|
+
lookup=lookup,
|
|
67
|
+
no_selection_value=None,
|
|
68
|
+
)
|
|
69
|
+
assert isinstance(result, expected_type)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@pytest.mark.parametrize(
|
|
73
|
+
"query,input_sequence,expected",
|
|
74
|
+
(
|
|
75
|
+
# get billy joel the stranger, and remove the first three songs
|
|
76
|
+
("the stranger billy joel", ["0", "1 2 3"], list),
|
|
77
|
+
# same as above, but specify no selection
|
|
78
|
+
("the stranger billy joel", ["0", "-1"], list),
|
|
79
|
+
# same as above, but quit
|
|
80
|
+
("the stranger billy joel", ["0", "q"], str),
|
|
81
|
+
),
|
|
82
|
+
)
|
|
83
|
+
def test_launch_album_mode(monkeypatch, query, input_sequence, expected):
|
|
84
|
+
inputs_iter = iter(input_sequence)
|
|
85
|
+
monkeypatch.setattr("builtins.input", lambda _: next(inputs_iter))
|
|
86
|
+
result = helpers.launch_album_mode(artist_album_string=query)
|
|
87
|
+
assert isinstance(result, expected)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@pytest.mark.parametrize(
|
|
91
|
+
"inp,out_type,choices,expected",
|
|
92
|
+
[
|
|
93
|
+
# ok with number casting to string
|
|
94
|
+
(0, str, None, "0"),
|
|
95
|
+
("q", str, ["y", "n"], "q"),
|
|
96
|
+
("y", str, ["y", "n"], "y"),
|
|
97
|
+
("", str, None, ""),
|
|
98
|
+
(0, int, [0, 1], 0),
|
|
99
|
+
(2, int, None, 2),
|
|
100
|
+
("q", int, None, "q"),
|
|
101
|
+
],
|
|
102
|
+
)
|
|
103
|
+
def test_get_input(monkeypatch, inp, out_type, choices, expected):
|
|
104
|
+
"""test get_input() function"""
|
|
105
|
+
# simulate user entering invalid inputs, and then one of the choices
|
|
106
|
+
monkeypatch.setattr("builtins.input", lambda _: inp)
|
|
107
|
+
output = helpers.get_input(
|
|
108
|
+
"hello", out_type=out_type, quit_str="q", choices=choices
|
|
109
|
+
)
|
|
110
|
+
assert output == expected
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@pytest.mark.parametrize(
|
|
114
|
+
"out_type,quit_str,inp,expected",
|
|
115
|
+
[
|
|
116
|
+
(str, "q", "hi;there", ["hi", "there"]),
|
|
117
|
+
(int, "q", "q", "q"),
|
|
118
|
+
],
|
|
119
|
+
)
|
|
120
|
+
def test_get_input_list(monkeypatch, out_type, quit_str: str, inp: str, expected):
|
|
121
|
+
monkeypatch.setattr("builtins.input", lambda _: inp)
|
|
122
|
+
|
|
123
|
+
inputs = helpers.get_input_list(prompt="hello", sep=";", out_type=str, quit_str="q")
|
|
124
|
+
|
|
125
|
+
assert inputs == expected
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@pytest.mark.parametrize(
|
|
129
|
+
"lyst,n_choices,opposite,no_selection_value,return_value,inp,expected",
|
|
130
|
+
[
|
|
131
|
+
(["option1", "option2"], 2, False, None, True, "0;1", ["option1", "option2"]),
|
|
132
|
+
# same as above, but with opposite enabled
|
|
133
|
+
(["option1", "option2"], 2, True, None, True, "0;1", []),
|
|
134
|
+
# same as above, but user uses -1 to quit
|
|
135
|
+
(["option1", "option2"], 2, False, -1, True, "-1", []),
|
|
136
|
+
],
|
|
137
|
+
)
|
|
138
|
+
def test_select_items_from_list(
|
|
139
|
+
monkeypatch,
|
|
140
|
+
lyst: List,
|
|
141
|
+
n_choices: int,
|
|
142
|
+
opposite: Optional[bool],
|
|
143
|
+
no_selection_value,
|
|
144
|
+
return_value: Optional[bool],
|
|
145
|
+
inp,
|
|
146
|
+
expected,
|
|
147
|
+
):
|
|
148
|
+
"""parametrized tester for select_items_from_list()"""
|
|
149
|
+
monkeypatch.setattr("builtins.input", lambda _: inp)
|
|
150
|
+
|
|
151
|
+
results = helpers.select_items_from_list(
|
|
152
|
+
"hi",
|
|
153
|
+
lyst=lyst,
|
|
154
|
+
n_choices=n_choices,
|
|
155
|
+
sep=";",
|
|
156
|
+
quit_str="q",
|
|
157
|
+
opposite=opposite,
|
|
158
|
+
no_selection_value=no_selection_value,
|
|
159
|
+
return_value=return_value,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
assert results == expected
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
version = "0.2.3"
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
from typing import List, Optional
|
|
3
|
-
from songbirdcli import helpers
|
|
4
|
-
from songbirdcore.models import modes
|
|
5
|
-
from songbirdcore import itunes
|
|
6
|
-
|
|
7
|
-
@pytest.fixture()
|
|
8
|
-
def parse_itunes_search_api(monkeypatch):
|
|
9
|
-
return itunes.query_api(
|
|
10
|
-
"jolene",
|
|
11
|
-
mode=modes.Modes.SONG,
|
|
12
|
-
limit=10
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
@pytest.mark.parametrize(
|
|
16
|
-
"query,input_sequence",
|
|
17
|
-
(
|
|
18
|
-
# get billy joel the stranger, and remove the first three songs
|
|
19
|
-
("the stranger billy joel", ["0", "1 2 3"]),
|
|
20
|
-
# same as above, but specify no selection
|
|
21
|
-
("the stranger billy joel", ["0", "-1"]),
|
|
22
|
-
# same as above, but quit
|
|
23
|
-
("the stranger billy joel", ["0", "q"])
|
|
24
|
-
)
|
|
25
|
-
)
|
|
26
|
-
def test_launch_album_mode(monkeypatch, query, input_sequence):
|
|
27
|
-
monkeypatch.setattr("builtins.input", lambda _: next(iter(input_sequence)))
|
|
28
|
-
result = helpers.launch_album_mode(artist_album_string=query)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@pytest.mark.parametrize(
|
|
32
|
-
"inp,out_type,choices,expected",
|
|
33
|
-
[
|
|
34
|
-
# ok with number casting to string
|
|
35
|
-
(0, str, None, "0"),
|
|
36
|
-
("q", str, ["y", "n"], None),
|
|
37
|
-
("y", str, ["y", "n"], "y"),
|
|
38
|
-
("", str, None, ""),
|
|
39
|
-
(0, int, [0, 1], 0),
|
|
40
|
-
(2, int, None, 2),
|
|
41
|
-
("q", int, None, None),
|
|
42
|
-
],
|
|
43
|
-
)
|
|
44
|
-
def test_get_input(monkeypatch, inp, out_type, choices, expected):
|
|
45
|
-
"""test get_input() function"""
|
|
46
|
-
# simulate user entering invalid inputs, and then one of the choices
|
|
47
|
-
monkeypatch.setattr("builtins.input", lambda _: inp)
|
|
48
|
-
output = helpers.get_input(
|
|
49
|
-
"hello", out_type=out_type, quit_str="q", choices=choices
|
|
50
|
-
)
|
|
51
|
-
assert output == expected
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@pytest.mark.parametrize(
|
|
55
|
-
"out_type,quit_str,inp,expected",
|
|
56
|
-
[
|
|
57
|
-
(str,"q","hi;there",["hi","there"]),
|
|
58
|
-
(int,"q","q",None),
|
|
59
|
-
]
|
|
60
|
-
)
|
|
61
|
-
def test_get_input_list(monkeypatch, out_type, quit_str: str, inp: str, expected):
|
|
62
|
-
monkeypatch.setattr("builtins.input", lambda _: "q")
|
|
63
|
-
|
|
64
|
-
inputs = helpers.get_input_list(prompt="hello", sep=";", out_type=str, quit_str="q")
|
|
65
|
-
|
|
66
|
-
assert inputs == None
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
@pytest.mark.parametrize(
|
|
70
|
-
"lyst,n_choices,opposite,no_selection_value,return_value,inp,expected",
|
|
71
|
-
[
|
|
72
|
-
(["option1", "option2"], 2, False, None, True, "0;1", ["option1", "option2"]),
|
|
73
|
-
# same as above, but with opposite enabled
|
|
74
|
-
(["option1", "option2"], 2, True, None, True, "0;1", []),
|
|
75
|
-
# same as above, but user uses -1 to quit
|
|
76
|
-
(["option1", "option2"], 2, False, -1, True, "-1", []),
|
|
77
|
-
]
|
|
78
|
-
)
|
|
79
|
-
def test_select_items_from_list(
|
|
80
|
-
monkeypatch,
|
|
81
|
-
lyst: List,
|
|
82
|
-
n_choices: int,
|
|
83
|
-
opposite: Optional[bool],
|
|
84
|
-
no_selection_value,
|
|
85
|
-
return_value: Optional[bool],
|
|
86
|
-
inp,
|
|
87
|
-
expected
|
|
88
|
-
):
|
|
89
|
-
"""parametrized tester for select_items_from_list()"""
|
|
90
|
-
monkeypatch.setattr("builtins.input", lambda _: inp)
|
|
91
|
-
|
|
92
|
-
results = helpers.select_items_from_list(
|
|
93
|
-
"hi",
|
|
94
|
-
lyst=lyst,
|
|
95
|
-
n_choices=n_choices,
|
|
96
|
-
sep=";",
|
|
97
|
-
quit_str="q",
|
|
98
|
-
opposite=opposite,
|
|
99
|
-
no_selection_value=no_selection_value,
|
|
100
|
-
return_value=return_value,
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
assert results == expected
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|