All posts by Max Chinni

Automatic download of album covers

Automatic download of album covers (with a Simple Bash Script)

Managing a digital music library can be both fun and a little obsessive. If you’re like me, you don’t just want your tracks properly tagged, you need them to look good too. Having the album cover right there makes browsing way more satisfying (and helps music servers like Navidrome or Jellyfin look polished).

That’s why I put together a small Bash script that automatically fetches album art using Last.fm. No need to manually copy-paste images anymore, just run the script in your album folder, and it does the heavy lifting for you.

How It Works

The idea is simple:

  1. Guess the album artist and title from the current folder (with some prompts if you want).
  2. Construct the right Last.fm album page URL.
  3. Parse the page to find the cover image.
  4. Download it to cover.jpg.

That’s it. Nothing magical, but it saves a lot of clicking.

Here’s the script itself:

#!/bin/bash

set -e

_error()
{
    echo "$(basename "$0" .sh): $1" >&2
    exit "$2"
}

_info()
{
        echo "[INFO] $*"
}

urlencode()
{
        local length="${#1}"

        for ((i=0; i<length; i++)); do
                local c="${1:i:1}"

                case $c in
                        [a-zA-Z0-9.~_-])
                                printf '%s' "$c"
                                ;;
                        ' ')
                                printf "%%20"
                                ;;
                        *)
                                printf '%%%02X' "'$c"
                                ;;
                esac
        done
        echo
}

##
# Init
#
umask 0002
output="cover.jpg"
batch=

##
# Checks
#
[[ ! -r $output ]] || _error "$output exists" 2
[[ $1 = '--batch' ]] && batch=1

##
# Main
#
defaultArtist="$(cd .. && basename "$(pwd)")"
defaultAlbum="$(basename "$(pwd)")"
if [[ $batch -ne 1 ]]; then
        read -p "artist [$defaultArtist]: " artist
        read -p "album [$defaultAlbum]: " album
fi
[[ -z $artist ]] && artist="$defaultArtist"
[[ -z $album ]] && album="$defaultAlbum"

{
        url="https://www.last.fm/music/$(urlencode "$artist")/$(urlencode "$album")"
        _info "search cover url in $url"
        cover_url="$(wget "$url" -O - | pup 'div.album-overview-cover-art img attr{src}')"
        [[ -n $cover_url ]] || _error 'cannot find cover_url' 5
        _info "download cover url $cover_url"
        curl -s "$cover_url" >"$output"
        [[ -r $output ]]
} || _error "cannot find cover" 99

echo
echo "Done"
exit 0

Usage

Run this script inside your album’s folder. For example:

~/music/navidrome/Afterhours/Ballate per piccole iene$ download-album-cover.sh
artist [Afterhours]:
album [Ballate per piccole iene]:
[INFO] search cover url in https://www.last.fm/music/Afterhours/Ballate%20per%20piccole%20iene
--2025-09-11 09:42:43--  https://www.last.fm/music/Afterhours/Ballate%20per%20piccole%20iene
Resolving www.last.fm (www.last.fm)... 151.101.241.188, 2a04:4e42:39::444
Connecting to www.last.fm (www.last.fm)|151.101.241.188|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: /music/Afterhours/Ballate+Per+Piccole+Iene [following]
--2025-09-11 09:42:48--  https://www.last.fm/music/Afterhours/Ballate+Per+Piccole+Iene
Reusing existing connection to www.last.fm:443.
HTTP request sent, awaiting response... 200 OK
Length: 632693 (618K) [text/html]
Saving to: ‘STDOUT’

-                                      100%[=========================================================================>] 617.86K  4.00MB/s    in 0.2s

2025-09-11 09:42:50 (4.00 MB/s) - written to stdout [632693/632693]

[INFO] download cover url https://lastfm.freetls.fastly.net/i/u/500x500/d0993bb25c9ea5085beb29486dcb5408.jpg

Done

When executed, it will suggest the folder names as defaults for artist and album. You can simply hit enter if they’re correct, or type something else if not.

  • By default, it downloads the cover as cover.jpg.
  • If you already have a cover.jpg file, it won’t overwrite it.
  • There’s also a --batch mode to skip interaction, which can be handy if you want automation.

Dependencies

You’ll need:

  • wget (to fetch the Last.fm HTML)
  • pup (for HTML parsing)
  • curl (to download the image)

On most Linux distros, these are easy to install with your package manager.

Why This Is Handy

For someone running a headless server or managing a huge MP3/FLAC collection, this is a lifesaver. Media players and tools like Navidrome, Jellyfin, or even plain old file explorers look so much better with consistent artwork. And because it’s just a shell script, you can tweak it however you like, change defaults, switch sources, or even integrate into a bigger tagging pipeline.

How to Install Tasmota on Shelly 1 from Linux

This guide will show you how to flash Tasmota firmware onto a Shelly 1 device using Linux. You will use the PlatformIO toolchain to communicate with the device, erase the existing firmware, and install the Tasmota firmware via serial communication. After flashing, you’ll configure the device to connect to your Wi-Fi and MQTT broker.

Prerequisites

  1. Linux PC
  2. Shelly 1 device
  3. USB to Serial adapter (e.g., FTDI adapter)
  4. Jumper wires to connect the Shelly 1 to the USB-to-serial adapter
  5. Tasmota binary downloaded to your local machine

Make sure that PlatformIO and Python 3 are installed on your system.

Step 1: Install PlatformIO

If you don’t already have PlatformIO installed, you can install it via Python’s package manager pip:

pip install platformio

This installs the platformio command-line interface (CLI), which will be used to flash the firmware onto the Shelly 1.

Step 2: Connect Shelly 1 to Your Linux PC

  1. Disconnect Shelly 1 from mains power to avoid electric shock.
  2. Connect the TX, RX, GND, and VCC pins of the Shelly 1 to the corresponding pins of your USB-to-serial adapter (TX->RX, RX->TX, GND->GND, VCC->3.3V). GPIO0 has to be temporary connected to GND to enter programming mode.
  3. Plug the USB-to-serial adapter into your Linux PC.
  4. You can now disconnect GPIO0 from GND or leave it as is.

Step 3: Test Communication with the Device

Before proceeding with the flashing, test whether your Linux PC can communicate with the Shelly 1 via serial.

Run the following command to check communication (replace /dev/ttyUSB0 with your actual serial device if needed):

python3 ~/.platformio/packages/tool-esptoolpy/esptool.py -p /dev/ttyUSB0 flash_id

If the communication is successful, you should see information about the connected ESP8266 chip inside the Shelly 1.

Step 4: Erase the Flash Memory

You have to reconnect the device to the pc as seen in Step 2.

Next, you need to erase the existing firmware on the device to ensure a clean installation of Tasmota. To erase the flash memory, run the following command:

python3 ~/.platformio/packages/tool-esptoolpy/esptool.py -p /dev/ttyUSB0 erase_flash

This process clears the current firmware from the Shelly 1.

Step 5: Flash Tasmota Firmware

You have to reconnect the device to the pc as seen in Step 2.

Once the flash memory is erased, you can now flash the Tasmota firmware onto the device. Replace the path ~/Downloads/tasmota.bin with the actual path to your downloaded Tasmota binary file:

python3 ~/.platformio/packages/tool-esptoolpy/esptool.py -p /dev/ttyUSB0 write_flash -fm dout 0x0 ~/Downloads/tasmota.bin

This writes the Tasmota firmware onto the Shelly 1.

Step 6: Configure the Device via Serial

After flashing, you can configure the Shelly 1 via serial connection using picocom. If it’s not installed on your system, you can install it with:

sudo apt install picocom

To open a serial connection, run:

picocom --echo --omap crcrlf --baud 115200 /dev/ttyUSB0

Once connected, you will see the device’s output. You can now paste the following configuration string to set up Wi-Fi and MQTT parameters:

Backlog ssid1 YourSSID; password1 veryStrongWiFiPassword; MqttHost 192.168.1.200; Template {"NAME":"Shelly 1","GPIO":[1,1,0,1,224,192,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":46};

Parameters in the Configuration String:

  • ssid1: Replace YourSSID with the name of your Wi-Fi network.
  • password1: Replace veryStrongWiFiPassword with your Wi-Fi password.
  • MqttHost: Set this to the IP address of your MQTT broker (e.g., 192.168.1.200).
  • Template: This defines the GPIO pin mapping for the Shelly 1.

Step 7: Verify the Device Connection

Once the Shelly 1 reboots, it should connect to your Wi-Fi and MQTT broker based on the configuration provided. You can now control it via the MQTT interface or the Tasmota web interface.


Congratulations! You have successfully flashed and configured Tasmota on your Shelly 1 device from Linux.

Tolino Shine 3 – upgrade if you have installed TWRP

If have installed TWRP and you want to upgrate to the latest firmware using the official procedure, you have to restore the original recovery.img.

  1. shutdown the device
  2. on the pc extract recovery.img from the update.zip file which contains your current firmware.

    tolino-15.3.0$ unzip update.zip recovery.img
    
  3. on the pc run the flash command and keep it waiting

    $ fastboot flash recovery recovery.img 
    < waiting for any device >
    
  4. (enter fastboot mode) keep pressed the power up button on the device while inserting the USB cable and in about 25 seconds you should see

    Sending 'recovery' (6474 KB)                       OKAY [  0.245s]
    Writing 'recovery'                                 OKAY [  0.906s]
    Finished. Total time: 1.170s
    
  5. reboot the device and now you should be able to upgrade it with the standard procedure

Tolino Shine 3 – 15.3.0 update

Good news

The adbd binary is the same of 14.1.0:

$ md5sum tolino-1*/ramdisk/sbin/adbd
1d23e203eba05102e6cb642a117b8d64  tolino-14.1.0/ramdisk/sbin/adbd
1d23e203eba05102e6cb642a117b8d64  tolino-15.3.0/ramdisk/sbin/adbd

The direct download link for the new Shine 3 firmware is https://tolinodownload-a.akamaihd.net/ereader/15.3.0/OS44/update.zip.

As a sidenote, you can find the latest Tolino updates on the Tolino website.

Everything documented is still relevant

Compile busybox (Magisk) for Android with ndk

Credits

All the credits to topjohnwu and osm0sis.

Prerequisites

I’m working on Ubuntu 21.10, so

$ apt install git google-android-ndk-installer

Instructions

Clone the repository

git clone https://github.com/topjohnwu/ndk-box-kitchen.git

Follow the instruction, as today are

git clone https://git.busybox.net/busybox/
git clone https://github.com/SELinuxProject/selinux.git jni/selinux
git clone https://android.googlesource.com/platform/external/pcre jni/pcre

Choose the supported busybox version

cd busybox
git checkout 1_34_1
cd ..

Build

/usr/lib/android-ndk/ndk-build all

Push on a device and test

adb push ./obj/local/armeabi-v7a/busybox /data/local/tmp
adb shell chmod 775 /data/local/tmp/busybox
adb shell /data/local/tmp/busybox date
Mon Nov 21 21:08:47 CET 2021

Install as you want, for example

adb shell
cd /data/local/tmp/
mkdir xbin
cd xbin
../busybox --install .
export PATH="$(pwd):$PATH"