songbirdcli 0.2.0__py3-none-any.whl
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/cli.py +402 -0
- songbirdcli/helpers.py +275 -0
- songbirdcli/requirements.txt +53 -0
- songbirdcli/requirements.txt.blank +3 -0
- songbirdcli/settings.py +103 -0
- songbirdcli/version.py +1 -0
- songbirdcli-0.2.0.dist-info/LICENSE +21 -0
- songbirdcli-0.2.0.dist-info/METADATA +319 -0
- songbirdcli-0.2.0.dist-info/RECORD +12 -0
- songbirdcli-0.2.0.dist-info/WHEEL +5 -0
- songbirdcli-0.2.0.dist-info/top_level.txt +2 -0
- tests/unit/test_cli.py +63 -0
songbirdcli/cli.py
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import datetime
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Optional, List
|
|
5
|
+
import os, sys, shutil
|
|
6
|
+
|
|
7
|
+
from songbirdcli import settings
|
|
8
|
+
from songbirdcli import helpers
|
|
9
|
+
from songbirdcli import version
|
|
10
|
+
|
|
11
|
+
from songbirdcore.models import modes, itunes_api
|
|
12
|
+
from songbirdcore import itunes
|
|
13
|
+
from songbirdcore import youtube
|
|
14
|
+
from songbirdcore import gdrive
|
|
15
|
+
from songbirdcore import common
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def validate_essentials(config: settings.SongbirdCliConfig):
|
|
21
|
+
success = True
|
|
22
|
+
if config.gdrive_enabled:
|
|
23
|
+
if not os.path.exists(config.get_gdrive_folder_path()):
|
|
24
|
+
logger.error(
|
|
25
|
+
f"You must create the path {config.get_gdrive_folder_path()} \
|
|
26
|
+
to use google drive feature! If using docker, use bind mounts. See README for more info."
|
|
27
|
+
)
|
|
28
|
+
success = False
|
|
29
|
+
if not os.path.exists(
|
|
30
|
+
os.path.join(config.get_gdrive_folder_path(), "credentials.json")
|
|
31
|
+
):
|
|
32
|
+
logger.error(
|
|
33
|
+
f"You must provide a credentials.json file inside of {config.get_gdrive_folder_path()} to use gdrive feature!"
|
|
34
|
+
)
|
|
35
|
+
success = False
|
|
36
|
+
|
|
37
|
+
if config.itunes_enabled:
|
|
38
|
+
if not os.path.exists(config.get_itunes_folder_path()):
|
|
39
|
+
logger.error(
|
|
40
|
+
f"You must create the path {config.get_itunes_folder_path()} \
|
|
41
|
+
to use itunes feature! If using docker, use bind mounts. See README for more info."
|
|
42
|
+
)
|
|
43
|
+
success = False
|
|
44
|
+
|
|
45
|
+
if not os.path.exists(config.get_itunes_lib_path()):
|
|
46
|
+
logger.error(
|
|
47
|
+
f"You must create the path {config.get_itunes_lib_path()} \
|
|
48
|
+
to use itunes feature! If using docker, use bind mounts. See README for more info."
|
|
49
|
+
)
|
|
50
|
+
success = False
|
|
51
|
+
|
|
52
|
+
if not os.path.exists(config.get_data_path()):
|
|
53
|
+
logger.error(
|
|
54
|
+
f"At minimum, you need path {config.get_data_path()} configured to run the app. If using docker, use bind mounts. See README."
|
|
55
|
+
)
|
|
56
|
+
return success
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def initialize_dirs(dirs: List[str]):
|
|
60
|
+
"""Initialize the apps directories
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
dirs (List[str]): the list of directories to initialize (create)
|
|
64
|
+
"""
|
|
65
|
+
for _dir in dirs:
|
|
66
|
+
if not os.path.exists(_dir):
|
|
67
|
+
logger.info(f"Creating dir: {_dir}")
|
|
68
|
+
os.mkdir(_dir)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def resolve_mode(
|
|
72
|
+
inp: str, current_mode: modes.Modes = modes.Modes.SONG
|
|
73
|
+
) -> Optional[modes.Modes]:
|
|
74
|
+
"""Resolve the mode based on a given mode, against the current mode
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
inp (str): user input
|
|
78
|
+
current_mode (modes.Modes, optional): The current mode of the app. Defaults to modes.Modes.SONG.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
Optional[modes.Modes]: return the mode if the current mode needs to be changed, otherwise return nothing.
|
|
82
|
+
"""
|
|
83
|
+
try:
|
|
84
|
+
mode = modes.Modes(inp)
|
|
85
|
+
if mode != current_mode:
|
|
86
|
+
logger.info(f"Switched to {mode.value} mode!")
|
|
87
|
+
return mode
|
|
88
|
+
else:
|
|
89
|
+
return None
|
|
90
|
+
except ValueError:
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def run_download_process(
|
|
95
|
+
file_path_no_format: str,
|
|
96
|
+
youtube_home_url: str,
|
|
97
|
+
youtube_search_url: str,
|
|
98
|
+
youtube_query_payload: dict,
|
|
99
|
+
file_format: str,
|
|
100
|
+
render_timeout: int,
|
|
101
|
+
render_wait: float,
|
|
102
|
+
render_retries: int,
|
|
103
|
+
render_sleep: int,
|
|
104
|
+
) -> str:
|
|
105
|
+
"""Download a song from youtube.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
file_name (str): the absolute path of where to save the file
|
|
109
|
+
youtube_home_url (str): the url to youtube's home page
|
|
110
|
+
youtube_search_url (str): the search url for youtube
|
|
111
|
+
youtube_query_payload (str): the query payload for youtube's search api
|
|
112
|
+
file_format (str): desired file format
|
|
113
|
+
render_timeout (int): amount of time before abandoning a render
|
|
114
|
+
render_wait (float): the amount of time before attempting a render
|
|
115
|
+
render_retries (int): the number of retries for a render
|
|
116
|
+
render_sleep (int): the amount of time to wait after rendering
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
str: the path on disk that the file was saved to. None if the download fails.
|
|
120
|
+
"""
|
|
121
|
+
# obtain video selection from user
|
|
122
|
+
video_url = helpers.get_input(
|
|
123
|
+
prompt=f"Enter a URL, or hit enter to use '{youtube_query_payload}' as a query to youtube: ",
|
|
124
|
+
out_type=str,
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
if video_url is None:
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
# empty str (enter) query youtube
|
|
131
|
+
if video_url == "":
|
|
132
|
+
link_list, links = youtube.get_video_links(
|
|
133
|
+
youtube_home_url,
|
|
134
|
+
youtube_search_url,
|
|
135
|
+
youtube_query_payload,
|
|
136
|
+
render_timeout,
|
|
137
|
+
render_wait,
|
|
138
|
+
render_retries,
|
|
139
|
+
render_sleep,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
if link_list is None:
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
# Allow user to select the link they want to download
|
|
146
|
+
common.pretty_lst_printer(link_list)
|
|
147
|
+
|
|
148
|
+
video_selection_idx = helpers.select_items_from_list(
|
|
149
|
+
"Select the song you wish to download!",
|
|
150
|
+
link_list,
|
|
151
|
+
1,
|
|
152
|
+
return_value=False,
|
|
153
|
+
)
|
|
154
|
+
if video_selection_idx is None or len(video_selection_idx) == 0:
|
|
155
|
+
return None
|
|
156
|
+
|
|
157
|
+
video_url = youtube_home_url + links[video_selection_idx[0]].attrs["href"]
|
|
158
|
+
# Process the download, and save locally
|
|
159
|
+
return youtube.run_download(video_url, file_path_no_format, file_format)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def run_for_song(
|
|
163
|
+
config: settings.SongbirdCliConfig,
|
|
164
|
+
song_name: str,
|
|
165
|
+
song_properties: Optional[itunes_api.ItunesApiSongModel],
|
|
166
|
+
):
|
|
167
|
+
"""Run a cycle of the application given a song.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
config (settings.SongbirdConfig): the songbird config
|
|
171
|
+
song_name (str): the name of the song to run the app for
|
|
172
|
+
song_properties (Optional[itunes_api.ItunesApiSongModel]): optionally include song properties. Including these skips the itunes api parser.
|
|
173
|
+
"""
|
|
174
|
+
logger.info(f"Searching for: {song_name}")
|
|
175
|
+
file_itunes = []
|
|
176
|
+
file_gdrive = []
|
|
177
|
+
# itunes craves m4a formatted files. Otherwise we use mp3s, as were civilized people.
|
|
178
|
+
file_format = config.file_format if not config.itunes_enabled else "m4a"
|
|
179
|
+
# check if song exists locally in dump folder
|
|
180
|
+
file_local = common.find_file(config.get_local_folder_path(), f"*{song_name}*")
|
|
181
|
+
# check if song exists locally in itunes
|
|
182
|
+
if config.itunes_enabled:
|
|
183
|
+
file_itunes = itunes.itunes_lib_search(config.get_itunes_lib_path(), song_name)
|
|
184
|
+
# check if song exists locally in google drive folder
|
|
185
|
+
if config.gdrive_enabled:
|
|
186
|
+
file_gdrive = common.find_file(
|
|
187
|
+
config.get_gdrive_folder_path(), f"*{song_name}*"
|
|
188
|
+
)
|
|
189
|
+
# if any of the above, ask user if they want to download anyways
|
|
190
|
+
files = file_local + file_itunes + file_gdrive
|
|
191
|
+
if len(files) > 0:
|
|
192
|
+
logger.info("Found the following similar files:")
|
|
193
|
+
common.pretty_lst_printer(files)
|
|
194
|
+
inp = helpers.get_input(
|
|
195
|
+
"Do you want to proceed with download anyway?", choices=["y", "n"]
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
if inp is None or inp == "n":
|
|
199
|
+
return
|
|
200
|
+
|
|
201
|
+
if song_properties is None:
|
|
202
|
+
song_properties = helpers.parse_itunes_search_api(song_name, modes.Modes.SONG)
|
|
203
|
+
|
|
204
|
+
if song_properties is None:
|
|
205
|
+
return
|
|
206
|
+
file_path_no_format = os.path.join(config.get_local_folder_path(), song_name)
|
|
207
|
+
file_path = file_path_no_format + "." + file_format
|
|
208
|
+
downloaded_file_path = None
|
|
209
|
+
# make sure file doesnt already exist
|
|
210
|
+
duped_filepath = common.fname_duper(file_path, config.fname_dup_limit, 1, "_dup")
|
|
211
|
+
if duped_filepath is None:
|
|
212
|
+
return
|
|
213
|
+
if duped_filepath != file_path:
|
|
214
|
+
logger.warning(
|
|
215
|
+
f"Duplicate file(s) already exist for base file {file_path}, so I generated a new filename {duped_filepath}!"
|
|
216
|
+
)
|
|
217
|
+
file_path_no_format = os.path.splitext(duped_filepath)[0]
|
|
218
|
+
file_path = duped_filepath
|
|
219
|
+
# run the youtube downloader
|
|
220
|
+
if config.youtube_dl_enabled:
|
|
221
|
+
payload = config.youtube_searchform_payload
|
|
222
|
+
if song_properties != []:
|
|
223
|
+
payload[config.youtube_search_tag] = (
|
|
224
|
+
f"{song_properties.artistName} {song_properties.trackName}"
|
|
225
|
+
)
|
|
226
|
+
else:
|
|
227
|
+
payload[config.youtube_search_tag] = song_name
|
|
228
|
+
|
|
229
|
+
downloaded_file_path = run_download_process(
|
|
230
|
+
file_path_no_format=file_path_no_format,
|
|
231
|
+
youtube_home_url=config.youtube_home_url,
|
|
232
|
+
youtube_search_url=config.youtube_search_url,
|
|
233
|
+
youtube_query_payload=payload,
|
|
234
|
+
file_format=file_format,
|
|
235
|
+
render_timeout=config.youtube_render_timeout,
|
|
236
|
+
render_wait=config.youtube_render_wait,
|
|
237
|
+
render_retries=config.youtube_render_retries,
|
|
238
|
+
render_sleep=config.youtube_render_sleep,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
if downloaded_file_path is None:
|
|
242
|
+
return
|
|
243
|
+
# tag file
|
|
244
|
+
tag_successful = False
|
|
245
|
+
if file_format == "mp3":
|
|
246
|
+
tag_successful = itunes.mp3ID3Tagger(downloaded_file_path, song_properties)
|
|
247
|
+
elif file_format == "m4a":
|
|
248
|
+
tag_successful = itunes.m4a_tagger(downloaded_file_path, song_properties)
|
|
249
|
+
else:
|
|
250
|
+
logger.warn(
|
|
251
|
+
"You've specified a file format that is has no tagger supported yet. Saving file without tags."
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
# provide user with choices for where to save their file to.
|
|
255
|
+
save_prompt_base = "Would you like to save your file to"
|
|
256
|
+
if config.itunes_enabled and config.gdrive_enabled:
|
|
257
|
+
inp = helpers.get_input(
|
|
258
|
+
save_prompt_base + " gdrive (g), itunes (i), or locally (l)",
|
|
259
|
+
out_type=str,
|
|
260
|
+
choices=["g", "i", "l"],
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
if config.itunes_enabled and not config.gdrive_enabled:
|
|
264
|
+
inp = helpers.get_input(
|
|
265
|
+
save_prompt_base + " itunes (i), or locally (l)",
|
|
266
|
+
out_type=str,
|
|
267
|
+
choices=["i", "l"],
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
if not config.itunes_enabled and config.gdrive_enabled:
|
|
271
|
+
inp = helpers.get_input(
|
|
272
|
+
save_prompt_base + " gdrive (g), or locally (l)",
|
|
273
|
+
out_type=str,
|
|
274
|
+
choices=["g", "l"],
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
if not config.itunes_enabled and not config.gdrive_enabled:
|
|
278
|
+
inp = "l"
|
|
279
|
+
|
|
280
|
+
if inp is None:
|
|
281
|
+
return
|
|
282
|
+
|
|
283
|
+
if inp == "i":
|
|
284
|
+
msg = "Saved to itunes"
|
|
285
|
+
itunes_dest_path = common.fname_duper(
|
|
286
|
+
os.path.join(
|
|
287
|
+
config.get_itunes_folder_path(), os.path.basename(downloaded_file_path)
|
|
288
|
+
),
|
|
289
|
+
config.fname_dup_limit,
|
|
290
|
+
1,
|
|
291
|
+
config.fname_dup_key,
|
|
292
|
+
)
|
|
293
|
+
if itunes_dest_path is None:
|
|
294
|
+
return None
|
|
295
|
+
shutil.move(downloaded_file_path, itunes_dest_path)
|
|
296
|
+
elif inp == "g":
|
|
297
|
+
msg = "Saved to gdrive"
|
|
298
|
+
gdrive_dest_path = common.fname_duper(
|
|
299
|
+
os.path.join(
|
|
300
|
+
config.get_gdrive_folder_path(), os.path.basename(downloaded_file_path)
|
|
301
|
+
),
|
|
302
|
+
config.fname_dup_limit,
|
|
303
|
+
1,
|
|
304
|
+
config.fname_dup_key,
|
|
305
|
+
)
|
|
306
|
+
if gdrive_dest_path is None:
|
|
307
|
+
return None
|
|
308
|
+
shutil.move(downloaded_file_path, gdrive_dest_path)
|
|
309
|
+
# If running in a container, we need to provide a bind address
|
|
310
|
+
# Users are expected to run the container with hostname songbird (--hostname songbird)
|
|
311
|
+
bind_addr = None
|
|
312
|
+
if not config.run_local:
|
|
313
|
+
bind_addr = "songbird"
|
|
314
|
+
gdrive.save_song(
|
|
315
|
+
config.gdrive_folder_id,
|
|
316
|
+
credentials_path=os.path.join(
|
|
317
|
+
config.get_gdrive_folder_path(), "credentials.json"
|
|
318
|
+
),
|
|
319
|
+
token_path=os.path.join(config.get_gdrive_folder_path(), "token.json"),
|
|
320
|
+
song_name=f"{song_name}.{file_format}",
|
|
321
|
+
song_path=str(gdrive_dest_path),
|
|
322
|
+
auth_port=config.gdrive_auth_port,
|
|
323
|
+
bind_addr=bind_addr,
|
|
324
|
+
)
|
|
325
|
+
else:
|
|
326
|
+
msg = "Saved locally."
|
|
327
|
+
|
|
328
|
+
logger.info(msg)
|
|
329
|
+
return True
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def run(config: settings.SongbirdCliConfig):
|
|
333
|
+
try:
|
|
334
|
+
common.set_logger_config_globally(log_level=config.log_level)
|
|
335
|
+
common.name_plate(entries=[f"--cli {config.version}"])
|
|
336
|
+
# only need folders on OS if we are running locally. Otherwise user is expected to provied folders
|
|
337
|
+
# via bind mounts
|
|
338
|
+
if config.run_local:
|
|
339
|
+
initialize_dirs(
|
|
340
|
+
[
|
|
341
|
+
config.get_data_path(),
|
|
342
|
+
config.get_itunes_folder_path(),
|
|
343
|
+
config.get_itunes_lib_path(),
|
|
344
|
+
config.get_gdrive_folder_path(),
|
|
345
|
+
config.get_local_folder_path(),
|
|
346
|
+
]
|
|
347
|
+
)
|
|
348
|
+
if not validate_essentials(config):
|
|
349
|
+
return None
|
|
350
|
+
current_mode = modes.Modes.SONG
|
|
351
|
+
while True:
|
|
352
|
+
logger.info(f"---Songbird Main Menu v{config.version}🐦---")
|
|
353
|
+
|
|
354
|
+
song_properties = None
|
|
355
|
+
album_song_properties = None
|
|
356
|
+
# launch album mode to collect songs
|
|
357
|
+
if current_mode == modes.Modes.ALBUM:
|
|
358
|
+
album_name = helpers.get_input(f"Enter an album name.", out_type=str)
|
|
359
|
+
# quit condition
|
|
360
|
+
if album_name is None:
|
|
361
|
+
break
|
|
362
|
+
mode = resolve_mode(album_name, current_mode=current_mode)
|
|
363
|
+
# detect mode change and return to main menu
|
|
364
|
+
if mode is not None:
|
|
365
|
+
current_mode = mode
|
|
366
|
+
continue
|
|
367
|
+
|
|
368
|
+
album_song_properties = launch_album_mode(album_name)
|
|
369
|
+
if album_song_properties is None:
|
|
370
|
+
break
|
|
371
|
+
|
|
372
|
+
songs = [song.trackName for song in album_song_properties]
|
|
373
|
+
elif current_mode == modes.Modes.SONG:
|
|
374
|
+
songs = helpers.get_input_list(
|
|
375
|
+
"Please input song(s), separated by ';'. E.g. song1; song2; song3.",
|
|
376
|
+
out_type=str,
|
|
377
|
+
sep="; ",
|
|
378
|
+
)
|
|
379
|
+
# quit condition
|
|
380
|
+
if songs is None:
|
|
381
|
+
break
|
|
382
|
+
mode = resolve_mode(songs[0], current_mode=current_mode)
|
|
383
|
+
# detect mode change and return to main menu
|
|
384
|
+
if mode is not None:
|
|
385
|
+
current_mode = mode
|
|
386
|
+
continue
|
|
387
|
+
|
|
388
|
+
logger.info(f"Searching for songs: {songs}")
|
|
389
|
+
for i, song in enumerate(songs):
|
|
390
|
+
if album_song_properties is not None:
|
|
391
|
+
song_properties = album_song_properties[i]
|
|
392
|
+
success = run_for_song(config, song, song_properties)
|
|
393
|
+
|
|
394
|
+
except KeyboardInterrupt as e:
|
|
395
|
+
logger.info("\nReceived keyboard interrupt :o")
|
|
396
|
+
|
|
397
|
+
logger.info("Shutting down!")
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
if __name__ == "__main__":
|
|
401
|
+
config = settings.SongbirdCliConfig(version=version.version)
|
|
402
|
+
run(config=config)
|
songbirdcli/helpers.py
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"""
|
|
2
|
+
helpers.py module for helping with parsing inputs
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Optional, List
|
|
6
|
+
from songbirdcore import common, itunes
|
|
7
|
+
from songbirdcore.models import modes, itunes_api
|
|
8
|
+
import logging
|
|
9
|
+
|
|
10
|
+
logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def launch_album_mode(artist_album_string=""):
|
|
14
|
+
"""
|
|
15
|
+
Args:
|
|
16
|
+
artist_album_string (str): the album/artist to search for.
|
|
17
|
+
Returns: the list of song properties gathered from the search.
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
while True:
|
|
21
|
+
album_props = parse_itunes_search_api(
|
|
22
|
+
search_variable=artist_album_string, mode=modes.Modes.ALBUM, lookup=False
|
|
23
|
+
)
|
|
24
|
+
# check if user quit
|
|
25
|
+
if album_props is None:
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
# get the song matching the album metadata
|
|
29
|
+
songs_in_album_props = itunes.query_api(
|
|
30
|
+
search_variable=album_props.collectionId, # get list of songs for chosen album
|
|
31
|
+
limit=album_props.trackCount,
|
|
32
|
+
mode=modes.Modes.SONG,
|
|
33
|
+
lookup=True,
|
|
34
|
+
)
|
|
35
|
+
if songs_in_album_props == None:
|
|
36
|
+
logger.error("Sorry. Cant seem to find any details for this album!")
|
|
37
|
+
|
|
38
|
+
songs_in_album_props = remove_songs_selected(
|
|
39
|
+
song_properties_list=songs_in_album_props
|
|
40
|
+
)
|
|
41
|
+
if songs_in_album_props is None:
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
return songs_in_album_props
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# entity is usually song for searching songs
|
|
48
|
+
def parse_itunes_search_api(
|
|
49
|
+
search_variable: str, mode: modes.Modes, limit: int = 20, lookup: bool = False
|
|
50
|
+
) -> itunes_api.ItunesApiSongModel:
|
|
51
|
+
parsed_results_list = itunes.query_api(search_variable, limit, mode, lookup=lookup)
|
|
52
|
+
|
|
53
|
+
# Present results to user
|
|
54
|
+
common.pretty_list_of_basemodel_printer(parsed_results_list)
|
|
55
|
+
logger.info("Searched for: %s" % (search_variable))
|
|
56
|
+
# Only one item can be selected
|
|
57
|
+
user_selection = select_items_from_list(
|
|
58
|
+
"Select the number for the properties you want",
|
|
59
|
+
parsed_results_list,
|
|
60
|
+
1,
|
|
61
|
+
no_selection_value=-1,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# user has quit
|
|
65
|
+
if user_selection is None:
|
|
66
|
+
logger.info("Quitting.")
|
|
67
|
+
return
|
|
68
|
+
if len(user_selection) == 0:
|
|
69
|
+
logger.info("Continuing without properties.")
|
|
70
|
+
return []
|
|
71
|
+
|
|
72
|
+
print(f"Selected item: ")
|
|
73
|
+
for k, v in user_selection[0].model_dump().items():
|
|
74
|
+
print(" - %s : %s" % (k, v))
|
|
75
|
+
|
|
76
|
+
return user_selection[0]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def remove_songs_selected(song_properties_list):
|
|
80
|
+
common.pretty_list_of_basemodel_printer(song_properties_list)
|
|
81
|
+
input_string = "Enter song id's (1 4 5 etc.) you dont want from this album"
|
|
82
|
+
user_input = select_items_from_list(
|
|
83
|
+
input_string,
|
|
84
|
+
song_properties_list,
|
|
85
|
+
n_choices=len(song_properties_list) - 1,
|
|
86
|
+
sep=" ",
|
|
87
|
+
opposite=True,
|
|
88
|
+
no_selection_value=-1,
|
|
89
|
+
)
|
|
90
|
+
# user has quit
|
|
91
|
+
if user_input == None:
|
|
92
|
+
return None
|
|
93
|
+
# user selects all songs
|
|
94
|
+
if user_input == []:
|
|
95
|
+
return song_properties_list
|
|
96
|
+
# otherwise, user gets the processed list with their items removed
|
|
97
|
+
return user_input
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def get_input(prompt: str, out_type=None, quit_str="q", choices: Optional[List] = None):
|
|
101
|
+
"""Given a prompt, get input from stdio and perform basic type validation
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
prompt (str): the prompt to use
|
|
105
|
+
out_type (type, optional): expected type for input. Defaults to None.
|
|
106
|
+
quit_str (str, optional): a character to signify quitting from the input gatherer. Defaults to "q".
|
|
107
|
+
choices (Optional[List], optional): valid character options to parse as input. Defaults to None.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
type: the type, or None if quit or invalid type received.
|
|
111
|
+
"""
|
|
112
|
+
while True:
|
|
113
|
+
built_prompt = prompt
|
|
114
|
+
if choices is not None:
|
|
115
|
+
built_prompt += f" , choices=({choices})"
|
|
116
|
+
built_prompt += " ['q' quits]: "
|
|
117
|
+
inp = input(built_prompt)
|
|
118
|
+
if inp == quit_str:
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
if out_type is not None:
|
|
122
|
+
try:
|
|
123
|
+
typed = out_type(inp)
|
|
124
|
+
|
|
125
|
+
except ValueError as e:
|
|
126
|
+
logger.error(
|
|
127
|
+
"Invalid type received. Try again, inputting an '{out_type}'"
|
|
128
|
+
)
|
|
129
|
+
else:
|
|
130
|
+
typed = inp
|
|
131
|
+
|
|
132
|
+
if choices is None:
|
|
133
|
+
return typed
|
|
134
|
+
|
|
135
|
+
if typed not in choices:
|
|
136
|
+
logger.error(f"You must input one of {choices}")
|
|
137
|
+
else:
|
|
138
|
+
return typed
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def get_input_list(prompt: str, sep: str, out_type=int, quit_str="q") -> List[int]:
|
|
142
|
+
"""Take an input prompt, and generate a typed list from it, validating against the given input type.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
prompt (str): the prompt to display to the user
|
|
146
|
+
sep (str): the expected separator in the input list
|
|
147
|
+
out_type (_type_, optional): The expected data type. Defaults to int.
|
|
148
|
+
|
|
149
|
+
Raises:
|
|
150
|
+
ValueError: If the input does not match the given type.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
Optional[List[int]]: the typed list, or None if user quit
|
|
154
|
+
"""
|
|
155
|
+
while True:
|
|
156
|
+
inp = input(prompt + f" ['{quit_str}' quits]: ")
|
|
157
|
+
if inp == quit_str:
|
|
158
|
+
return None
|
|
159
|
+
|
|
160
|
+
str_list = inp.split(sep)
|
|
161
|
+
typed_list = []
|
|
162
|
+
for item in str_list:
|
|
163
|
+
type_check_passed = True
|
|
164
|
+
try:
|
|
165
|
+
typed_inp = out_type(item)
|
|
166
|
+
except ValueError as e:
|
|
167
|
+
logger.error(
|
|
168
|
+
f"Invalid input {inp} recieved, expected list with types: {out_type}, separated by '{sep}'"
|
|
169
|
+
)
|
|
170
|
+
type_check_passed = False
|
|
171
|
+
break
|
|
172
|
+
|
|
173
|
+
typed_list.append(out_type(item))
|
|
174
|
+
|
|
175
|
+
# only exit loop if the type check has passed
|
|
176
|
+
if type_check_passed:
|
|
177
|
+
break
|
|
178
|
+
return typed_list
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def select_items_from_list(
|
|
182
|
+
prompt: str,
|
|
183
|
+
lyst: List,
|
|
184
|
+
n_choices: int,
|
|
185
|
+
sep: Optional[str] = None,
|
|
186
|
+
quit_str: str = "q",
|
|
187
|
+
opposite: bool = False,
|
|
188
|
+
no_selection_value=None,
|
|
189
|
+
return_value: bool = True,
|
|
190
|
+
) -> List:
|
|
191
|
+
"""Input validation against a list.
|
|
192
|
+
|
|
193
|
+
Args:
|
|
194
|
+
prompt (str): prompt to display to user
|
|
195
|
+
sep (str): the separator for the input
|
|
196
|
+
lyst (List): the list to perform input validation against
|
|
197
|
+
n_choices (int): the number of choices allowed
|
|
198
|
+
quit_str (str): The string to cancel validation and exit. Defaults to "q".
|
|
199
|
+
opposite (bool): return everything BUT the user selection
|
|
200
|
+
no_selection_value (any): value to indicate no selection wanted from the user
|
|
201
|
+
return_value (bool): if true, return the value, otherwise return the indicies of selections
|
|
202
|
+
Returns Optiona[List]: None if user quits, [] if user selects nothing, otherwise a list of the users selections are returned.
|
|
203
|
+
"""
|
|
204
|
+
tries = 0
|
|
205
|
+
low = 0
|
|
206
|
+
high = len(lyst) - 1
|
|
207
|
+
# provide useful ranges to user
|
|
208
|
+
if high == -1:
|
|
209
|
+
range_display = ""
|
|
210
|
+
elif high == 0:
|
|
211
|
+
range_display = f" (choose {high})"
|
|
212
|
+
else:
|
|
213
|
+
range_display = f" (choose {low} to {high}) "
|
|
214
|
+
# fill appropriate prompt based on opposite feature
|
|
215
|
+
if opposite:
|
|
216
|
+
opposite_prompt = " select all"
|
|
217
|
+
else:
|
|
218
|
+
opposite_prompt = " continue without selection"
|
|
219
|
+
|
|
220
|
+
if no_selection_value is None:
|
|
221
|
+
no_selection_prompt = ""
|
|
222
|
+
else:
|
|
223
|
+
no_selection_prompt = f"[{no_selection_value} {opposite_prompt}]"
|
|
224
|
+
|
|
225
|
+
while True:
|
|
226
|
+
tries += 1
|
|
227
|
+
if tries > 5:
|
|
228
|
+
logger.info(f"Wtf man. {tries} tries so far? Just get it right!")
|
|
229
|
+
# get user input
|
|
230
|
+
inp = get_input_list(
|
|
231
|
+
prompt + f"{range_display} {no_selection_prompt}",
|
|
232
|
+
sep,
|
|
233
|
+
out_type=int,
|
|
234
|
+
)
|
|
235
|
+
if inp is None:
|
|
236
|
+
return None
|
|
237
|
+
if len(inp) == 0:
|
|
238
|
+
logger.info("You selected nothing.")
|
|
239
|
+
return []
|
|
240
|
+
# verify if the value of the input is the selection value
|
|
241
|
+
if inp[0] == no_selection_value:
|
|
242
|
+
return []
|
|
243
|
+
# if user has entered too many choices, try again!!
|
|
244
|
+
if len(inp) > n_choices:
|
|
245
|
+
logger.error(f"You're only allowed {n_choices} here. Try again.")
|
|
246
|
+
continue
|
|
247
|
+
# user has passed validation, now check the values are reasonable
|
|
248
|
+
|
|
249
|
+
boundary_check_passed = True
|
|
250
|
+
for val in inp:
|
|
251
|
+
if val > high or val < low:
|
|
252
|
+
logger.error(
|
|
253
|
+
f"Sorry, the value {val} is out of bounds. Please enter within the interval [{low}, {high}]"
|
|
254
|
+
)
|
|
255
|
+
boundary_check_passed = False
|
|
256
|
+
if not boundary_check_passed:
|
|
257
|
+
continue
|
|
258
|
+
|
|
259
|
+
# if user gets passed all of above, actually select values or indices at this point, and return
|
|
260
|
+
if not opposite:
|
|
261
|
+
result = []
|
|
262
|
+
for val in inp:
|
|
263
|
+
if return_value:
|
|
264
|
+
result.append(lyst[val])
|
|
265
|
+
else:
|
|
266
|
+
result.append(val)
|
|
267
|
+
else:
|
|
268
|
+
result = []
|
|
269
|
+
for idx in range(len(lyst)):
|
|
270
|
+
if idx not in inp:
|
|
271
|
+
if return_value:
|
|
272
|
+
result.append(lyst[idx])
|
|
273
|
+
else:
|
|
274
|
+
result.append(idx)
|
|
275
|
+
return result
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
annotated-types==0.6.0
|
|
2
|
+
beautifulsoup4==4.12.3
|
|
3
|
+
Brotli==1.1.0
|
|
4
|
+
cachetools==5.3.3
|
|
5
|
+
certifi==2024.2.2
|
|
6
|
+
charset-normalizer==3.3.2
|
|
7
|
+
coverage==5.5
|
|
8
|
+
cssselect==1.2.0
|
|
9
|
+
deprecation==2.1.0
|
|
10
|
+
eyed3==0.9.7
|
|
11
|
+
fake-useragent==1.5.1
|
|
12
|
+
filetype==1.2.0
|
|
13
|
+
google-api-core==2.18.0
|
|
14
|
+
google-api-python-client==2.126.0
|
|
15
|
+
google-auth==2.29.0
|
|
16
|
+
google-auth-httplib2==0.2.0
|
|
17
|
+
google-auth-oauthlib==1.2.0
|
|
18
|
+
googleapis-common-protos==1.63.0
|
|
19
|
+
greenlet==3.0.3
|
|
20
|
+
httplib2==0.22.0
|
|
21
|
+
idna==3.7
|
|
22
|
+
lxml==5.2.1
|
|
23
|
+
lxml_html_clean==0.1.1
|
|
24
|
+
mutagen==1.47.0
|
|
25
|
+
oauthlib==3.2.2
|
|
26
|
+
packaging==24.0
|
|
27
|
+
parse==1.20.1
|
|
28
|
+
playwright==1.43.0
|
|
29
|
+
proto-plus==1.23.0
|
|
30
|
+
protobuf==4.25.3
|
|
31
|
+
pyasn1==0.6.0
|
|
32
|
+
pyasn1_modules==0.4.0
|
|
33
|
+
pycryptodomex==3.20.0
|
|
34
|
+
pydantic==2.7.0
|
|
35
|
+
pydantic-settings==2.2.1
|
|
36
|
+
pydantic_core==2.18.1
|
|
37
|
+
pyee==11.1.0
|
|
38
|
+
pyparsing==3.1.2
|
|
39
|
+
pyquery==2.0.0
|
|
40
|
+
python-dotenv==1.0.1
|
|
41
|
+
requests==2.31.0
|
|
42
|
+
requests-htmlc==0.0.4
|
|
43
|
+
requests-oauthlib==2.0.0
|
|
44
|
+
rsa==4.9
|
|
45
|
+
songbirdcore==0.0.5
|
|
46
|
+
soupsieve==2.5
|
|
47
|
+
toml==0.10.2
|
|
48
|
+
typing_extensions==4.11.0
|
|
49
|
+
uritemplate==4.1.1
|
|
50
|
+
urllib3==2.2.1
|
|
51
|
+
w3lib==2.1.2
|
|
52
|
+
websockets==12.0
|
|
53
|
+
yt-dlp==2024.4.9
|
songbirdcli/settings.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
import pydantic
|
|
7
|
+
from pydantic import BaseModel, Field, field_validator, ValidationInfo
|
|
8
|
+
from pydantic_settings import BaseSettings
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SongbirdCliConfig(BaseSettings):
|
|
13
|
+
"""Configuration using .env file or defaults declared in here"""
|
|
14
|
+
|
|
15
|
+
version: str = ""
|
|
16
|
+
log_level: str = "INFO"
|
|
17
|
+
run_local: bool = False
|
|
18
|
+
|
|
19
|
+
root_path: str = sys.path[0]
|
|
20
|
+
|
|
21
|
+
@field_validator("root_path")
|
|
22
|
+
def validate_root_path(cls, value: str, info: ValidationInfo):
|
|
23
|
+
# if run_local is true, return the raw value obtained for root_path
|
|
24
|
+
if info.data["run_local"]:
|
|
25
|
+
return value
|
|
26
|
+
# if run_local is false, assume we are running in docker, and use '/app' as root_path
|
|
27
|
+
# this preserves back-wards compatible behavior for initial songbird installations
|
|
28
|
+
else:
|
|
29
|
+
return os.path.join(os.sep, "app")
|
|
30
|
+
|
|
31
|
+
data_path: str = "data"
|
|
32
|
+
itunes_search_api_base_url: str = "https://itunes.apple.com/search"
|
|
33
|
+
itunes_enabled: bool = True
|
|
34
|
+
itunes_folder_path: Optional[str] = "itunesauto"
|
|
35
|
+
itunes_lib_path: Optional[str] = "ituneslib"
|
|
36
|
+
gdrive_enabled: bool = True
|
|
37
|
+
gdrive_folder_path: Optional[str] = "gdrive"
|
|
38
|
+
gdrive_folder_id: Optional[str] = ""
|
|
39
|
+
gdrive_auth_port: int = 8080
|
|
40
|
+
local_song_store_str: str = "dump"
|
|
41
|
+
fname_dup_key: str = "_dup"
|
|
42
|
+
fname_dup_limit: int = 8
|
|
43
|
+
youtube_dl_enabled: bool = True
|
|
44
|
+
youtube_render_timeout: int = 20
|
|
45
|
+
youtube_render_wait: float = 0.2
|
|
46
|
+
youtube_render_sleep: int = 1
|
|
47
|
+
youtube_render_retries: int = 3
|
|
48
|
+
youtube_home_url: str = "https://www.youtube.com"
|
|
49
|
+
youtube_search_url: str = "https://www.youtube.com/results"
|
|
50
|
+
youtube_search_tag: str = "search_query"
|
|
51
|
+
youtube_searchform_payload: dict = {youtube_search_tag: ""}
|
|
52
|
+
youtube_dl_retries: int = 3
|
|
53
|
+
file_format: str = "mp3"
|
|
54
|
+
|
|
55
|
+
class ConfigDict:
|
|
56
|
+
env = os.getenv("ENV", "dev")
|
|
57
|
+
config_path = os.path.join(os.path.dirname(sys.path[0]), f"{env}.env")
|
|
58
|
+
env_file = config_path
|
|
59
|
+
env_file_encoding = "utf-8"
|
|
60
|
+
|
|
61
|
+
def get_data_path(self):
|
|
62
|
+
return os.path.join(self.root_path, self.data_path)
|
|
63
|
+
|
|
64
|
+
def get_local_folder_path(self):
|
|
65
|
+
return os.path.join(self.get_data_path(), self.local_song_store_str)
|
|
66
|
+
|
|
67
|
+
def get_itunes_folder_path(self):
|
|
68
|
+
"""If you run the app locally, configure the itunes path as an absolute path. Otherwise, the program will
|
|
69
|
+
use the local container storage and assume to be running in a docker container.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
str: the path to where itunes destined songs should live
|
|
73
|
+
"""
|
|
74
|
+
if self.run_local:
|
|
75
|
+
return self.itunes_folder_path
|
|
76
|
+
return os.path.join(self.get_data_path(), self.itunes_folder_path)
|
|
77
|
+
|
|
78
|
+
def get_itunes_lib_path(self):
|
|
79
|
+
"""If you run the app locally, configure the itunes path as an absolute path. Otherwise, the program will
|
|
80
|
+
use the local container storage and assume to be running in a docker container.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
str: the path to where itunes destined songs should live
|
|
84
|
+
"""
|
|
85
|
+
if self.run_local:
|
|
86
|
+
return self.itunes_lib_path
|
|
87
|
+
return os.path.join(self.get_data_path(), self.itunes_lib_path)
|
|
88
|
+
|
|
89
|
+
def get_gdrive_folder_path(self):
|
|
90
|
+
return os.path.join(self.get_data_path(), self.gdrive_folder_path)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class SongbirdServerConfig(BaseSettings):
|
|
94
|
+
"""Configuration using .env file or defaults declared in here"""
|
|
95
|
+
|
|
96
|
+
version: str = ""
|
|
97
|
+
run_local: bool = False
|
|
98
|
+
root_path: str = sys.path[0]
|
|
99
|
+
|
|
100
|
+
class ConfigDict:
|
|
101
|
+
config_path = os.path.join(os.path.dirname(sys.path[0]), ".env")
|
|
102
|
+
env_file = config_path
|
|
103
|
+
env_file_encoding = "utf-8"
|
songbirdcli/version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
version = "0.2.0"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Christian Boin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: songbirdcli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Songbird's cli.
|
|
5
|
+
Author: Christian Boin
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: annotated-types ==0.6.0
|
|
10
|
+
Requires-Dist: beautifulsoup4 ==4.12.3
|
|
11
|
+
Requires-Dist: Brotli ==1.1.0
|
|
12
|
+
Requires-Dist: cachetools ==5.3.3
|
|
13
|
+
Requires-Dist: certifi ==2024.2.2
|
|
14
|
+
Requires-Dist: charset-normalizer ==3.3.2
|
|
15
|
+
Requires-Dist: coverage ==5.5
|
|
16
|
+
Requires-Dist: cssselect ==1.2.0
|
|
17
|
+
Requires-Dist: deprecation ==2.1.0
|
|
18
|
+
Requires-Dist: eyed3 ==0.9.7
|
|
19
|
+
Requires-Dist: fake-useragent ==1.5.1
|
|
20
|
+
Requires-Dist: filetype ==1.2.0
|
|
21
|
+
Requires-Dist: google-api-core ==2.18.0
|
|
22
|
+
Requires-Dist: google-api-python-client ==2.126.0
|
|
23
|
+
Requires-Dist: google-auth ==2.29.0
|
|
24
|
+
Requires-Dist: google-auth-httplib2 ==0.2.0
|
|
25
|
+
Requires-Dist: google-auth-oauthlib ==1.2.0
|
|
26
|
+
Requires-Dist: googleapis-common-protos ==1.63.0
|
|
27
|
+
Requires-Dist: greenlet ==3.0.3
|
|
28
|
+
Requires-Dist: httplib2 ==0.22.0
|
|
29
|
+
Requires-Dist: idna ==3.7
|
|
30
|
+
Requires-Dist: lxml ==5.2.1
|
|
31
|
+
Requires-Dist: lxml-html-clean ==0.1.1
|
|
32
|
+
Requires-Dist: mutagen ==1.47.0
|
|
33
|
+
Requires-Dist: oauthlib ==3.2.2
|
|
34
|
+
Requires-Dist: packaging ==24.0
|
|
35
|
+
Requires-Dist: parse ==1.20.1
|
|
36
|
+
Requires-Dist: playwright ==1.43.0
|
|
37
|
+
Requires-Dist: proto-plus ==1.23.0
|
|
38
|
+
Requires-Dist: protobuf ==4.25.3
|
|
39
|
+
Requires-Dist: pyasn1 ==0.6.0
|
|
40
|
+
Requires-Dist: pyasn1-modules ==0.4.0
|
|
41
|
+
Requires-Dist: pycryptodomex ==3.20.0
|
|
42
|
+
Requires-Dist: pydantic ==2.7.0
|
|
43
|
+
Requires-Dist: pydantic-settings ==2.2.1
|
|
44
|
+
Requires-Dist: pydantic-core ==2.18.1
|
|
45
|
+
Requires-Dist: pyee ==11.1.0
|
|
46
|
+
Requires-Dist: pyparsing ==3.1.2
|
|
47
|
+
Requires-Dist: pyquery ==2.0.0
|
|
48
|
+
Requires-Dist: python-dotenv ==1.0.1
|
|
49
|
+
Requires-Dist: requests ==2.31.0
|
|
50
|
+
Requires-Dist: requests-htmlc ==0.0.4
|
|
51
|
+
Requires-Dist: requests-oauthlib ==2.0.0
|
|
52
|
+
Requires-Dist: rsa ==4.9
|
|
53
|
+
Requires-Dist: songbirdcore ==0.0.5
|
|
54
|
+
Requires-Dist: soupsieve ==2.5
|
|
55
|
+
Requires-Dist: toml ==0.10.2
|
|
56
|
+
Requires-Dist: typing-extensions ==4.11.0
|
|
57
|
+
Requires-Dist: uritemplate ==4.1.1
|
|
58
|
+
Requires-Dist: urllib3 ==2.2.1
|
|
59
|
+
Requires-Dist: w3lib ==2.1.2
|
|
60
|
+
Requires-Dist: websockets ==12.0
|
|
61
|
+
Requires-Dist: yt-dlp ==2024.4.9
|
|
62
|
+
Provides-Extra: dev
|
|
63
|
+
Requires-Dist: black ; extra == 'dev'
|
|
64
|
+
Requires-Dist: click ; extra == 'dev'
|
|
65
|
+
Requires-Dist: isort ; extra == 'dev'
|
|
66
|
+
Requires-Dist: pytest ; extra == 'dev'
|
|
67
|
+
Requires-Dist: pytest-cov ; extra == 'dev'
|
|
68
|
+
Provides-Extra: package
|
|
69
|
+
Requires-Dist: build ; extra == 'package'
|
|
70
|
+
Requires-Dist: twine ; extra == 'package'
|
|
71
|
+
|
|
72
|
+
# songbirdcli 🐦
|
|
73
|
+
|
|
74
|
+
Music downloading client featuring mp3 or m4a tagging.
|
|
75
|
+
|
|
76
|
+
## Install via Docker
|
|
77
|
+
|
|
78
|
+
To run the app via docker, you will require:
|
|
79
|
+
1. docker: https://docs.docker.com/get-docker/
|
|
80
|
+
|
|
81
|
+
Note: to be gung-ho, add `--pull always` to any of the
|
|
82
|
+
below commands to always receive the latest
|
|
83
|
+
and greatest images.
|
|
84
|
+
|
|
85
|
+
First, initialize your docker volumes
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
make volumesinit
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Note: bash or zsh aliases are provided below,
|
|
92
|
+
assuming you clone songbird into your home directory
|
|
93
|
+
into `~/proj/cboin1996/`.
|
|
94
|
+
|
|
95
|
+
### Itunes and Google Drive Integration
|
|
96
|
+
|
|
97
|
+
Macos:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
alias songbirdgi="docker run -it --env-file "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/docker.env \
|
|
101
|
+
-v "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/data/dump:/app/data/dump \
|
|
102
|
+
-v "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/data/gdrive:/app/data/gdrive \
|
|
103
|
+
-v "${HOME}"/Music/iTunes/iTunes\ Media/Automatically\ Add\ to\ Music.localized:/app/data/itunesauto \
|
|
104
|
+
-v "${HOME}"/Music/Itunes/Itunes\ Media/Music:/app/data/ituneslib \
|
|
105
|
+
-p 8080:8080 \
|
|
106
|
+
--hostname songbird \
|
|
107
|
+
--pull always \
|
|
108
|
+
cboin/songbird:latest"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Windows:
|
|
112
|
+
|
|
113
|
+
Install windows sub-system for linux and setup the below alias:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
alias songbirdgi="docker run -it --env-file "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/docker.env \
|
|
117
|
+
-v "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/data/dump:/app/data/dump \
|
|
118
|
+
-v "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/data/gdrive:/app/data/gdrive \
|
|
119
|
+
-v /mnt/c/Users/*/Music/iTunes/iTunes\ Media/Automatically\ Add\ to\ Music:/app/data/itunesauto \
|
|
120
|
+
-v /mnt/c/Users/*/Music/iTunes/iTunes\ Media/Music:/app/data/ituneslib \
|
|
121
|
+
-p 8080:8080 \
|
|
122
|
+
--hostname songbird \
|
|
123
|
+
--pull always \
|
|
124
|
+
cboin/songbird:latest"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Minimal configuration
|
|
128
|
+
|
|
129
|
+
By default, the app assumes itunes is installed. At minimum,
|
|
130
|
+
create a `.env` file with to run without either.
|
|
131
|
+
|
|
132
|
+
In addition, you need a folder to store local files in.
|
|
133
|
+
This folder will be passed as a volume mount to the
|
|
134
|
+
dockerized app, as above in `-v "app/data/dump":"app/data/dump",
|
|
135
|
+
and is initialized automatically when running
|
|
136
|
+
`make volumesinit`.
|
|
137
|
+
|
|
138
|
+
```.env
|
|
139
|
+
ITUNES_ENABLED=False
|
|
140
|
+
GDRIVE_ENABLED=False
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Gdrive Only
|
|
144
|
+
|
|
145
|
+
Create a .env file at the root of the project containing:
|
|
146
|
+
```.env
|
|
147
|
+
ITUNES_ENABLED=false
|
|
148
|
+
GDRIVE_FOLDER_ID=foo
|
|
149
|
+
```
|
|
150
|
+
Replace the `foo` with the folder id of your google drive
|
|
151
|
+
folder. This is found
|
|
152
|
+
in the url inside the folder when open in googledrive.
|
|
153
|
+
|
|
154
|
+
`E.x: https://drive.google.com/drive/folders/foo`
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
Follow https://developers.google.com/drive/api/quickstart/python,
|
|
158
|
+
and place the `credentials.json` file at the `app/data/gdrive`
|
|
159
|
+
folder at the root of the project.
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
alias songbirdg="docker run -it --env-file "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/docker.env \
|
|
163
|
+
-v "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/data/dump:/app/data/dump \
|
|
164
|
+
-v "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/data/gdrive:/app/data/gdrive \
|
|
165
|
+
-p 8080:8080 \
|
|
166
|
+
--hostname songbird \
|
|
167
|
+
--pull always \
|
|
168
|
+
cboin/songbird:latest"
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Itunes Only
|
|
172
|
+
|
|
173
|
+
```.env
|
|
174
|
+
GDRIVE_ENABLED=false
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Run
|
|
178
|
+
|
|
179
|
+
Macos:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
alias songbirdi="docker run -it --env-file "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/docker.env \
|
|
183
|
+
-v "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/data/dump:/app/data/dump \
|
|
184
|
+
-v "${HOME}"/Music/iTunes/iTunes\ Media/Automatically\ Add\ to\ Music.localized:/app/data/itunesauto \
|
|
185
|
+
-v "${HOME}"/Music/Itunes/Itunes\ Media/Music:/app/data/ituneslib \
|
|
186
|
+
--pull always \
|
|
187
|
+
cboin/songbird:latest"
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Windows:
|
|
191
|
+
|
|
192
|
+
Install windows sub-system for linux and
|
|
193
|
+
setup the below alias:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
alias songbirdi="docker run -it --env-file "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/docker.env \
|
|
197
|
+
-v "${HOME}"/proj/cboin1996/songbird/songbirdcli/songbirdcli/data/dump:/app/data/dump \
|
|
198
|
+
-v /mnt/c/Users/*/Music/iTunes/iTunes\ Media/Automatically\ Add\ to\ Music:/app/data/itunesauto \
|
|
199
|
+
-v /mnt/c/Users/*/Music/iTunes/iTunes\ Media/Music:/app/data/ituneslib \
|
|
200
|
+
-p 8080:8080 \
|
|
201
|
+
--hostname songbird \
|
|
202
|
+
--pull always \
|
|
203
|
+
cboin/songbird:latest"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Install as Package
|
|
207
|
+
|
|
208
|
+
To use songbirdcli as a python package, use
|
|
209
|
+
```bash
|
|
210
|
+
pip install songbirdcli
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
See [tests](./tests/unit/test_cli.py) for an example
|
|
214
|
+
of configuring and running songbirdcli as a package.
|
|
215
|
+
|
|
216
|
+
## Development
|
|
217
|
+
|
|
218
|
+
To run the application locally, you can use a vscode debugger.
|
|
219
|
+
You should also setup a .env file
|
|
220
|
+
with the parameter `RUN_LOCAL=True`.
|
|
221
|
+
|
|
222
|
+
### Requirements
|
|
223
|
+
|
|
224
|
+
1. Clone [songbirdcore](https://github.com/cboin1996/songbirdcore.git)
|
|
225
|
+
adjacent to this project.
|
|
226
|
+
|
|
227
|
+
2. Next, run
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
export ENV=dev
|
|
231
|
+
make setup
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
3. Follow the outputted instructions from `make setup`.
|
|
235
|
+
|
|
236
|
+
4. Next, run:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
make requirements
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Note: the above command performs an editable install of `songbirdcore`**
|
|
243
|
+
|
|
244
|
+
This allows you to edit `songbirdcore` locally,
|
|
245
|
+
and have those changes directly
|
|
246
|
+
integrated with this application when developing.
|
|
247
|
+
To install the official stable version use
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
pip install songbirdcore
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Debug CLI
|
|
254
|
+
|
|
255
|
+
Vscode debugger can be configured to run the `cli.py` file
|
|
256
|
+
with the following `.vscode/launch.json` file
|
|
257
|
+
|
|
258
|
+
```json
|
|
259
|
+
{
|
|
260
|
+
"configurations": [
|
|
261
|
+
{
|
|
262
|
+
"name": "Python: Current File",
|
|
263
|
+
"type": "python",
|
|
264
|
+
"request": "launch",
|
|
265
|
+
"program": "./songbirdcli/cli.py",
|
|
266
|
+
"console": "integratedTerminal",
|
|
267
|
+
"justMyCode": true,
|
|
268
|
+
"envFile": "./dev.env"
|
|
269
|
+
},
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Alternatively, you can simply run the app directly with
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
python3 songbirdcli/cli.py
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Linting
|
|
281
|
+
|
|
282
|
+
To lint the app, run
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
make lint
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Configuration
|
|
289
|
+
|
|
290
|
+
The following table summarizes the configurable parameters for the app,
|
|
291
|
+
these can be setup in a `.env` file at the root of the project,
|
|
292
|
+
and passed to docker with `--env-file .env`.
|
|
293
|
+
|
|
294
|
+
| Variable | Type | Default | Description |
|
|
295
|
+
| -------------------------- | ------------- | --------------------------------- | -------------------------------------------------------------------------- |
|
|
296
|
+
| RUN_LOCAL | bool | False | Whether to run the app locally, or configure it for running in a container |
|
|
297
|
+
| ROOT_PATH | str | sys.path[0] | The root path to the project folder |
|
|
298
|
+
| DATA_PATH | str | "data" | The name of the folder where app data is stored on disk |
|
|
299
|
+
| ITUNES_SEARCH_API_BASE_URL | str | "https://itunes.apple.com/search" | The itunes search api root url |
|
|
300
|
+
| ITUNES_ENABLED | bool | True | Whether to run with itunes integration enabled |
|
|
301
|
+
| ITUNES_FOLDER_PATH | Optional[str] | "itunesauto" | The path to the itunes automatically add folder |
|
|
302
|
+
| ITUNES_LIB_PATH | Optional[str] | "ituneslib" | The path to the itunes library folder |
|
|
303
|
+
| GDRIVE_ENABLED | bool | True | Whether to run with google drive integration |
|
|
304
|
+
| GDRIVE_FOLDER_PATH | Optional[str] | "gdrive" | Local folder for storing files destined for uploading to google drive |
|
|
305
|
+
| GDRIVE_FOLDER_ID | Optional[str] | "" | The folder id of a cloud google drive folder |
|
|
306
|
+
| GDRIVE_AUTH_PORT | int | 8080 | The port for oauth setup for google drive integration |
|
|
307
|
+
| LOCAL_SONG_STORE_STR | str | "dump" | Where songs are stored locally |
|
|
308
|
+
| FNAME_DUP_KEY | str | "_dup" | The key for naming duplicate files |
|
|
309
|
+
| FNAME_DUP_LIMIT | str | 8 | The limit of duplicate files matching the `FNAME_DUP_KEY` |
|
|
310
|
+
| YOUTUBE_DL_ENABLED | bool | True | Whether to enable the youtube download feature |
|
|
311
|
+
| YOUTUBE_RENDER_TIMEOUT | int | 20 | The time before giving up on the render of youtube's search page |
|
|
312
|
+
| YOUTUBE_RENDER_WAIT | float | 0.2 | The wait time before starting a render of the youtube search page |
|
|
313
|
+
| YOUTUBE_RENDER_SLEEP | int | 1 | The wait time after initial render of youtube |
|
|
314
|
+
| YOUTUBE_HOME_URL | str | "https://www.youtube.com" | |
|
|
315
|
+
| YOUTUBE_SEARCH_URL | str | "https://www.youtube.com/results" | |
|
|
316
|
+
| YOUTUBE_SEARCH_TAG | str | "search_query" | The html tag on youtubes home page linking to the html search form |
|
|
317
|
+
| YOUTUBE_SEARCHFORM_PAYLOAD | dict | {youtube_search_tag: ""} | the payload for performing a youtube search |
|
|
318
|
+
| YOUTUBE_DL_RETRIES | int | 3 | number of retries for youtube-dlp before giving up on a download |
|
|
319
|
+
| FILE_FORMAT | str | "mp3" | This field is overwritten to m4a if itunes is enabled. |
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
songbirdcli/cli.py,sha256=3--k_VAXD8a4dE7K-ggQgRTTSbW1kvPgvH3c35ikvKk,14631
|
|
2
|
+
songbirdcli/helpers.py,sha256=igBJfcvXY7VCzjKN2KCtP_aBjOt86MMexhPPeYFUOZ0,9058
|
|
3
|
+
songbirdcli/requirements.txt,sha256=4_jpg-mVbn6kUA7hm5qGppoOJAbMtGrzYyjtCpdZDaI,1000
|
|
4
|
+
songbirdcli/requirements.txt.blank,sha256=1OL6HCs83AfULbKesGNazLQo4wZS4sz61QOJIdtOZFE,39
|
|
5
|
+
songbirdcli/settings.py,sha256=eJQF2vDaSI6VNlxC9pwszUolYrhrMEBHzUn4EukZUKM,3739
|
|
6
|
+
songbirdcli/version.py,sha256=XQVhijSHeIVMVzY2S4fY9BKxV2XHSTr9VVHsYltGPvQ,18
|
|
7
|
+
tests/unit/test_cli.py,sha256=3yci6PNIb8RCLJlMzkHhliQzBh1lWQHqB7uCX_KxzrE,2011
|
|
8
|
+
songbirdcli-0.2.0.dist-info/LICENSE,sha256=wra9E2UbAAmYAXJniYe8xog9e9ezJ0uBbkxg3F1u04s,1071
|
|
9
|
+
songbirdcli-0.2.0.dist-info/METADATA,sha256=l8txN6G4WiviPrOoRVns-AJtDiu39DjvC-H2TyJG81c,12324
|
|
10
|
+
songbirdcli-0.2.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
11
|
+
songbirdcli-0.2.0.dist-info/top_level.txt,sha256=rW_SitIP1BbB7yEDpk7LStn6DF3U-pedbx3fYTrlTm8,18
|
|
12
|
+
songbirdcli-0.2.0.dist-info/RECORD,,
|
tests/unit/test_cli.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from songbirdcli import cli
|
|
2
|
+
from songbirdcli import settings
|
|
3
|
+
from songbirdcli import version
|
|
4
|
+
from io import StringIO
|
|
5
|
+
import os, sys, shutil
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture()
|
|
10
|
+
def load_config(monkeypatch, request):
|
|
11
|
+
# below are parametrized vectorized inputs that
|
|
12
|
+
# a user would enter if downloading a song
|
|
13
|
+
inputs = iter(request.param)
|
|
14
|
+
monkeypatch.setattr("builtins.input", lambda _: next(inputs))
|
|
15
|
+
# create tests-output folder
|
|
16
|
+
tests_data_folder = os.path.join(sys.path[0], "tests-output")
|
|
17
|
+
if not os.path.exists(tests_data_folder):
|
|
18
|
+
os.mkdir(tests_data_folder)
|
|
19
|
+
config = settings.SongbirdCliConfig(
|
|
20
|
+
version=version.version,
|
|
21
|
+
root_path=tests_data_folder,
|
|
22
|
+
gdrive_enabled=False,
|
|
23
|
+
itunes_enabled=True,
|
|
24
|
+
# we set these paths explicitly so that test
|
|
25
|
+
# directories are used
|
|
26
|
+
# in real world scenario, these values
|
|
27
|
+
# could be set to the actual itunes folders
|
|
28
|
+
# as long as run_local is true.
|
|
29
|
+
itunes_lib_path=os.path.join(tests_data_folder, "mock-itunes-lib"),
|
|
30
|
+
itunes_folder_path=os.path.join(tests_data_folder, "mock-itunes-auto-folder"),
|
|
31
|
+
run_local=True,
|
|
32
|
+
)
|
|
33
|
+
# yield setup to test
|
|
34
|
+
yield config
|
|
35
|
+
|
|
36
|
+
# test cleanup
|
|
37
|
+
shutil.rmtree(tests_data_folder)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.mark.parametrize(
|
|
41
|
+
"load_config",
|
|
42
|
+
[
|
|
43
|
+
[
|
|
44
|
+
"jolene", # user enters jolene
|
|
45
|
+
"0", # user selects first song
|
|
46
|
+
"", # user opts to search youtube
|
|
47
|
+
"0", # user selects first song
|
|
48
|
+
"i", # save to local itunes folder
|
|
49
|
+
"q", # user quits
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
"jolene", # user enters jolene
|
|
53
|
+
"0", # user selects first song
|
|
54
|
+
"https://www.youtube.com/watch?v=Ixrje2rXLMA", # user opts to direct download
|
|
55
|
+
"l", # save locally
|
|
56
|
+
"q", # user quits
|
|
57
|
+
],
|
|
58
|
+
],
|
|
59
|
+
indirect=True,
|
|
60
|
+
)
|
|
61
|
+
def test_cli_default(load_config):
|
|
62
|
+
# invoke the make function of the cli
|
|
63
|
+
cli.run(config=load_config)
|