@@ -116,9 +116,13 @@ def get_tracks_from_listens(self, listens):
116
116
mbid = self .get_mb_recording_id (track )
117
117
tracks .append (
118
118
{
119
- "album" : {"name" : track ["track_metadata" ].get ("release_name" )},
119
+ "album" : {
120
+ "name" : track ["track_metadata" ].get ("release_name" )
121
+ },
120
122
"name" : track ["track_metadata" ].get ("track_name" ),
121
- "artist" : {"name" : track ["track_metadata" ].get ("artist_name" )},
123
+ "artist" : {
124
+ "name" : track ["track_metadata" ].get ("artist_name" )
125
+ },
122
126
"mbid" : mbid ,
123
127
"release_mbid" : mbid_mapping .get ("release_mbid" ),
124
128
"listened_at" : track .get ("listened_at" ),
@@ -153,23 +157,31 @@ def get_listenbrainz_playlists(self):
153
157
if playlist_info .get ("creator" ) == "listenbrainz" :
154
158
title = playlist_info .get ("title" )
155
159
self ._log .debug (f"Playlist title: { title } " )
156
- playlist_type = "Exploration" if "Exploration" in title else "Jams"
160
+ playlist_type = (
161
+ "Exploration" if "Exploration" in title else "Jams"
162
+ )
157
163
if "week of" in title :
158
164
date_str = title .split ("week of " )[1 ].split (" " )[0 ]
159
- date = datetime .datetime .strptime (date_str , "%Y-%m-%d" ).date ()
165
+ date = datetime .datetime .strptime (
166
+ date_str , "%Y-%m-%d"
167
+ ).date ()
160
168
else :
161
169
continue
162
170
identifier = playlist_info .get ("identifier" )
163
171
id = identifier .split ("/" )[- 1 ]
164
172
listenbrainz_playlists .append (
165
173
{"type" : playlist_type , "date" : date , "identifier" : id }
166
174
)
167
- listenbrainz_playlists = sorted (listenbrainz_playlists , key = lambda x : x ["type" ])
175
+ listenbrainz_playlists = sorted (
176
+ listenbrainz_playlists , key = lambda x : x ["type" ]
177
+ )
168
178
listenbrainz_playlists = sorted (
169
179
listenbrainz_playlists , key = lambda x : x ["date" ], reverse = True
170
180
)
171
181
for playlist in listenbrainz_playlists :
172
- self ._log .debug (f'Playlist: { playlist ["type" ]} - { playlist ["date" ]} ' )
182
+ self ._log .debug (
183
+ f'Playlist: { playlist ["type" ]} - { playlist ["date" ]} '
184
+ )
173
185
return listenbrainz_playlists
174
186
175
187
def get_playlist (self , identifier ):
@@ -231,13 +243,17 @@ def get_weekly_playlist(self, playlist_type, most_recent=True):
231
243
# Fetch all playlists
232
244
playlists = self .get_listenbrainz_playlists ()
233
245
# Filter playlists by type
234
- filtered_playlists = [p for p in playlists if p ["type" ] == playlist_type ]
246
+ filtered_playlists = [
247
+ p for p in playlists if p ["type" ] == playlist_type
248
+ ]
235
249
# Sort playlists by date in descending order
236
250
sorted_playlists = sorted (
237
251
filtered_playlists , key = lambda x : x ["date" ], reverse = True
238
252
)
239
253
# Select the most recent or older playlist based on the most_recent flag
240
- selected_playlist = sorted_playlists [0 ] if most_recent else sorted_playlists [1 ]
254
+ selected_playlist = (
255
+ sorted_playlists [0 ] if most_recent else sorted_playlists [1 ]
256
+ )
241
257
self ._log .debug (
242
258
f"Selected playlist: { selected_playlist ['type' ]} - { selected_playlist ['date' ]} "
243
259
)
0 commit comments