View Source Creating a file archive

Creating a file archive

Mix.install(
  [{:lastfm_archive, "~> 0.10"}],
  config: [
    lastfm_archive: [
      data_dir: "./lastfm_data/",
      user: ""
    ]
  ]
)

alias LastfmArchive.Livebook, as: LFM_LB
:ok

Introduction

This guide uses the lastfm_archive library to create an archive containing scrobbles: music tracks that Lastfm users have been listening to. It downloads scrobbles via the Lastfm API and stores them as raw JSON data in a local file location.

Requirement

  • install and start Livebook
  • run this Livebook guide
  • configure Livebook as instructued below, click on Notebook dependencies and setup, Setup (above)

Configuration

Lastfm archive has been configured as a dependency in Setup above. You need to check and modify the following configs:

  1. user: specify a Lastfm username in this config
  2. data_dir (optional): by default scrobbles data is stored in ~/lastfm_data/ directory within your home directory. Modifiy this location if other directory is preferred

API key environment variable

To access the API provided by Lastfm, you need to apply for a 32-digit string key. This key will be used when downloading data via Lastfm API.

Once you have obtained this key, add it as LFM_API_KEY secret and share it with this Livebook - see Secrets management for further details.

Scope

Run the following code (click Evaluate below) to find out what are you about to archive:

LFM_LB.info()

Archiving

Run the follow to begin archiving. This will initate a process that fetches scrobbles on a daily basis, at around every 1s (within permissable Lastfm API request rate). The process is memoised or cached. It can be halted (click Stop) and restarted without data being re-fetched and the API being unnecessarily called again.

LastfmArchive.sync()

Status

Run the following for a heatmap and counts, checking the archiving progress. Rerun the code to get the latest status.

[LFM_LB.monthly_playcounts_heatmap(), LFM_LB.yearly_playcounts_table()]
|> Kino.Layout.grid(columns: 2)