-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_nhk_news_live.bash
64 lines (54 loc) · 1.89 KB
/
check_nhk_news_live.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Watch NHK News Live and kick downloader up
#
# ORIGIN: 2021-08-26 by hmr
# Read common functions
. ./common_func.bash
TARGET_SRV="https://www3.nhk.or.jp"
TARGET_DOC="news/json16/realtime.json"
TARGET_URL="${TARGET_SRV}/${TARGET_DOC}"
# ライブ放送情報のJSONを取得
RT_JSON="$("${PROG_CURL_BIN}" -s -S "${TARGET_URL}")"
# RT_JSON="$(cat realtime.json)" # for development
if [[ -z "${RT_JSON}" ]]; then
eecho "can't get document from ${TARGET_URL}"
exit 1
fi
# 実施されているライブ放送の数を取得
NUM=$(jq -rc '.item | length' <<< "${RT_JSON}")
if [ "${NUM}" -lt 1 ]; then
# ライブ放送が実施されていないので終了
iecho "live streaming not found"
exit
fi
# ライブ放送が実施されている
IFS=$'\n'
for LINE in $(jq -c '.item[] | [.title, .link]' <<< "${RT_JSON}")
do
[ -z "${LINE}" ] && continue
# ライブ放送のタイトル、URL、ライブ放送番号(rt0123456形式)
ARR=($(jq -r '.[]' <<< "${LINE}"))
LIVE_TITLE="${ARR[0]}"
LIVE_URL="${TARGET_SRV}${ARR[1]}"
LIVE_NUM="$(basename "${ARR[1]}" | sed -e 's/\.html//')"
# 録画スキップ設定の有無を確認
if [ -e "${LIVE_NUM}.norec" ]; then
iecho "skipping live straming \"[${LIVE_NUM}] ${LIVE_TITLE}\" due to setting"
"${PROG_PKILL_BIN}" -f "${LIVE_NUM}"
else
# すでに録画を開始しているか判定
if ! "${PROG_PGREP_BIN}" -f "${LIVE_URL}" >& /dev/null; then
# 録画プログラムを呼び出す
iecho "live straming \"[${LIVE_NUM}] ${LIVE_TITLE}\" found at ${LIVE_URL}"
if [ -e "${LIVE_NUM}.norec" ]; then
iecho "but it will be skipped due to setting."
else
${PROG_GET_NHK_NEWS_LIVE_HLS} "${LIVE_URL}" &
fi
else
# 録画中であることを通知
iecho "live streaming \"${LIVE_TITLE}\" is now being recorded"
fi
fi
done
# vim: ft=sh:ts=4:sw=4:noet