def __init__(self, *args, **kwargs):
        Lib.__init__(self, *args, **kwargs)

        self.play_lists_by_id = {}
        self.play_lists_by_name = {}
        self.play_list_by_hierarchy_name = {}
        self.play_lists = []
        for p in self.il['Playlists']:
            pl = Playlist(p["Playlist Persistent ID"],
                          p["Parent Persistent ID"] if "Parent Persistent ID" in p else None,
                          self, p["Name"])
            tracknum = 1
            if 'Playlist Items' in p:
                for track in p['Playlist Items']:
                    id=int(track['Track ID'])
                    t = self.songs[id]
                    t.playlist_order = tracknum
                    tracknum += 1
                    pl.tracks.append(t)

            self.play_lists_by_id[pl.id] = pl
            if pl.name not in self.play_lists_by_name:
                self.play_lists_by_name[pl.name] = []
            self.play_lists_by_name[pl.name].append(pl)
            self.play_lists.append(pl)
        for p in self.play_lists:
            self.play_list_by_hierarchy_name[self.get_playlist_hierarchy(p)] = p
def read_playlists(library_file: str) -> List[Playlist]:
    library = Library(library_file)
    playlist_names = library.getPlaylistNames(
        ignoreList=english_german_ignore_list)
    return [
        library.getPlaylist(playlist_name) for playlist_name in playlist_names
    ]
Exemple #3
0
def get_itunes():
    l = Library('../x/iTunes Music Library.xml')
    playlists = [x for x in l.getPlaylistNames() if x != 'iTunes\xa0U']

    # Key is playlist persistent ID
    lookup = dict()
    name_lookup = dict()

    lounge = list()
    numbers = list()

    # Populates playlist entres in `lookup` by ID, which can be obtained
    # from a playlist name using `name_lookup`.
    for pn in playlists:
        p = l.getPlaylist(pn)

        cid = p.playlist_persistent_id
        pid = p.parent_persistent_id
        name = p.name

        pp = {
            'playlist': p,
            'name': name,
            'id': cid,  # Current ID
            'pid': pid,  # Parent ID
            'children': list()
        }

        name_lookup[name] = cid

        # Register as a child of a parent
        if pid in lookup.keys():
            lookup[pid]['children'].append(cid)

        # Identify list of parent nodes, in order, until the root node
        parents = list()
        while pid is not None:
            parent = lookup[pid]
            parents.append(parent['name'])
            pid = parent['pid']

        if len(parents) == 0:
            pp['parents'] = None
            pp['root'] = None
        else:
            pp['parents'] = parents
            root = parents[-1]
            pp['root'] = root

            if not p.is_folder:
                if root == 'lounge':
                    lounge.append(cid)
                elif root == 'numerology':
                    numbers.append(cid)

        lookup[cid] = pp

    # Populate song lists for numbered playlists
    numbers_pl = defaultdict(dict)
    for cid in numbers:
        pl = lookup[cid]
        p = pl['playlist']

        songs = [format_song(s) for s in p.tracks]
        parent = pl['parents'][0]

        numbers_pl[parent][p.name] = songs

    # All playlist names that need to be hide-able
    keys = list()

    # For each period (a season), add a list of all playlists
    seasons = sorted(numbers_pl.keys())
    out = ''

    for season in seasons:
        # Header for the season
        keys.append(season)
        out = add_to_out(
            out, '''
    
    <li><div id="{0}">
    <strong><a href="#" id="{0}-title">{1}</a></strong>
    <div id="{0}-body" style="display: none;">\n<ul class="space-before space-after">'''
            .format(season, season.replace('--', '&ndash;')))

        # Loop over playlists
        season_pls = numbers_pl[season]
        for pn in sorted(season_pls.keys()):
            songs = season_pls[pn]

            # Record songs
            entries = list()
            for i in range(len(songs)):
                s = songs[i]
                entries.append('<li>{1}</li>'.format(i + 1, s))

            p_txt = '\n'.join(entries)
            p_title = ''.join(
                [c for c in pn.replace(' ', '-') if c in alphanum])
            keys.append(p_title)
            out = add_to_out(
                out, '''
    
    
        <li><div id="{1}">
          <a href="#" id="{1}-title">{0}</a>
    
          <div id="{1}-body" style="display: none;">
            <ol class="space-before space-after">
              {2}
            </ol>
          </div> <!-- #{1}-body -->
        </div> <!-- #{1} -->'''.format(pn, p_title, p_txt))

        out = add_to_out(
            out, '''
      </div> <!-- #{0}-body -->
    </div> <!-- #{0} -->
    </li>'''.format(season))

    return (out, keys)
Exemple #4
0
 def getITunesPlaylistTrackNames(self, name):
     itunes_library = Library(settings.ITUNES_LIBRARY_XML_PATH)
     return ['/' + s.location
             for s in itunes_library.getPlaylist(name).tracks]
def read_songs(library_file: str) -> Dict[int, Song]:
    library = Library(library_file)
    return library.songs
Exemple #6
0
def get_itunes():
    l = Library('../x/iTunes Music Library.xml')
    playlists = [x for x in l.getPlaylistNames() if x != 'iTunes\xa0U']
    
    # Key is playlist persistent ID
    lookup = dict()
    name_lookup = dict()
    
    lounge = list()
    numbers = list()
    
    # Populates playlist entres in `lookup` by ID, which can be obtained
    # from a playlist name using `name_lookup`.
    for pn in playlists:
        p = l.getPlaylist(pn)
    
        cid = p.playlist_persistent_id
        pid = p.parent_persistent_id
        name = p.name
    
        pp = { 'playlist' : p,
               'name'     : name,
               'id'       : cid,      # Current ID
               'pid'      : pid,      # Parent ID
               'children' : list() }
    
        name_lookup[name] = cid
    
        # Register as a child of a parent
        if pid in lookup.keys():
            lookup[pid]['children'].append(cid)
    
        # Identify list of parent nodes, in order, until the root node
        parents = list()
        while pid is not None:
            parent = lookup[pid]
            parents.append(parent['name'])
            pid = parent['pid']
    
        if len(parents) == 0:
            pp['parents'] = None
            pp['root'] = None
        else:
            pp['parents'] =  parents
            root = parents[-1]
            pp['root'] = root
    
            if not p.is_folder:
                if root == 'lounge':
                    lounge.append(cid)
                elif root == 'numerology':
                    numbers.append(cid)
    
        lookup[cid] = pp
    
    # Populate song lists for numbered playlists
    numbers_pl = defaultdict(dict)
    for cid in numbers:
        pl = lookup[cid]
        p = pl['playlist']
    
        songs = [format_song(s) for s in p.tracks]
        parent = pl['parents'][0]
    
        numbers_pl[parent][p.name] = songs
    
    # All playlist names that need to be hide-able
    keys = list()
    
    # For each period (a season), add a list of all playlists
    seasons = sorted(numbers_pl.keys())
    out = ''
    
    for season in seasons:
        # Header for the season
        keys.append(season)
        out = add_to_out(out, '''
    
    <li><div id="{0}">
    <strong><a href="#" id="{0}-title">{1}</a></strong>
    <div id="{0}-body" style="display: none;">\n<ul class="space-before space-after">'''.format(season, season.replace('--', '&ndash;')))
    
        # Loop over playlists
        season_pls = numbers_pl[season]
        for pn in sorted(season_pls.keys()):
            songs = season_pls[pn]
    
            # Record songs
            entries = list()
            for i in range(len(songs)):
                s = songs[i]
                entries.append('<li>{1}</li>'.format(i+1, s))
    
            p_txt   = '\n'.join(entries)
            p_title = ''.join([c for c in pn.replace(' ', '-') if c in alphanum])
            keys.append(p_title)
            out = add_to_out(out, '''
    
    
        <li><div id="{1}">
          <a href="#" id="{1}-title">{0}</a>
    
          <div id="{1}-body" style="display: none;">
            <ol class="space-before space-after">
              {2}
            </ol>
          </div> <!-- #{1}-body -->
        </div> <!-- #{1} -->'''.format(pn, p_title, p_txt))
    
        out = add_to_out(out, '''
      </div> <!-- #{0}-body -->
    </div> <!-- #{0} -->
    </li>'''.format(season))
    
    return(out, keys)