worker を追加(yt-dlp によるダウンロード、段階別進捗、ffprobe 検査、実行中の取り消し)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package worker
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseProgress(t *testing.T) {
|
||||
video, ok := parseProgress(`{"event":"download","format_id":"hls-698-1","progress":{"downloaded_bytes":25,"total_bytes_estimate":100.0,"speed":10.5,"eta":3,"fragment_index":1,"fragment_count":4}}`)
|
||||
if !ok || video.Phase != "video" || video.DownloadedBytes == nil || *video.DownloadedBytes != 25 || video.TotalBytes == nil || *video.TotalBytes != 100 || !video.TotalIsEstimate || video.SpeedBPS == nil || *video.SpeedBPS != 10.5 || video.ETASeconds == nil || *video.ETASeconds != 3 || video.FragmentIndex == nil || *video.FragmentIndex != 1 || video.FragmentCount == nil || *video.FragmentCount != 4 || video.FormatID == nil || *video.FormatID != "hls-698-1" {
|
||||
t.Fatalf("映像進捗: %+v ok=%v", video, ok)
|
||||
}
|
||||
audio, ok := parseProgress(`{"event":"download","format_id":"hls-ts_AUDIO-0_2","progress":{"downloaded_bytes":50,"total_bytes":50}}`)
|
||||
if !ok || audio.Phase != "audio" || audio.TotalIsEstimate || audio.TotalBytes == nil || *audio.TotalBytes != 50 {
|
||||
t.Fatalf("音声進捗: %+v ok=%v", audio, ok)
|
||||
}
|
||||
merging, ok := parseProgress(`{"event":"postprocess","progress":{"status":"started","postprocessor":"Merger"}}`)
|
||||
if !ok || merging.Phase != "merging" {
|
||||
t.Fatalf("結合進捗: %+v ok=%v", merging, ok)
|
||||
}
|
||||
path, ok := parseAfterMove(`{"event":"after_move","filepath":"/videos/incoming/ep.mp4"}`)
|
||||
if !ok || path != "/videos/incoming/ep.mp4" {
|
||||
t.Fatalf("移動後パス: %q ok=%v", path, ok)
|
||||
}
|
||||
for _, invalid := range []string{"noise", `{"event":"other"}`} {
|
||||
if _, ok := parseProgress(invalid); ok {
|
||||
t.Errorf("不正な進捗を許した: %q", invalid)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user