2014年2月28日 星期五

下載香港電台節目重溫方法

Update: 2015-5-17 更新並整理內容
===========================

方法1:使用 internet download manager 下載
方法2:使用 ffmpeg 下載
方法3:使用 LiveStreamer 下載
方法4:使用 Download manager 下節目的 playlists 中的多個 ts 檔案
方法5:自行寫 program 解釋 HLS (HTTP Live Streaming),並下載檔案 (待寫)
方法6:編寫script並使用 ffmpeg、LiveStreamer下載


方法1:使用 internet download manager
========================================== 
internet download manager 能下載所有playlist中所有 ts 檔案並自動合併成單一檔案



refs: http://forum4.hkgolden.com/view.aspx?type=SW&message=5226138


方法2:使用 ffmpeg 下載
=====================

第一步下載 ffmpeg
http://www.ffmpeg.org/download.html

以下以 windows 為例子,Mac /Linux 下載方法細節自行推敲吧。


第二步到要重溫節目聲音檔案網頁,打開重溫節目的 Rthk player 網頁

第三步檢視原始碼
找出要下載的 playlist 網址

講東講西為例子,打開獨立 Rthk player 網頁

下載完整全部份網址
 
下載第一部份網址
 
下載第二部份網址

「命令提示字元」 MS-DOS Command Prompt 下輸入

ffmpeg -i "http://stmw.rthk.hk/aod/_definst_/radio/archive/radio1/happydaily/mp3/mp3:20140128.mp3/playlist.m3u8?wowzaplaystart=0&wowzaplayduration=2398000" -acodec mp3 OutputTest12345.mp3


等待數分鐘後便完成下載 (轉錄 stream),檔名為 OutputTest12345.mp3 (自訂的檔案名)


方法3:使用 LiveStreamer 下載
=========================
livestreamer 介紹
http://www.videohelp.com/tools/livestreamer

用法例子 
http://stream-recorder.com/forum/download-audio-streamed-jwplayer-t19521.html

以 windows 版的 LiveStremer 為例,下載以下節目

講東講西 - 任性

先下載 LiveStreamer ,解壓

「命令提示字元」 MS-DOS Command Prompt 下輸入

Step 1
============================================================
livestreamer "hlsvariant://stmw3.rthk.hk/aod/_definst_/radio/archive/radio1/Free_as_the_wind/mp3/mp3:20150327.mp3/playlist.m3u8"  best -o 20150327.ts

Step 2
============================================================
再使用ffmpeg轉換 ts file為 mp3 file,去除一些不必要的 header data

ffmpeg -i "20150327.ts" -c:a copy "20150327.mp3"




方法4:使用 Download manager 下節目的 playlists 中的多個 ts 檔案
=====================================================
待寫,暫時參考
http://blog.sina.com.cn/s/blog_571e0fe40101hrvo.html


方法5:自行寫 program 解釋 HLS (HTTP Live Streaming),並下載檔案 (待寫)
 ============================================================
- 什麼是 HTTP Live Streaming
- 什麼是 M3U、M3U8 file
- M3U8 格式
- note 一些細節
港台使用串流server軟件為 Wowza Media Server 3 Perpetual Edition 3.6.4 build9641
串流時 load balance到幾個不同server,下載串流網址其實互通的,一個 down 機時,可改用另一個server

http://stmw.rthk.hk
http://stmw1.rthk.hk
http://stmw2.rthk.hk
http://stmw3.rthk.hk

現成解釋 HLS 工具或script,e.g.
gohls - HTTP Live Streaming (HLS) downloader written in Golang
https://github.com/kz26/gohls 

 hlsclient
Client to download all files from HLS streams
This is a simple Python HTTP Live Streaming Client. It consumes a list of remote playlists, and saves all needed files to serve the playlist locally: the key, segments, and a modified m3u8 with paths normalized.