Mediatomb – Live Streaming DLNA

Es ist möglich über Mediatomb (DLNA-Server) sunshine-live oder jedes andere Live Streaming Internetradio zu hören.

mediatomb-live-streaming

Dies geht folgendermaßen:

nano /etc/mediatomb/config.xml
<transcoding enabled="yes">

In <mimetype-profile-mappings>:

<transcode mimetype="audio/x-stream" using="streaming"/>

In <profiles>:

<profile name="streaming" enabled="yes" type="external">
      <mimetype>audio/L16</mimetype>
      <first-resource>yes</first-resource>
      <accept-url>yes</accept-url>
      <sample-frequency>44100</sample-frequency>
      <audio-channels>2</audio-channels>
      <hide-original-resource>yes</hide-original-resource>
      <agent command="/etc/mediatomb/transcode.sh" arguments="-f transcode_playlist_to_pcm -i %in -o %out -t pls"/>
      <buffer size="1048576" chunk-size="4096" fill-size="1024"/>
</profile>

In /etc/mediatomb/transcode.sh:

#!/bin/bash
display_usage() {

  USAGE="
  Usage:
    mediatomb-transcode -f function_name -i input -o output [function_arguments]

  Generic Options:
   -h, --help                  Display this help message.
   -i, --input                 Input file that is meant to be transcoded.
   -o, --output                Output file that will be read back by MediaTomb.
   -f, --func                  Function to execute from the script.
  "
  echo "${USAGE}"
  echo "Available Functions:"
  FUNCTIONS=($(compgen -A function | grep "^transcode_*"))
  printf " %s\n" "${FUNCTIONS[@]}"
  exit 1

}

transcode_to_pcm() {

  PROG=$(which avconv)
  if [ -z "$PROG" ]; then
    PROG=$(which ffmpeg)
  fi
  if [ -n "$PROG" ]; then
    exec "$PROG" -i "$1" -ac 2 -ar 44100 -y -f s16be "$2"
  fi

}

transcode_playlist_to_pcm() {

  INPUT=$1
  OUT_FILE=/tmp/playlist.tmp
  wget -q -O $OUT_FILE $INPUT
  if [ $? -eq 0 ]; then
    PLAYLIST_TYPE=${FUNC_ARGS["-t"],,}
    case "$PLAYLIST_TYPE" in
      "asx")
        RADIO_URL=$(grep -iE "^([[:space:]]*)<ref href.*=" $OUT_FILE | head -n 1 | tr -d '\"')
        RADIO_URL=${RADIO_URL#*=}
        RADIO_URL=${RADIO_URL//'/>'/}
        ;;
      "pls")
        RADIO_URL=$(grep -i "^file.*=" $OUT_FILE | head -n 1)
        RADIO_URL=${RADIO_URL#*=}
        ;;
      "m3u")
        LINE=$(head -n 1 $OUT_FILE)
        if [ "$LINE" == "#EXTM3U" ]; then
          RADIO_URL=$(grep -viE "(^#EXT|^$)" $OUT_FILE | head -n 1)
        else #normal m3u
          RADIO_URL=$LINE
        fi
        ;;
      *)
        echo "Invalid playlist type provided ($PLAYLIST_TYPE)"
        exit 1
        ;;
    esac
    if [ -a $OUT_FILE ]; then
      rm $OUT_FILE
    fi
    if [ "$RADIO_URL" != "" ]; then
      RADIO_URL=$(echo $RADIO_URL | tr -d '\r')
      transcode_to_pcm "$RADIO_URL" "$2"
    fi
  fi
}

declare -A FUNC_ARGS
while [ "$#" -gt "0" ]
do
  case "$1" in
      -f|--func)
        FUNCTION=$2
        shift; shift;
        ;;
      -i|--input)
        INPUT=$2
        shift; shift;
        ;;
      -o|--output)
        OUTPUT=$2
        shift; shift;
        ;;
      -h|--help)
        display_usage
        ;;
      *)
        FUNC_ARGS+=([$1]="$2")
        shift; shift;
        ;;
  esac
done

if [[ "$FUNCTION" != "" && "$INPUT" != "" && "$OUTPUT" != "" ]] ; then
  ${FUNCTION} "$INPUT" "$OUTPUT"
else
  display_usage
fi
chmod +x /etc/mediatomb/transcode.sh
Mediatomb -> Database -> add Item -> External Link (URL)
sunshinelive
http://stream.sunshine-live.de/hq/mp3-128/stream.sunshine-live.de/play.pls

http://listen.housetime.fm/dsl.pls

http://listen.technobase.fm/dsl.pls

http-get

object.item.audioItem.musicTrack

audio/x-stream

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben scrollen