Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple playlist support
 #2

Open
MatthieuTnsc opened this issue Jul 2, 2015 · 0 comments
Open

Multiple playlist support
 #2

MatthieuTnsc opened this issue Jul 2, 2015 · 0 comments

Comments

@MatthieuTnsc
Copy link

That would be nice to support multiple playlist file identifying in ‘retrieve-identifier.py’
Personally I managed to do it this way !

def findFiles (path, filter):
    for root, dirs, files in os.walk(path):
        for file in fnmatch.filter(files, filter):
            yield os.path.join(root, file)


itunes_identifiers = []

itunes_dir = "itunes"

if not os.path.exists(itunes_dir):
    os.makedirs(itunes_dir)

execution_dir = os.path.dirname(os.path.realpath(__file__))

for csv_files in findFiles(execution_dir, '*.csv'):

    csv_file_name = os.path.basename(csv_files)
    playlist_name, playlist_extension = os.path.splitext(csv_file_name)

    print("Found a playlist file named {}".format(playlist_name))

    with open(csv_file_name, encoding='utf-8') as playlist_file:
        playlist_reader = csv.reader(playlist_file)
        next(playlist_reader)

        for row in playlist_reader:
            title, artist = row[1], row[2]
            itunes_identifier = retrieve_itunes_identifier(title, artist)

            if itunes_identifier:
                itunes_identifiers.append(itunes_identifier)
                print("{} - {} => {}".format(title, artist, itunes_identifier))
            else:
                print("{} - {} => Not Found".format(title, artist))


    with open(execution_dir+'/itunes/'+csv_file_name, 'w', encoding='utf-8') as output_file:
        for itunes_identifier in itunes_identifiers:
            output_file.write(str(itunes_identifier) + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant