Skip to content

Commit 3398716

Browse files
authored
Merge pull request #86 from metabrainz/yim-2022-fixes
YIM 2022 playlist touch-ups
2 parents a328417 + a8e8a00 commit 3398716

9 files changed

+246
-194
lines changed

troi/internal/top_discoveries_for_year.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

troi/internal/top_missed_recordings_for_year.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

troi/internal/top_new_recordings_you_listened_to_for_year.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def description():
6262
return "Generate a playlist of tracks released this year that you've listened to."
6363

6464
def create(self, inputs):
65-
recs = DataSetFetcherElement(server_url="https://bono.metabrainz.org/top-new-tracks/json",
65+
recs = DataSetFetcherElement(server_url="https://datasets.listenbrainz.org/top-new-tracks/json",
6666
json_post_data=[{ 'user_name': inputs['user_name'] }])
6767

6868
y_lookup = troi.musicbrainz.year_lookup.YearLookupElement(skip_not_found=False)

troi/listenbrainz/stats.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def read(self, inputs = []):
9090
for r in recordings['payload']['recordings']:
9191
artist = Artist(r['artist_name'], mbids=r['artist_mbids'])
9292
release = Release(r['release_name'], mbid=r['release_mbid'])
93-
recording_list.append(Recording(r['track_name'], mbid=r['recording_mbid'], msid=r['recording_msid'],
94-
artist=artist, release=release))
93+
recording_list.append(Recording(r['track_name'], mbid=r['recording_mbid'], artist=artist, release=release))
9594

9695
return recording_list

troi/listenbrainz/tests/test_stats.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
'artist_name': 'Woolfy',
4949
'listen_count': 94,
5050
'recording_mbid': None,
51-
'recording_msid': '65435007-a8ea-48aa-9b23-5af1bd640905',
5251
'release_mbid': None,
5352
'release_name': 'Stations',
5453
'track_name': 'Tangiers'
@@ -95,4 +94,3 @@ def test_user_recording_stats(self, stats_mock):
9594
assert entities[0].artist.name == 'Woolfy'
9695
assert entities[0].release.name == 'Stations'
9796
assert entities[0].name == 'Tangiers'
98-
assert entities[0].msid == '65435007-a8ea-48aa-9b23-5af1bd640905'
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from datetime import datetime
2+
3+
import troi.filters
4+
import troi.listenbrainz.recs
5+
import troi.musicbrainz.recording_lookup
6+
import troi.musicbrainz.year_lookup
7+
import troi.sorts
8+
from troi import Recording
9+
from troi.listenbrainz.dataset_fetcher import DataSetFetcherElement
10+
from troi.playlist import PlaylistShuffleElement, PlaylistRedundancyReducerElement
11+
12+
13+
class TopDiscoveries(troi.patch.Patch):
14+
"""
15+
See below for description
16+
"""
17+
18+
NAME = "Top Discoveries of %d for %s"
19+
DESC = """<p>
20+
This playlist contains the top tracks for %s that were first listened to in %d.
21+
</p>
22+
<p>
23+
For more information on how this playlist is generated, please see our
24+
<a href="https://musicbrainz.org/doc/YIM2022Playlists">Year in Music 2022 Playlists</a> page.
25+
</p>
26+
"""
27+
28+
def __init__(self, debug=False):
29+
troi.patch.Patch.__init__(self, debug)
30+
31+
@staticmethod
32+
def inputs():
33+
"""
34+
Generate a top discoveries playlist for a user.
35+
36+
\b
37+
USER_ID: is a MusicBrainz userid that has an account on ListenBrainz.
38+
USER_NAME: is a MusicBrainz username that has an account on ListenBrainz.
39+
"""
40+
return [{"type": "argument", "args": ["user_id"]},
41+
{"type": "argument", "args": ["user_name"]}]
42+
43+
@staticmethod
44+
def outputs():
45+
return [Recording]
46+
47+
@staticmethod
48+
def slug():
49+
return "top-discoveries-for-year"
50+
51+
@staticmethod
52+
def description():
53+
return "Generate a top discoveries playlist for a user."
54+
55+
def create(self, inputs):
56+
recs = DataSetFetcherElement(server_url="https://datasets.listenbrainz.org/top-discoveries/json",
57+
json_post_data=[{ 'user_id': inputs['user_id'] }])
58+
59+
year = datetime.now().year
60+
pl_maker = troi.playlist.PlaylistMakerElement(self.NAME % (year, inputs['user_name']),
61+
self.DESC % (inputs['user_name'], year),
62+
patch_slug=self.slug(),
63+
user_name=inputs['user_name'])
64+
pl_maker.set_sources(recs)
65+
66+
shaper = PlaylistRedundancyReducerElement()
67+
shaper.set_sources(pl_maker)
68+
69+
shuffle = PlaylistShuffleElement()
70+
shuffle.set_sources(shaper)
71+
72+
return shuffle

0 commit comments

Comments
 (0)