Created
November 10, 2011 11:39
-
-
Save tf0054/1354667 to your computer and use it in GitHub Desktop.
NHKラジオ語学講座ダウンロードシェル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| VERSION='2011/9/4 08:35:38 UTC' | |
| CMDDIR='/home/00962724/radio'; | |
| OUTDIR='/home/00962724/radio/out'; | |
| YEAR='2011' | |
| ARTIST='NHK' | |
| downfiles() | |
| { | |
| TARGET=${1} | |
| ADDURL1=${2} | |
| ADDURL2=${3} | |
| mkdir -p ${TARGET} | |
| cd ${TARGET} || exit 1 | |
| TMPFILE1="`mktemp`" | |
| TMPFILE2="`mktemp`" | |
| while read -r codeline | |
| do | |
| testline=${codeline#*code=} # 最初のcode=より後ろを取り出す | |
| SCRAMBLECODE=${testline:1:14} # 2文字目から14文字 | |
| echo ${SCRAMBLECODE} && echo | |
| URL=${BASEURL}${ADDURL1}/${SCRAMBLECODE}/${ADDURL2} | |
| ${WGET} -O "${TMPFILE1}" ${URL} | |
| if test $? -eq 0; then | |
| grep \.${TARGETEXT} "${TMPFILE1}">"${TMPFILE2}" | |
| while read -r line | |
| do | |
| echo "${line}" | |
| line=${line#*title=*} # 最初のtitleより後ろの文字列 | |
| line=${line#*\"*} # 最初の"より後ろの文字列を取り出す | |
| title=${line%%\"*} # 最初の"より前の文字列を取り出す | |
| echo "${title}" | |
| line=${line#*hdate=*} # 最初のhdateより後ろの文字列 | |
| line=${line#*\"*} # 最初の"より後ろの文字列を取り出す | |
| hdate=${line%%\"*} # 最初の"より前の文字列を取り出す | |
| if [[ $hdate == 10* ]]; then | |
| echo "${hdate}" | |
| line=${line#*file=*} # 最初のfileより後ろの文字列 | |
| line=${line#*\"*} # 最初の"より後ろの文字列を取り出す | |
| file=${line%%\"*} # 最初の"より前の文字列を取り出す | |
| file=${file%*\.${TARGETEXT}} # 指定拡張子の切取をおこなう | |
| echo "${file}" | |
| TARGETFILE="${title}_${hdate}.${TARGETEXT}" | |
| TARGETMP3="${title}_${hdate}.mp3" | |
| utf8title="`echo "${title}_${hdate}"`" | |
| utf8Atitle="`echo "${title}"`" | |
| cp932title="`echo "${utf8title}"|iconv -f UTF-8 -t CP932`" | |
| cp932Atitle="`echo "${utf8Atitle}"|iconv -f UTF-8 -t CP932`" | |
| if !(test -e "${TARGETMP3}") then | |
| currentdir="`pwd`" | |
| # TMPFILE3="`mktemp "${currentdir}/tmp.XXXXXXXXXX"`" | |
| TMPFILE3="`mktemp "/cygwin/tmp/tmp.XXXXXXXXXX"`" | |
| # TMPFILE4="`mktemp "${currentdir}/tmp.XXXXXXXXXX"`" | |
| TMPFILE4="`mktemp "/cygwin/tmp/tmp.XXXXXXXXXX"`" | |
| TARGETFILE="${TMPFILE3}" | |
| echo "FLV: ${FLVBASEURL}${SCRAMBLECODE}/${file}"; | |
| # ${CMDDIR}/flvstreamer.exe -o "${TARGETFILE}" -r "${FLVBASEURL}${SCRAMBLECODE}/${file}" | |
| ${CMDDIR}/rtmpdump.exe -o "${TARGETFILE}" -r "${FLVBASEURL}${SCRAMBLECODE}/${file}" | |
| test $? -ne 0 && test -e "${TARGETFILE}" && rm "${TARGETFILE}" | |
| test -e "${TARGETFILE}" && ! test -s "${TARGETFILE}" && rm "${TARGETFILE}" | |
| if test -e "${TARGETFILE}"; then | |
| ${CMDDIR}/ffmpeg.exe -y -i "${TARGETFILE}" -acodec copy -f mp3 "${TMPFILE4}" </dev/null | |
| test $? -ne 0 && test -e "${TMPFILE4}" && rm "${TMPFILE4}" | |
| if test -e "${TMPFILE4}"; then | |
| # chmod go+r "${TARGETMP3}" | |
| # Linux向き | |
| #id3v2 -g 101 -A "${utf8Atitle}" -t "${utf8title}" "${TARGETMP3}" | |
| # Windows向き(SJIS(CP932)変換) | |
| # ${CMDDIR}/id3v2.exe -g 101 -A "${cp932Atitle}" -t "${cp932title}" "${TMPFILE4}" | |
| # Android向き(UTF8まま) | |
| ${CMDDIR}/id3v2.exe -g 101 -y "${YEAR}" -a "${ARTIST}" -A "${utf8Atitle}" -t "${utf8title}" "${TMPFILE4}" | |
| fi | |
| test -e "${TMPFILE4}" && mv "${TMPFILE4}" "${TARGETMP3}" | |
| rm "${TMPFILE3}" | |
| else | |
| rm "${TMPFILE4}" | |
| fi | |
| else | |
| echo "${TARGETMP3} already exists" | |
| fi | |
| else | |
| echo "${hdate} is not in range" | |
| fi | |
| done<"${TMPFILE2}" | |
| fi | |
| done<"${TMPFILE6}" | |
| rm "${TMPFILE1}" "${TMPFILE2}" | |
| cd .. | |
| } | |
| get_code() | |
| { | |
| TMPFILE5="`mktemp`" | |
| #curl -o "${TMPFILE5}" ${CODEURL} | |
| ${WGET} -U "${UAG}" -O "${TMPFILE5}" ${CODEURL} | |
| if test $? -eq 0; then | |
| TMPFILE6="`mktemp`" | |
| egrep "scramble [^\=]+\=" ${TMPFILE5}|sort -r>${TMPFILE6} | |
| #grep "scramble date=" ${TMPFILE5}>${TMPFILE6} | |
| fi | |
| rm "${TMPFILE5}" | |
| testline="$(cat ${TMPFILE6})" | |
| if test -z "${testline}"; then | |
| echo "Failed to retrieve scramble code" | |
| rm "${TMPFILE6}" && exit 1 | |
| fi | |
| } | |
| exitproc(){ rm -rf "${TMPFILE1}" "${TMPFILE2}" "${TMPFILE3}" | |
| "${TMPFILE4}" "${TMPFILE5}" "${TMPFILE6}";} | |
| trap ' | |
| exitproc | |
| exit 1 | |
| ' 2 15 | |
| WGET="wget -t 1 -T 15" | |
| UAG="Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0" | |
| # NHK語学講座用 | |
| BASEDIR="${OUTDIR}/NHK語学講座" # 必ず絶対パス | |
| BASEURL="http://www.nhk.or.jp/gogaku/english/" | |
| SCRAMBLECODE= | |
| FLVBASEURL="rtmp://flv9.nhk.or.jp/flv9/_definst_/flv:gogaku/streaming/flv/" | |
| TARGETEXT=flv | |
| mkdir -p "${BASEDIR}" | |
| cd "${BASEDIR}" || exit 1 | |
| # NHK語学講座ダウンロード @ ウィキ - コード参照用xml | |
| CODEURL="http://www47.atwiki.jp/jakago/pub/scramble.xml" | |
| get_code | |
| #downfiles "01_基礎英語1" "basic1" "listdataflv.xml" | |
| #downfiles "02_基礎英語2" "basic2" "listdataflv.xml" | |
| #downfiles "03_基礎英語3" "basic3" "listdataflv.xml" | |
| #downfiles "04_英語5分間トレーニング" "training" "listdataflv.xml" | |
| #downfiles "05_ラジオ英会話" "kaiwa" "listdataflv.xml" | |
| downfiles "06_入門ビジネス英語" "business1" "listdataflv.xml" | |
| #downfiles "07_実践ビジネス英語" "business2" "listdataflv.xml" | |
| rm ${TMPFILE6} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment