This commit is contained in:
Fabio Manganiello 2022-09-19 15:39:18 +02:00
parent 9a7e720e7e
commit 4c72748b9f

View file

@ -2,7 +2,7 @@
[//]: # (description: Use Platypush to manage your music activity, discovery playlists and be on top of new releases.)
[//]: # (image: /img/music-automation.png)
[//]: # (author: Fabio Manganiello <fabio@platypush.tech>)
[//]: # (published: 2022-09-18)
[//]: # (published: 2022-09-19)
I have been an enthusiastic user of mpd and mopidy for nearly two decades. I
have already [written an
@ -167,8 +167,7 @@ database.
I'll assume that you have a Postgres database running somewhere, but the script
below can be easily adapted also to other DBMS's.
Database initialization script (download/pastebin link is
[here](https://paste.fabiomanganiello.com/blacklight/music.sql)):
Database initialization script:
```sql
-- New listened tracks will be pushed to the tmp_music table, and normalized by
@ -241,6 +240,20 @@ create table music_discovery_playlist_track(
foreign key(track_id) references music_track(id)
);
-- This table contains the new releases from artist that we've listened to at
-- least once
drop table if exists new_release cascade;
create table new_release(
id serial not null,
artist varchar(255) not null,
album varchar(255) not null,
genre varchar(255),
created_at timestamp with time zone default CURRENT_TIMESTAMP,
primary key(id),
constraint u_artist_title unique(artist, album)
);
-- This trigger normalizes the tracks inserted into tmp_track
create or replace function sync_music_data()
returns trigger as
@ -498,6 +511,7 @@ TrackActivity = Base.classes.music_activity
TrackSimilar = Base.classes.music_similar
DiscoveryPlaylist = Base.classes.music_discovery_playlist
DiscoveryPlaylistTrack = Base.classes.music_discovery_playlist_track
NewRelease = Base.classes.new_release
def get_db_session():
@ -955,3 +969,28 @@ your Python interpreter:
If everything went well, you should soon see a new playlist in your collection
named _Discover Weekly [date]_. Congratulations!
## Release radar playlist
Another great feature of Spotify and Tidal is the ability to provide "release
radar" playlists that contain new releases from artists that we may like.
We now have a powerful way of creating such playlists ourselves though. We
previously configured Platypush to subscribe to the RSS feed from
newalbumreleases.net. Populating our release radar playlist involves the
following steps:
1. Creating a hook that reacts to [`NewFeedEntryEvent`
events](https://docs.platypush.tech/platypush/events/rss.html) on this feed.
2. The hook will store new releases that match artists in our collection on the
`new_release` table that we created when we initialized the database.
3. A cron will scan this table on a weekly basis, search the tracks on
Spotify/Tidal, and populate our playlist just like we did for _Discover
Weekly_.
Let's put these pieces together in a new user script stored under e.g.
`~/.config/platypush/scripts/music/releases.py`:
```python
# ~/.config/platypush/scripts/music/releases.py
```