Why Yoink?
While corporations “protect” music transfer with DRM and data monopolization, storing and transferring offline audio files across systems really is not that complicated at all. It’s impressive that they actually put a paywall on offline listening when it is such simple functionality.
In the modern era, having an offline library is both convienient and practical. It’s just tough to source the music, especially if you are trying to do so legally. “Purchasing” songs from iTunes is prohibitively expensive. ($10 for an album with 20 MB of data, no thanks) Further, data lords like Spotify require you to go online every 30 days to “keep” your downloads…
All this said, music eventually gets transformed into electrical signals that get sent to your
headphones or speakers. On Linux, this is typically done through some combination of pipewire
,
pulseaudio
, and/or alsa
.
A Useful Tool
The program sox
turns recording the digital encoding of
these electrical signals into a shell command. https://askubuntu.com/q/1260805
sox -t pulseaudio alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -t flac recording.flac
This is similar to what OBS and other audio/video recording software is doing behind the scenes.
Keep in mind that while the output is encoded in flac, the true quality of the output is determined
by the sound that you were recording. Also, lossless audio is considerably larger than lossy audio.
If you’re looking to maximize your songs-per-memory-card, you will probably want to convert to a
lossy format like mp3
anyway.
Metadata
It is useful to track metadata about your songs too. You could theoretically put this in the file
name but formats like flac
and mp3
support including metadata like title and author inside of
the audio file. The premier audio manipulation platform, ffmpeg
makes
converting encodings and adding metadata easy.
ffmpeg -i recording.flac -metadata author='Ryan' recording.mp3
You can even do album art once you know the standard format. example
Automation
You could use these two tools to record and tag anything that you have already listened to. However,
running the two commands described above manually is a huge pain. That’s where auto-audio-recorder
comes in.
https://git.beefslab.com/michael/auto-audio-recorder
This program consists of a local server that interfaces with a firefox extension. While you listen to music on Spotify, it automatically records, splits, and tags each song. It even mutes the tab and stops recording when it detects an ad.
Unfortunately for you I never wrote up a README.md for the project. For the client it’s as simple as
running npm install
, node main.js
. You might need to install a few dependency packages. (like ffmpeg
,
gst-launch-1.0
, etc.) Once the client is running, add the extension to Firefox
and it will start sending events over to the server indicating which song is playing.
Tips
Be sure to replace the device name
with your computer’s pulseaudio sink name. You can get your sink names (like
alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
) using the following command. Make sure to
include .monitor
pacmd list-sinks