How can I programmatically modify iTunes playlists on Windows?

Question:

I want to add local music files to an iTunes playlist on Windows 10. All other questions are from 2010, or they use Applescript, which is unavailable on Windows.

I’d like to do this with Python, but I would be fine with any language.

Is there a way to do this?

Asked By: TheKingElessar

||

Answers:

The iTunes COM library can be used to interface with iTunes. You can find out more by downloading the documentation from Apple’s developer website (search for "iTunes"). You need a free developer account. To open a local version of the documentation, you may need to check this:

enter image description here

An online version of the iTunes COM documentation can be found here.

To see how to use Windows COM with Python, check this out. It makes use of the win32com.client library.

To give you an idea of how it’s used, here’s an example from a program of mine:

import win32com.client

itunes = win32com.client.Dispatch("iTunes.Application")

itunes_sources = itunes.Sources
itunes_playlists = None
for source in itunes_sources:
    if source.Kind == 1:
        itunes_playlists = source.Playlists

itunes_playlists_dict = {}
playlists_left = itunes_playlists.Count
while playlists_left != 0:
    playlist = itunes_playlists.Item(playlists_left)
    blacklist = {"Voice Memos", "Genius", "Audiobooks", "Podcasts", "TV Shows", "Movies", "Library", "Music"}
    if playlist.Name not in blacklist:
        itunes_playlists_dict[playlist.Name] = playlist
    playlists_left -= 1
Answered By: TheKingElessar
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.