from typing import Dict
from typing import Iterable
from typing import Tuple


def extract_apple_playlists(xml_plist: Dict) -> Iterable[Tuple[str, Iterable[Dict]]]:
    """Extracts the user-defined playlists from the Apple plist.

        :param xml_plist: The parsed XML plist.
        :returns: An Iterable of (playlist_name, playlist_items) tuples.
    """

    playlists = []
    xml_playlists = xml_plist["Playlists"]
    for playlist in xml_playlists:
        keys = playlist.keys()
        if "Master" not in keys and "Distinguished Kind" not in keys:
            tracks = playlist.get("Playlist Items", [])
            playlists.append((
                playlist["Name"],
                tracks,
            ))

    return playlists