# Buggy code
def spotify_dl():
    parser = argparse.ArgumentParser(prog="spotify_dl")
    parser.add_argument(
        "-d",
        "--download",
        action="store_true",
        help="Download using youtube-dl",
        default=True,
    )
    parser.add_argument(
        "-p",
        "--playlist",
        action="store",
        help="Download from playlist id instead of saved tracks",
    )
    parser.add_argument(
        "-V",
        "--verbose",
        action="store_true",
        help="Show more information on whats happening.",
    )
    parser.add_argument(
        "-v",
        "--version",
        action="store_true",
        help="Shows current version of the program",
    )
    parser.add_argument(
        "-o",
        "--output",
        type=str,
        action="store",
        nargs="*",
        help="Specify download directory.",
    )
    parser.add_argument(
        "-u",
        "--user_id",
        action="store",
        help="Specify the playlist owner's userid when it"
        " is different than your spotify userid",
    )
    parser.add_argument(
        "-i",
        "--uri",
        type=str,
        action="store",
        nargs="*",
        help="Given a URI, download it.",
    )
    parser.add_argument(
        "-f",
        "--format_str",
        type=str,
        action="store",
        nargs="*",
        help="Specify youtube-dl format string.",
        default=["bestaudio/best"],
    )
    parser.add_argument(
        "-m",
        "--skip_mp3",
        action="store_true",
        help="Don't convert downloaded songs to mp3",
    )
    parser.add_argument("-l", "--url", action="store", help="Spotify Playlist link URL")

    args = parser.parse_args()

    if args.version:
        print("spotify_dl v{}".format(VERSION))
        exit(0)

    if os.path.isfile(os.path.expanduser("~/.spotify_dl_settings")):
        with open(os.path.expanduser("~/.spotify_dl_settings")) as file:
            config = json.loads(file.read())

        for key, value in config.items():
            if value and (value.lower() == "true" or value.lower() == "t"):
                setattr(args, key, True)
            else:
                setattr(args, key, value)

    if args.verbose:
        log.setLevel(DEBUG)

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

    if not check_for_tokens():
        exit(1)

    token = authenticate()
    sp = spotipy.Spotify(auth=token)
    log.debug("Arguments: {}".format(args))
    if args.url is not None:
        url = args.url.split("open.spotify.com/")[1].split("/")
        uri = ":".join(url)
        uri = "spotify:" + uri
        args.uri = []
        args.uri.append(uri)
    if args.uri:
        current_user_id, playlist_id = extract_user_and_playlist_from_uri(args.uri[0])
    else:
        if args.user_id is None:
            current_user_id = sp.current_user()["id"]
        else:
            current_user_id = args.user_id

    if args.output:
        if args.uri:
            uri = args.uri[0]
            playlist = playlist_name(uri, sp)
        else:
            playlist = get_playlist_name_from_id(args.playlist, current_user_id, sp)

        log.info("Saving songs to: {}".format(playlist))
        download_directory = args.output + "/" + playlist
        # Check whether directory has a trailing slash or not
        if len(download_directory) >= 0 and download_directory[-1] != "/":
            download_directory += "/"
        if not os.path.exists(download_directory):
            os.makedirs(download_directory)
    else:
        download_directory = ""

    if args.uri:
        songs = fetch_tracks(sp, playlist_id, current_user_id)
    else:
        songs = fetch_tracks(sp, args.playlist, current_user_id)
    url = []
    for song, artist in songs.items():
        link = fetch_youtube_url(song + " - " + artist)
        if link:
            url.append((link, song, artist))

    save_songs_to_file(url, download_directory)
    if args.download is True:
        download_songs(url, download_directory, args.format_str[0], args.skip_mp3)


# Traceback (TypeError)
INFO: 2017-06-03 19:12:37,099 - extract_user_and_playlist_from_uri - List owner: anjunadeep
INFO: 2017-06-03 19:12:37,099 - extract_user_and_playlist_from_uri - List ID: 1GfH39JcID8aFZ0ZQQVkBk
INFO: 2017-06-03 19:12:37,100 - extract_user_and_playlist_from_uri - List owner: anjunadeep
INFO: 2017-06-03 19:12:37,100 - extract_user_and_playlist_from_uri - List ID: 1GfH39JcID8aFZ0ZQQVkBk
INFO: 2017-06-03 19:12:37,813 - spotify_dl - Saving songs to: Anjunadeep Recommends - Updated Daily
Traceback (most recent call last):
File "f:\python34\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "f:\python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "F:\Python34\Scripts\spotify_dl.exe\__main__.py", line 9, in <module>
File "f:\python34\lib\site-packages\spotify_dl\spotify_dl.py", line 96, in spotify_dl
download_directory = args.output + '/' + playlist
TypeError: can only concatenate list (not "str") to list

# Fixed code
def spotify_dl():
    parser = argparse.ArgumentParser(prog="spotify_dl")
    parser.add_argument(
        "-d",
        "--download",
        action="store_true",
        help="Download using youtube-dl",
        default=True,
    )
    parser.add_argument(
        "-p",
        "--playlist",
        action="store",
        help="Download from playlist id instead of saved tracks",
    )
    parser.add_argument(
        "-V",
        "--verbose",
        action="store_true",
        help="Show more information on whats happening.",
    )
    parser.add_argument(
        "-v",
        "--version",
        action="store_true",
        help="Shows current version of the program",
    )
    parser.add_argument(
        "-o", "--output", type=str, action="store", help="Specify download directory."
    )
    parser.add_argument(
        "-u",
        "--user_id",
        action="store",
        help="Specify the playlist owner's userid when it"
        " is different than your spotify userid",
    )
    parser.add_argument(
        "-i",
        "--uri",
        type=str,
        action="store",
        nargs="*",
        help="Given a URI, download it.",
    )
    parser.add_argument(
        "-f",
        "--format_str",
        type=str,
        action="store",
        help="Specify youtube-dl format string.",
        default="bestaudio/best",
    )
    parser.add_argument(
        "-m",
        "--skip_mp3",
        action="store_true",
        help="Don't convert downloaded songs to mp3",
    )
    parser.add_argument("-l", "--url", action="store", help="Spotify Playlist link URL")

    args = parser.parse_args()

    playlist_url_pattern = re.compile(r"^https://open.spotify.com/(.+)$")

    if args.version:
        print("spotify_dl v{}".format(VERSION))
        exit(0)

    if os.path.isfile(os.path.expanduser("~/.spotify_dl_settings")):
        with open(os.path.expanduser("~/.spotify_dl_settings")) as file:
            config = json.loads(file.read())

        for key, value in config.items():
            if value and (value.lower() == "true" or value.lower() == "t"):
                setattr(args, key, True)
            else:
                setattr(args, key, value)

    if args.verbose:
        log.setLevel(DEBUG)

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

    if not check_for_tokens():
        exit(1)

    token = authenticate()
    sp = spotipy.Spotify(auth=token)
    log.debug("Arguments: {}".format(args))

    url_match = playlist_url_pattern.match(args.url)
    if args.url and url_match and len(url_match.groups()) > 0:
        uri = "spotify:" + url_match.groups()[0].replace("/", ":")
        args.uri = [uri]
    else:
        raise Exception("Invalid playlist URL ")
    if args.uri:
        current_user_id, playlist_id = extract_user_and_playlist_from_uri(args.uri[0])
    else:
        if args.user_id is None:
            current_user_id = sp.current_user()["id"]
        else:
            current_user_id = args.user_id

    if args.output:
        if args.uri:
            uri = args.uri[0]
            playlist = playlist_name(uri, sp)
        else:
            playlist = get_playlist_name_from_id(args.playlist, current_user_id, sp)

        log.info("Saving songs to: {}".format(playlist))
        download_directory = os.path.join(args.output, playlist)

        if not os.path.exists(download_directory):
            os.makedirs(download_directory)
    else:
        download_directory = ""

    if args.uri:
        songs = fetch_tracks(sp, playlist_id, current_user_id)
    else:
        songs = fetch_tracks(sp, args.playlist, current_user_id)
    url = []
    for song, artist in songs.items():
        link = fetch_youtube_url(song + " - " + artist)
        if link:
            url.append((link, song, artist))

    save_songs_to_file(url, download_directory)
    if args.download is True:
        download_songs(url, download_directory, args.format_str, args.skip_mp3)