# Creating a file archive ```elixir Mix.install( [{:lastfm_archive, "~> 1.2"}], config: [ lastfm_archive: [ data_dir: "./lastfm_data/", user: "" ] ] ) alias LastfmArchive.Livebook, as: LFM_LB :ok ``` ## Introduction This is a step-by-step guide to creating a local file archive containing [Last.fm scrobbles](https://www.last.fm/about/trackmymusic), i.e. music tracks that you have been listening to. This uses the [lastfm_archive](https://github.com/boonious/lastfm_archive) tool that facilicates scrobbles downloading from the Last.fm API and stores them in raw JSON files. **Why?** This grounds your data, backs up your music listening history, keeping it safe. You can also use the archive personally in many ways, in other applications. For example, [transforming the data](https://hexdocs.pm/lastfm_archive/transforming.html) into suitable formats for interesting analytics and visualisation. ### Prerequisite * [Setup, installation](https://hexdocs.pm/lastfm_archive/setup.html) Livebook ## Scope Run the following code (click `Evaluate` below) to find out what are you about to archive: ```elixir LFM_LB.info() ``` ## Archiving Run the follow to begin archiving. This will initate a process that fetches daily scrobbles at around every 1s (within permissable Lastfm API request rate). The process is memoised or cached. It can be halted (click `Stop`) and resumed without data being re-fetched. This prevents unnecessarily calls being made to the API. ```elixir LastfmArchive.sync() ``` ## Status: daily playcounts Run the following to visualise the archiving process and progress. The code displays daily and annual playcounts stats. It also provides heatmaps visualisation. Rerun the code to get the latest status. See a [sample output](https://hexdocs.pm/lastfm_archive/assets/img/livebook_heatmap.png). ```elixir LastfmArchive.default_user() |> LFM_LB.render_playcounts_heatmaps() ``` ## Year option `:year`: archiving scrobbles from a given year option. For example: ```elixir # change year to one containing scrobbles LastfmArchive.default_user() |> LastfmArchive.sync(year: 2023) ``` ## Date option `:date` archiving scrobbles from a given date ```elixir # change date to one containing scrobbles LastfmArchive.default_user() |> LastfmArchive.sync(date: ~D[2023-09-03]) ``` ## Overwrite option `:overwrite` any existing scrobbles, ignoring archiving status cache ```elixir LastfmArchive.default_user() |> LastfmArchive.sync(date: ~D[2023-09-03], overwrite: true) ```