Skip to content

Commit

Permalink
Fix parsing configuration file (#233)
Browse files Browse the repository at this point in the history
Co-authored-by: Bibhas <bd@nuiteq.com>
  • Loading branch information
Bibhas and Bibhas committed Jan 21, 2022
1 parent 9bc18e0 commit 8792542
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions spotify_dl/spotify_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def spotify_dl():
"""Main entry point of the script."""
parser = argparse.ArgumentParser(prog='spotify_dl')
parser.add_argument('-l', '--url', action="store",
help="Spotify Playlist link URL", type=str, required=True)
help="Spotify Playlist link URL", type=str, required=False)
parser.add_argument('-o', '--output', type=str, action='store',
help='Specify download directory.', required=True)
help='Specify download directory.', required=False)
parser.add_argument('-d', '--download', action='store_true',
help='Download using youtube-dl', default=True)
parser.add_argument('-f', '--format_str', type=str, action='store',
Expand Down Expand Up @@ -50,14 +50,19 @@ def spotify_dl():
config = json.loads(file.read())

for key, value in config.items():
if value and (value.lower() in ['true', 't']):
if (isinstance(value, bool) and value) or (isinstance(value, str) and value and value.lower() in ['true', 't']):
setattr(args, key, True)
else:
setattr(args, key, value)

if args.verbose:
log.setLevel(DEBUG)

if not hasattr(args, 'url'):
raise(Exception("No playlist url provided"))
if not hasattr(args, 'o'):
raise(Exception("No output folder configured"))

log.info('Starting spotify_dl')
log.debug('Setting debug mode on spotify_dl')

Expand Down

0 comments on commit 8792542

Please sign in to comment.