Created
November 1, 2015 20:38
-
-
Save martineno/66cb5a4c36770355fa3b to your computer and use it in GitHub Desktop.
Processes all the .mp3 files in the current directory and creates a CSV file that contains their album, artist and title.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import eyed3 | |
import csv | |
import glob | |
import argparse | |
# eyed3 is a required module that is used to process the files. Install: pip --user eyed3 | |
def main(): | |
parser = argparse.ArgumentParser(description="Processes all the .mp3 files in the current directory and creates a CSV file that contains their album, artist and title.") | |
parser.add_argument("output_file", help="The output file in which the csv data is saved.") | |
args = parser.parse_args() | |
create_csv(args.output_file) | |
def create_csv(output_file): | |
with open(output_file, 'wb') as listingfile: | |
listingwriter = csv.writer(listingfile) | |
for mp3file in glob.glob('*.mp3'): | |
audiofile = eyed3.load(mp3file) | |
album = audiofile.tag.album | |
artist = audiofile.tag.artist | |
title = audiofile.tag.title | |
should_add = True | |
if not album: | |
print mp3file + " is missing album" | |
should_add = False | |
if not artist: | |
print mp3file + " is missing artist" | |
should_add = False | |
if not title: | |
print mp3file + " is missing title" | |
should_add = False | |
if should_add: | |
listingwriter.writerow([album, artist, title]) | |
else: | |
print mp3file + " was not added to the output" | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment