Merge branch 'rename_arguments' into 'main'
Move exclusive arguments to subcommands See merge request team-zotify/zotify!15
This commit is contained in:
commit
79edca89d3
15
README.md
15
README.md
|
@ -39,15 +39,16 @@ See [INSTALLATION](INSTALLATION.md) for a more detailed and opinionated installa
|
|||
|
||||
```
|
||||
Basic command line usage:
|
||||
zotify <track/album/playlist/episode/artist url> Downloads the track, album, playlist or podcast episode specified as a command line argument. If an artist url is given, all albums by specified artist will be downloaded. Can take multiple urls.
|
||||
zotify <command> Specify a subcommand to execute.
|
||||
|
||||
Basic options:
|
||||
(nothing) Download the tracks/albums/playlists URLs from the parameter
|
||||
-d, --download Download all tracks/albums/playlists URLs from the specified file
|
||||
-p, --playlist Downloads a saved playlist from your account
|
||||
-l, --liked Downloads all the liked songs from your account
|
||||
-f, --followed Downloads all songs by all artists you follow
|
||||
-s, --search Searches for specified track, album, artist or playlist, loads search prompt if none are given.
|
||||
(nothing) Defaults to search.
|
||||
download Download all tracks/albums/playlists URLs from the specified file.
|
||||
playlist Downloads a saved playlist from your account.
|
||||
liked Downloads all the liked songs from your account.
|
||||
followed Downloads all songs by all artists you follow.
|
||||
search Searches for specified track, album, artist or playlist, loads search prompt if none are given.
|
||||
url Downloads the track, album, playlist, podcast episode, or all albums by an artist from a url. Can take multiple urls.
|
||||
-h, --help See this message.
|
||||
```
|
||||
|
||||
|
|
|
@ -25,32 +25,21 @@ def main():
|
|||
parser.add_argument('--password',
|
||||
type=str,
|
||||
help='Account password')
|
||||
group = parser.add_mutually_exclusive_group(required=False)
|
||||
group.add_argument('urls',
|
||||
type=str,
|
||||
# action='extend',
|
||||
default='',
|
||||
nargs='*',
|
||||
help='Downloads the track, album, playlist, podcast episode, or all albums by an artist from a url. Can take multiple urls.')
|
||||
group.add_argument('-l', '--liked',
|
||||
dest='liked_songs',
|
||||
action='store_true',
|
||||
|
||||
# Create subparsers with custom prefixes
|
||||
subparsers = parser.add_subparsers(dest='command', metavar='command')
|
||||
subparsers.add_parser('url',
|
||||
help='Downloads the track, album, playlist, podcast episode, or all albums by an artist from a url. Can take multiple urls.').add_argument(dest='url_string', type=str, default='', nargs='*')
|
||||
subparsers.add_parser('liked',
|
||||
help='Downloads all the liked songs from your account.')
|
||||
group.add_argument('-f', '--followed',
|
||||
dest='followed_artists',
|
||||
action='store_true',
|
||||
subparsers.add_parser('followed',
|
||||
help='Downloads all the songs from all your followed artists.')
|
||||
group.add_argument('-p', '--playlist',
|
||||
action='store_true',
|
||||
subparsers.add_parser('playlist',
|
||||
help='Downloads a saved playlist from your account.')
|
||||
group.add_argument('-s', '--search',
|
||||
type=str,
|
||||
nargs='?',
|
||||
const=' ',
|
||||
help='Loads search prompt to find then download a specific track, album or playlist')
|
||||
group.add_argument('-d', '--download',
|
||||
type=str,
|
||||
help='Downloads tracks, playlists and albums from the URLs written in the file passed.')
|
||||
subparsers.add_parser('search',
|
||||
help='Loads search prompt to find then download a specific track, album or playlist').add_argument(dest="search_string", nargs="?", const=" ")
|
||||
subparsers.add_parser( 'download',
|
||||
help='Downloads tracks, playlists and albums from the URLs written in the file passed.').add_argument("download_string", type=str)
|
||||
|
||||
for configkey in CONFIG_VALUES:
|
||||
parser.add_argument(CONFIG_VALUES[configkey]['arg'],
|
||||
|
|
|
@ -30,9 +30,9 @@ def client(args) -> None:
|
|||
}
|
||||
Zotify.DOWNLOAD_QUALITY = quality_options[Zotify.CONFIG.get_download_quality()]
|
||||
|
||||
if args.download:
|
||||
if args.command == "download":
|
||||
urls = []
|
||||
filename = args.download
|
||||
filename = args.download_string
|
||||
if Path(filename).exists():
|
||||
with open(filename, 'r', encoding='utf-8') as file:
|
||||
urls.extend([line.strip() for line in file.readlines()])
|
||||
|
@ -43,16 +43,16 @@ def client(args) -> None:
|
|||
Printer.print(PrintChannel.ERRORS, f'File {filename} not found.\n')
|
||||
return
|
||||
|
||||
if args.urls:
|
||||
if len(args.urls) > 0:
|
||||
download_from_urls(args.urls)
|
||||
if args.command == "url":
|
||||
if len(args.url_string) > 0:
|
||||
download_from_urls(args.url_string)
|
||||
return
|
||||
|
||||
if args.playlist:
|
||||
if args.command == "playlist":
|
||||
download_from_user_playlist()
|
||||
return
|
||||
|
||||
if args.liked_songs:
|
||||
if args.command == "liked":
|
||||
for song in get_saved_tracks():
|
||||
if not song[TRACK][NAME] or not song[TRACK][ID]:
|
||||
Printer.print(PrintChannel.SKIPS, '### SKIPPING: SONG DOES NOT EXIST ANYMORE ###' + "\n")
|
||||
|
@ -60,20 +60,20 @@ def client(args) -> None:
|
|||
download_track('liked', song[TRACK][ID])
|
||||
return
|
||||
|
||||
if args.followed_artists:
|
||||
if args.command == "followed":
|
||||
for artist in get_followed_artists():
|
||||
download_artist_albums(artist)
|
||||
return
|
||||
|
||||
if args.search:
|
||||
if args.search == ' ':
|
||||
if args.command == "search":
|
||||
if args.search_string == ' ':
|
||||
search_text = ''
|
||||
while len(search_text) == 0:
|
||||
search_text = input('Enter search: ')
|
||||
search(search_text)
|
||||
else:
|
||||
if not download_from_urls([args.search]):
|
||||
search(args.search)
|
||||
if not download_from_urls([args.search_string]):
|
||||
search(args.search_string)
|
||||
return
|
||||
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue