Skip to content

Instantly share code, notes, and snippets.

@mutsune
Last active May 15, 2021 07:10
Show Gist options
  • Save mutsune/a6d62f7d2fc97cb02f6fd06b45c33031 to your computer and use it in GitHub Desktop.
Save mutsune/a6d62f7d2fc97cb02f6fd06b45c33031 to your computer and use it in GitHub Desktop.
Extract albums containing songs that have been played more than 5 times
from itertools import groupby
f = open("music.utf8.tsv")
lines = [l[:-1] for l in f]
data = [l.split("\t") for l in lines[1:]]
data = filter(lambda d: "Apple Music" in d[1], data)
data = filter(lambda d: d[2] != "", data)
for k, v in groupby(data, lambda c: c[0]):
album = list(v)
popular = False
for song in album:
if int(song[2]) >= 5:
popular = True
print(song)
break
@mutsune
Copy link
Author

mutsune commented May 15, 2021

How to use

  1. Export your music
  2. Covert Music.txt to UTF-8 and extract necessary columns
    • nkf -d -w Music.txt | cut -d$'\t' -f4,23,26 > music.utf8.tsv
  3. Extract only your favorite albums!
    • python3 fav_albums.py
    • or, if you just count number of albums: python3 fav_albums.py | wc -l

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment