from pathlib import Path
import csv


def display_playlist_tracks(playlist):
    """
    display playlist tracks from saved csv file
    """
    path = Path('playlist_tracks_csv/')
    file_name = '{}'.format(playlist)
    # read from existing csv file
    fpath = (path / file_name).with_suffix('.csv')
    with fpath.open(mode='r') as csv_file:
        csv_reader = csv.DictReader(csv_file)
        tracks = []
        line_count = 1
        for row in csv_reader:
            track = "{} - {}: spotify_url: {}".format(row['name'], row['artists'], row['spotify_url'])
            tracks.append(track)
            line_count += 1
        i = 0
        while i != len(tracks) - 1:
            print("{}. {}".format(i, tracks[i]))
            i += 1
        print(f'Processed {line_count} lines.')
        return tracks