From 4c72748b9f594dcf13761aca548445890d746bcb Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 19 Sep 2022 15:39:18 +0200 Subject: [PATCH] wip --- markdown/Automate-your-music-collection.md | 45 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/markdown/Automate-your-music-collection.md b/markdown/Automate-your-music-collection.md index 591e0ad..7f6622d 100644 --- a/markdown/Automate-your-music-collection.md +++ b/markdown/Automate-your-music-collection.md @@ -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 ) -[//]: # (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 +```