Is there a possibility to play files randomly?

Hi,
Is there a possibility to play files randomly?
For example, I have all “Three ???” episodes and I want to play one randomly.

Hi, as far as i know not directly, but… in HowTo: Toniebox as Jukebox [mpd] [teddyCloud] is described how to setup a media server which streams content to the box. maybe that can do that.

Yes, mpd can play randomly as well as never ending stream.

Thanks.
Mpd is only streaming?
Can I stream a random episode with a teddy? Or is it like a radio channel?

Well, mpd provides a (web)stream of your own radio chanel. You can configure your mpd to randomly play titles and/or let it loop for ever and so on…

The tonie on the box triggers teddycloud to play that (web)stream, just like it would be a “live tonie”. So what ever the mpd stream would provide, it will be played on toniebox.

In regards to the question: yes, mpd is only a stream, like a radio channel. And yes although it is only a stream, it can play random episodes. And no, it is not teddy doing that, but mpd. Teddy will only link your stream(playback) with a tonie/custom tag.

I had a similar idea. I wrote a shell script which gets all my “Die drei ???” audiobooks from the Teddycloud library, chooses a random episode and assigns it to a Tonie.

#!/bin/bash
TEDDYCLOUD_IP=192.168.178.11

# check amount of episodes
count=$(curl -s "http://$TEDDYCLOUD_IP/api/fileIndexV2?path=/DDF&special=library" | jq '.files' | jq length)

# roll the dice
r=$(( $RANDOM % $count )); 

# get random episode name
episodeName=$(curl -s "http://$TEDDYCLOUD_IP/api/fileIndexV2?path=/DDF&special=library" | jq -r ".files[$r].name")

# assign episode to tonie (uid)
curl "http://$TEDDYCLOUD_IP/content/json/set/55********0304e0?overlay=582B0A599452" \
  --data-raw "source=lib://DDF/$episodeName"

Now you could run this manually or automatically or maybe once a day. You could also convert it into an iOS shortcut and run it via voice (Siri) or as an automation or even nfc triggered.

2 Likes

Hello! Inspirated by your script, here is a bit more advanced version.

#!/bin/bash

# Check if parameters are passed
if [ "$#" -lt 4 ]; then
    echo "Usage: $0 TEDDYCLOUD_IP DIRECTORY ORIGINAL_UID TONIEBOX_MAC"
    echo ""
    echo "Parameters:"
    echo "  TEDDYCLOUD_IP   - The IP address of the TeddyCloud server (e.g., 192.168.178.100)"
    echo "  DIRECTORY       - The path to the library (e.g., /DDF)"
    echo "  ORIGINAL_UID    - The UID of the Tonie in the format E0:04:03:50:FF:FF:FF:FF"
    echo "  TONIEBOX_MAC    - The MAC address of the Toniebox without colons (e.g., 582B0A545452)"
    echo ""
    echo "Example: $0 192.168.178.100 /DDF E0:04:03:50:FF:FF:FF:FF 582B0A545452"
    exit 1
fi

# Assign parameters to variables
TEDDYCLOUD_IP="$1"
DIRECTORY="$2"
ORIGINAL_UID="$3"
TONIEBOX_MAC="$4"

# Prepare UID by removing colons and splitting into two parts
cleanUID=$(echo "$ORIGINAL_UID" | tr -d ':')
firstBytes="${cleanUID:6:2}${cleanUID:4:2}${cleanUID:2:2}${cleanUID:0:2}"  # First 4 bytes (reversed)
lastBytes="${cleanUID:14:2}${cleanUID:12:2}${cleanUID:10:2}${cleanUID:8:2}"  # Last 4 bytes (reversed)

# API call to fetch file index from TeddyCloud
jsonResponse=$(curl -s "http://$TEDDYCLOUD_IP/api/fileIndexV2?path=$DIRECTORY&special=library")
if [ -z "$jsonResponse" ]; then
    echo "Error: No response received from TeddyCloud."
    exit 1
fi

# Determine the number of episodes in the specified directory
count=$(echo "$jsonResponse" | jq '.files' | jq length)
if [ "$count" -le 0 ]; then
    echo "Error: No files found in the directory $DIRECTORY."
    exit 1
fi

# Select a random episode
r=$(( $RANDOM % $count ))
episodeName=$(echo "$jsonResponse" | jq -r ".files[$r].name")

# Log the selected episode
echo "Randomly selected episode: $episodeName for the Tonie with UID $ORIGINAL_UID"

# Assign the episode to the Tonie
curl -s "http://$TEDDYCLOUD_IP/content/json/set/$lastBytes$firstBytes?overlay=$TONIEBOX_MAC" \
  --data-raw "source=lib://$DIRECTORY/$episodeName" \
  --data-raw "nocloud=true" # Detach the Tonie from the TonieCloud