きっかけ

どうしてもこれを録音したかったのです

FMプラプラ(FM++/エフエムプラプラ)はなかなかの強敵のようで、そう簡単にはツールが見つからなかったのですが世の中には賢い方々がいらっしゃるようでとても助かります

てことで、こいつをコンテナ化してみました

Dockerfile

FROM alpine
MAINTAINER Nobuhiro Oki

ARG http_proxy

RUN apk add tzdata ffmpeg py3-pip    \
    && adduser -g '' -h /rec -D rec  \
    && pip3 install websocket-client \
    && wget -O- https://pastebin.com/raw/gQ0Ay2aN    \
      | tr -d '\r'                                   \
      | sed '1s/python/&3/' >/usr/local/bin/fmplapla \
    && chmod a+x /usr/local/bin/fmplapla

WORKDIR /rec
USER rec
ENV HISTFILE=''

WORKDIR /usr/local/bin
COPY rec.sh rec

ENTRYPOINT ["sh","/usr/local/bin/rec"]
CMD ["-h"]

rec.sh

#/bin/sh

usage() {
  cat <<...
${0##*/} - netwok radio recorder

Parameters:
  REC_MIN     : recording duration [minute]
  REC_SEC     : recording dulation [second], override REC_MIN
  REC_STATION : radio statuon url  (default: radioheart / Sanjo, Niigata, Japan)
  REC_PREFIX  : output file prefix (default: radioheart <= same as REC_STATION )
  REC_TZ      : TimeZone for timestamp of output file name (default: Asia/Tokyo)

Note:
  - all parameters must be given by environment variable.
  - recording file is placed on /rec (\$HOME directory of 'rec' user)
    - if you use 'root' user in container, output directory is /root

Example:
  rec ラヂオは&#12316;と while 30min, output /tmp directory of docker-host
    docker run --rm -v /tmp:/rec -e REC_MIN=30 rec-fmplapla rec

  after into the container, execute 'rec' command
    docker run -it --rm -v /tmp:/rec sh
      (in container's shell) 
        export REC_MIN=30
        export REC_PREFIX=SATOCHIN
        rec

  same as above, using 'env' command
    docker run -it --rm -v /tmp:/rec sh
      (in container's shell) 
        env REC_MIN=30 REC_PREFIX=SATOCHIN sh /usr/local/bin/rec

  show station list
    docker run --rm rec-fmplapla -l

...
}

# station list
station_list() {
wget                    \
  -q                    \
  -O-                   \
  https://fmplapla.com/ \
| grep                \
  -oE                 \
  '(href|alt)=[^> ]*' \
| awk                         \
  '/^alt=/{print a,$0}{a=$0}' \
| awk                                     \
  -F'["/]+'                               \
  '/\/.*\//{printf "%-20s %s\n", $2, $4}'
}

# when 1st parameter is executable...
command -v $1 >/dev/null 2>&1 && exec $@
[ -x $1 ] && exec $@

# station list
[ "$1"_ = "-l_" ] && { station_list; exit 0; }

# help
[ "$1"_ = "-h_" ] && { usage;        exit 0; }


# parameters
duration_min=${REC_MIN:-1}
duration_sec=${REC_SEC:-$(expr $duration_min \* 60)}
station_id=${REC_STATION:-radioheart}
file_prefix=${REC_PREFIX:-"$station_id"}
TZ=${REC_TZ:-Asia/Tokyo}

rec_filename=$HOME/${file_prefix}_$(env TZ=$TZ date +%Y%m%d-%H%M).m4a

# recording
set -x
fmplapla \
  --station "$station_id" \
  --time "$duration_sec" \
  | \
ffmpeg \
  -loglevel quiet \
  -i pipe: \
  -c libvorbis \
  -acodec aac \
  -f mp4 \
  "$rec_filename"

build

$ podman build . -t rec-fmplapla
(略)

$ podman images rec-fmplapla
REPOSITORY               TAG      IMAGE ID       CREATED          SIZE
localhost/rec-fmplapla   latest   2e70db1ce15b   52 minutes ago   119 MB

crontab

0 6,20 * * * podman run --rm -v ~/Downloads/rec:/rec -e REC_STATION=radioheart -e REC_MIN=60 -e REC_PREFIX=さとちん電波 rec-fmplapla rec

station list

$ podman run --rm rec-fmplapla rec -l
fmhanabi             FMはなび
fmnemaline           FMねまらいん
fmasmo               FMあすも
bikkifm              Bikki-FM
fmaozora             FMあおぞら
radioheart           ラヂオは&#12316;と
fmtokamachi          FMとおかまち
(略)

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2020-06-16 (火) 19:39:55