Created
December 23, 2016 20:42
-
-
Save victorlin/01db6ef2df4d9debc7e00f912786ce49 to your computer and use it in GitHub Desktop.
merge iTunes playlist export and djay key/bpm data
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
""" | |
Script to crete TSV file containing title/artist/__/BPM/key info | |
playlist_export_file | |
iTunes export of playlist (CSV) | |
auto_fpath | |
filepath of binary plist file generated by djay.app | |
""" | |
import csv | |
from biplist import readPlist | |
from pandas import read_table, DataFrame | |
playlist_export_file = '/Users/Victor/Downloads/2016.txt' | |
auto_fpath = '/Users/Victor/Library/Containers/com.algoriddim.djay-pro-mac/Data/Library/Application Support/Algoriddim/djay Cached Data.plist' | |
keys = ["8B-C", "8A-Am", | |
"3B-Db", "3A-Bbm", | |
"10B-D", "10A-Bm", | |
"5B-Eb", "5A-Cm", | |
"12B-E", "12A-C#m", | |
"7B-F", "7A-Dm", | |
"2B-Gb", "2A-Ebm", | |
"9B-G", "9A-Em", | |
"4B-Ab", "4A-Fm", | |
"11B-A", "11A-F#m", | |
"6B-Bb", "6A-Gm", | |
"1B-B", "1A-G#m"] | |
keys_generic = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'] | |
def biplist_to_tsv(auto_fpath, out_file): | |
with open(out_file, 'w') as f: | |
fwriter = csv.writer(f, delimiter='\t') | |
auto_plist = readPlist(auto_fpath) | |
fwriter.writerow(['Name', 'Artist', 'idk', 'BPM', 'KeyID']) | |
for song, data in auto_plist.items(): | |
row = song.encode('utf-8').split('\t') + data.values() | |
if len(row) is not 5: | |
continue | |
fwriter.writerow(row) | |
def get_playlist_djay_info(playlist_file, auto_fpath): | |
"""Return pandas.DataFrame | |
generates a file `djay.txt` | |
""" | |
djay_file = 'djay.txt' | |
biplist_to_tsv(auto_fpath, djay_file) | |
songs = read_table(playlist_file) | |
djay = read_table(djay_file) | |
songs_df = DataFrame() | |
songs_df['Name'] = [x.lower() for x in songs.Name] | |
songs_df['Artist'] = [x.lower() for x in songs.Artist] | |
result_df = songs_df.merge(djay, on=['Name', 'Artist']) | |
if len(result_df) is not len(songs_df): | |
print 'mising songs:' | |
print set(songs_df.Name) - set(result_df.Name) | |
result_df['Key Detail'] = [keys[int(x)] for x in result_df['KeyID']] | |
result_df['Key'] = [keys_generic[int(x) / 2] for x in result_df['KeyID']] | |
return result_df | |
if __name__ == '__main__': | |
df = get_playlist_djay_info(playlist_export_file, auto_fpath) | |
df.to_csv('playlist_songs_info.txt', sep='\t', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment