Created
April 18, 2020 17:28
-
-
Save suma/438ccd03f0603aa92c559ed119f3ba9a to your computer and use it in GitHub Desktop.
Music(iTunes)のライブラリからプレイリストを出力するスクリプト (python3)
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
import plistlib | |
INPUT_FILE = 'PATH_TO' + 'iTunes Music Library.xml' | |
with open(INPUT_FILE, 'rb') as f: | |
xml = plistlib.load(f) | |
tracks = xml["Tracks"] | |
t = {} | |
for track_id in tracks: | |
t[int(track_id)] = tracks[track_id] | |
for playlist in xml["Playlists"]: | |
print("\n##", playlist["Name"]) | |
if not "Playlist Items" in playlist: | |
continue | |
for item in playlist["Playlist Items"]: | |
track_id = int(item["Track ID"]) | |
info = t[track_id] | |
print(info["Name"] + " - " + info.get("Artist", "") + " / " + info.get("Album", "")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment