Skip to content
Generate a playlist of your top favorites tracks on lastfm and post it on twitter or mastodon.
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

lastfm_pg : lastfm playlist generator

Codacy Badge Build Status codecov

Generate playlist of a user's favorite most played tracks for a certain timespan and post it to twitter or mastodon.

This utility needs a valid config file with your lastfm API keys (get them at, twitter API keys (get them at and mastodon account information in the ~/.config/lastfm_pg/config.ini file (see config_sample.ini for an example).

Running the script for the first time will generate a sample config file if one doesn't exist yet.

In order to run the script at a given time, some systemd services are provided in the systemd-service directory. You will have to change them to match your configuration, more specifically the WorkingDirectory and ExecStart directive.


  • pylast
  • tweepy

Installation in a virtualenv (recommended)

git clone
cd lastfm_pg
pipenv install '-e .'


Show the help and the available options.

lastfm_pg -h
usage: lastfm_pg [-h] [--debug] [--username USERNAME] [--no_upload]
                 [--timeframe TIMEFRAME] [--social-media SOCIAL_MEDIA]
                 [--not-only-favorites] [--config_file CONFIG_FILE]
                 [--template_file TEMPLATE_FILE] [--hashtag HASHTAG]

Generate playlist of a user's favorite most played tracks for the last week
and post it to twitter or mastodon.

optional arguments:
  -h, --help            show this help message and exit
  --debug               Display debugging information
  --username USERNAME, -u USERNAME
                        Lastfm usernames, separated by comma (default :
                        username section of the config.ini file).
  --no_upload           Disable the upload. Use it for debugging.
  --timeframe TIMEFRAME, -t TIMEFRAME
                        Timeframe (Accepted values : 7day, 1month, 3month,
                        6month, 12month, overall. Default : 7day).
  --social-media SOCIAL_MEDIA, -s SOCIAL_MEDIA
                        Social media where the playlist will be posted
                        (twitter, mastodon or all. Default : all).
  --not-only-favorites, -n
                        The playlist will be composed of any tracks, not only
                        favorite tracks.
  --config_file CONFIG_FILE
                        Path to the config file (Default :
  --template_file TEMPLATE_FILE
                        Path to the template file for the tweet (Default :
  --hashtag HASHTAG     Hashtag to insert at the end of each secondary tweets
                        (Default : '#lastfm').

Systemd service

cp systemd-service/* ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable --now twitter_lastfm_pg_weekly.timer


The posted tweets will follow the template. See the tweet_template.txt file for an example.

Available variables :

  • timeframe
  • username
You can’t perform that action at this time.