HowTo: convert audio to TAF fast and easy (macOS/Linux)

This is amazing! Thank you very much, used it already multiple times.

I have an additional script which helps to create the required structure for my audio books by placing all episodes into the respective folder.

#!/bin/bash

# Funktion zur Organisation der Hörbuchdateien
organize_audiobooks() {
    local folder_path="$1"
    cd "$folder_path" || { echo "Ordner nicht gefunden!"; exit 1; }

    # Dateien analysieren und organisieren
    for file in *.ogg; do
        # Teile den Dateinamen anhand des Patterns
        # Beispiel: "Die Biene Maja - Majas Geburt - Teil 01.ogg"
        base_name=$(basename "$file")
        audiobook=$(echo "$base_name" | cut -d'-' -f1 | xargs) # Hörbuchname
        episode_title=$(echo "$base_name" | cut -d'-' -f2 | xargs) # Episodentitel
        part=$(echo "$base_name" | grep -oP 'Teil \d+' | xargs) # Teilnummer

        # Hauptordner basierend auf dem Hörbuchnamen erstellen
        main_folder="$audiobook"
        mkdir -p "$main_folder"

        # Unterordner basierend auf dem Episodentitel erstellen
        episode_folder="$main_folder/$episode_title"
        mkdir -p "$episode_folder"

        # Datei in den entsprechenden Ordner verschieben
        mv "$file" "$episode_folder/"
    done

    # Überprüfen, wie viele Dateien in jedem Ordner sind
    echo "Überprüfung der Dateien in den Ordnern:"
    for episode_folder in "$folder_path"/*/*; do
        file_count=$(find "$episode_folder" -type f | wc -l)
        if [ "$file_count" -eq 0 ]; then
            echo "Warnung: Keine Dateien im Ordner '$episode_folder'."
        else
            echo "Im Ordner '$episode_folder' liegen $file_count Datei(en)."
        fi
    done

    echo "Hörbuchdateien wurden erfolgreich organisiert!"
}

# Benutzer nach dem Ordner fragen
read -p "Gib den Pfad zum Ordner mit den Dateien an: " source_folder
organize_audiobooks "$source_folder"

I was wondering about where you got the information how to use the Teddycloud API? My itention is to modify the upload path, to place the generated .TAF files into the destination folder which reduce the effort.

Hi, there are two ways at least.

  1. look into the sources of teddycloud on GitHub.
  2. (more easy) just do the encoding in the webgui with dev mode open (F12) and have a look into the network tab. There are the api calls shown.
1 Like

I used the latter and checked the network tab while uploading a file with the GUI. Then I tried with curl and used the -F "file=@output_file" option instead (which is a little more easy).

You can create directories in your teddyCloud library like this:

curl 'https://192.168.178.11:8443/api/dirCreate?special=library' \
  --data-raw '/Biene Maja' 

When uploading to this folder in your library, use it as path attribute in your http query string:

curl -s -F "file=@$output_file" -w "%{http_code}" "http://$TEDDYCLOUD_IP/api/fileUpload?path=%2FBiene%20Maja&special=library"

You can also download files from your library via API. This is possible as taf or even es raw opus file (without the taf header). I will add a tap input parameter to this script which automatically downloads all needed files, splits existing tafs into their chapters and repackages them in a combined taf file. This will preserve the chapters inside a single episode (which is not possible with the native tap feature).

1 Like

:small_orange_diamond: Update Docker: added ARD Audiothek support :small_orange_diamond:

I just updated the Docker container with support for ARD Audiothek content. It uses their REST API to retrieve the content (no html scraping). Just copy & paste the link of the content and use it as -s parameter (source).

:small_orange_diamond: Usage :small_orange_diamond:

Command:

docker run --rm -v $(pwd):/data ghcr.io/marco79cgn/audio2tonie transcode -s "[AUDIOTHEK-URL]"

Example URL:

https://www.ardaudiothek.de/episode/3nach9-podcast/hape-birthday-ein-3nach9-spezial-zum-60-geburtstag-von-hape-kerkeling/radio-bremen/13935781/

Output:

The output filename will be created automatically and produces valid filenames (without unsupported characters), like Hape.Birthday.ein.3nach9.-Spezial.zum.60.Geburtstag.von.Hape.Kerkeling.taf.

1 Like

Hi,

thank you for your effort! That’s great!

Here is a feature request - would it be possible to scrape all items of a Podcast (programSet) from ARD Audiothek to convert it to Taf?

Thank you very much!

Yes, that‘s totally possible. I already integrated this in my dedicated script here:

It works for mini series or Podcasts up to 12 episodes. This is because I was scraping the html in this former script and the main page only includes the latest 12 items.

In the meantime I figured out how their API works - both for single items and whole program sets (Podcasts/Mini Series). I will implement it as soon as I find some sparetime. The only problem is that there are Podcasts with over 100 episodes and the limit for chapters in tafs is 99.

1 Like

Maybe TAP could do the trick here… :thinking:

No, a tap has the same restrictions. It’s the Toniebox which doesn’t like it. The files play perfectly fine in the integrated web player.

And as a cracy idea, what about providing it as a webstream…?
Would it be possible to assign a “podcast.sh” as source into a tonie-json file…
…and this would just return one episode after another just like it would be any other radio station (mpd liek) stream that ffmpeg in TC could handle?

:small_orange_diamond: Update Docker: add Teddycloud upload :small_orange_diamond:

I updated the Docker container with support for automatic upload to your Teddycloud.

:small_orange_diamond: Usage :small_orange_diamond:

Use the new upload parameter follwed by your teddyCloud ip address: -u 192.168.178.11

The file will be uploaded to the root directory of your library.

Command:
docker run --rm -v $(pwd):/data ghcr.io/marco79cgn/audio2tonie transcode -s /data/test.mp3 -u 192.168.178.11

Output:

It works fine with docker desktop also on windows, but the upload fails all the times

Any hint for that?

I haven’t used Windows in a long time but could it be a file access permission problem?

Do you have curl on Windows? If yes, could you try to upload a file manually from Terminal/Powershell?

curl -F "file=@test.taf" "http://$TEDDYCLOUD_IP/api/fileUpload?path=&special=library"

this works. maybe the problems are spaces in the filename?

Edit: Even that works fine…

I assume it’s related to docker desktop

Strange. Are you using macvlan for teddycloud and is both tc and Docker Desktop running on the same machine?

no, teddycloud on its own raspi with static ip (nothing else running on it)

quite sure, no connection from within the docker container to outside

Could be the case. Maybe you can change this somewhere in the settings of Docker Desktop? I’m using the official “Docker for Mac” (which is the equivalent) and it works there. I haven’t changed any settings.

its a fresh installation…

curl 192.168.178.40

curl: (7) Failed to connect to 192.168.178.40 port 80 after 3117 ms: Couldn’t connect to server

but this confirms that it cant connect to the outside

I just wanted to propose that you try to connect inside my container and do a curl upload manually to your teddycloud:

docker run -it ghcr.io/marco79cgn/audio2tonie bash

docker run -it Package audio2tonie · GitHub bash
root@17f91da93bdc:/app# curl -F “file=@opus2tonie.py” “http://192.168.178.40/api/fileUpload?path=&special=library
curl: (7) Failed to connect to 192.168.178.40 port 80 after 3112 ms: Couldn’t connect to server
root@17f91da93bdc:/app#