A year or so ago I bought a HIFI Walker H2 audio player. I stuck a 256GB SD micro SD card in it and promptly copied my Apple Music nee iTunes library to it. This was pretty slick and I was very happy with it. As I mentioned the wired headphones were probably more important than the stand alone player as far as quality of listening went (though anything is better than most streaming services OTA codecs), but over time the freedom of having a device where I don't have to fiddle around multitasking to find which music player is playing to change albums or whatever has been welcome. The big drawback though is that the UI is essentially just a file browser. This is fine if I just want to listen to a single album but over time I've found myself wanting to just be able to shuffle things. On my Mac I have a playlist that has recently added items as well as a playlist that has items that have not been listened to recently. Lucky me the H2 support the M3U playlist format (mostly).
Extracting Apple Music Library Metadata
I made a goofy throwback to Winamp a while back and wrote some Python to generate this webpage. I originally had to remember to manually export my Apple Music library to an XML file when I bought new music so it would show up the next time the script ran but then I found a library exporter that did exactly what I needed. I wired that up as a cronjob to run every week and voilà! Now armed with that I had the data I needed to convert the Apple playlists to M3U files. While I was in there I took it upon myself to do something that Apple Music nee iTunes can't seem to reliably do and that is sort albums by Artist Name and then by Release Year. So more Python is clearly called for.
Reading Playlists
If you go look at itunes-sucks
in my misc.git repository you'll find the bits and pieces. music.py is the
library file that contains all the classes that do the heavy lifting.
Specifically the MusicLibrary class's playlists property returns a
Playlists class instance that provides a dict-like interface to the Plist
XML format.
Over in
playlists.py
there is an Albums class that does the heavy lifting to ensure things are
sorted the way I want them to be. Album's static method albumsort makes
sure the tracks within an album are properly sorted (by disc number and track
number if we know it, otherwise by year and then name if all else fails)...
def albumsort(track):
_id = (100 * track.get('Disc Number', 0)) + \
track.get('Track Number', 0)
if _id == 0:
if track.get('Year'):
return int(track['Year'])
else:
return track.get('Name')
return _id
... and then the Albums constructor sorts the list of Album instances by
the year.
self.albums.sort(key=lambda a: a.year)
H2 M3U Generation
Now that we have all the data organized in our head, we can just write it to
disk. The easiest way I found to organize things was to create a Music and
Playlists folder in the root of the microSD card. This makes browsing easy
and also relative path generation for the M3U files easy. A little helper
function in playlists.py converts the Apple Music Library paths into what
I need for the layout on the H2...
def h2ize_path(fp, second=False):
parts = fp.split(os.path.sep)[-4:]
if not second:
return os.path.join('..', *parts)
else:
return os.path.join('../..', *parts)
... and so we just write out the files we want. Of note, I emit an All.m3u
along with the individual album .m3u files which are prefixed by release year.
This sorts well and gives me the option to go into an artist and hit play on
their entire catalog (that I own).
# Pass 1: write All.m3u with all the tracks in order.
with open(os.path.join(art_path, 'All.m3u'), 'w') as fd:
for album in albums:
for track in album.tracks:
fd.write(h2ize_path(
track.file,
True
) + '\n')
# Pass 2: write per-album playlists.
for album in albums:
if '/' in album.name:
continue
fn = f'{album.year}-{album.name}.m3u'
fp = os.path.join(art_path, fn)
with open(fp, 'w') as fd:
for track in album.tracks:
fd.write(h2ize_path(
track.file,
True
) + '\n')
Conclusion
While at first the minimalist interfaces of these devices might seem like a drawback or bad design but with the right perspective and tools they can be alarmingly flexible. I'd happily argue that Apple's Music interface both on macOS and i{,pad}OS are so heavily "designed" that they border on uselessness unless you use the program the exact way the people who signed off on the design intended to (shut up and listen to Apple Music+'s radio, I imagine).
If all the custom software scares you, there are other music players out there that are much simpler (like Foobar2000, for example) and allow you to drop your music files into them and write out a playlist. Something like that may take more work but you could accomplish the same outcome -- customizing your music player to fit your style of listening without all the extra nerd shit.

Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.