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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
package main
import (
"reflect"
"testing"
)
func TestSlug(t *testing.T) {
cases := map[string]string{
"...von oben": "von-oben",
"Tagesschau": "tagesschau",
"Maischberger": "maischberger",
"Löwenzahn": "loewenzahn",
"Straße & Brücken": "strasse-bruecken",
"Le Dessous des Cartes – Éco": "le-dessous-des-cartes-eco",
"ZDFheute Xpress": "zdfheute-xpress",
"!!!": "",
"Kraków": "krakow",
}
for in, want := range cases {
if got := slug(in); got != want {
t.Errorf("slug(%q) = %q, want %q", in, got, want)
}
}
}
func TestFamilies(t *testing.T) {
for s, want := range map[string]string{
"WDR": "ard", "tagesschau24": "ard", "ZDF-tivi": "zdf",
"SRF": "srf", "ARTE.DE": "arte-de", "3Sat": "3sat", "Funk.net": "funk-net",
"Radio Bremen TV": "ard",
} {
if got := familyOf(s); got != want {
t.Errorf("familyOf(%q) = %q, want %q", s, got, want)
}
}
// tagesschau at SRF and at ARD must not merge.
if channelName(familyOf("SRF"), "Tagesschau") == channelName(familyOf("ARD"), "Tagesschau") {
t.Error("SRF and ARD tagesschau merged")
}
}
// The uuid must not depend on anything we derive, only on raw list fields.
func TestUUIDStable(t *testing.T) {
u := videoUUID("ARD", "Tatort", "http://x/y.mp4")
if u != videoUUID("ARD", "Tatort", "http://x/y.mp4") {
t.Fatal("not deterministic")
}
if u == videoUUID("WDR", "Tatort", "http://x/y.mp4") || u == videoUUID("ARD", "tatort", "http://x/y.mp4") {
t.Error("collides")
}
if len(u) != 36 || u[14] != '5' {
t.Errorf("not a v5-shaped uuid: %s", u)
}
// Pinned: changing this breaks every link out there.
if want := "979def53-f521-524c-b0ba-8773b1a9bc27"; u != want {
t.Errorf("uuid is %s, want %s: changing this breaks every link out there", u, want)
}
}
func TestPlayURL(t *testing.T) {
cases := map[string]string{
"http://tvdlzdf-a.akamaihd.net/a.mp4": "https://tvdlzdf-a.akamaihd.net/a.mp4",
"http://nrodl.zdf.de/a.mp4": "https://nrodlzdf-a.akamaihd.net/a.mp4",
"http://dl-ondemand.radiobremen.de/a.mp4": "https://rbprogressivedl-a.akamaihd.net/a.mp4",
"http://hbbtv-ondemand.swr.de/a.mp4": "http://hbbtv-ondemand.swr.de/a.mp4",
"https://already.example/a.mp4": "https://already.example/a.mp4",
}
for in, want := range cases {
if got := playURL(in); got != want {
t.Errorf("playURL(%q) = %q, want %q", in, got, want)
}
}
}
func TestSubtitleURL(t *testing.T) {
cases := map[string]string{
"": "",
"http://www.ardmediathek.dehttps://api.ardmediathek.de/player-service/subtitle/ebutt/urn:x": "https://api.ardmediathek.de/player-service/subtitle/ebutt/urn:x",
"//utstreaming.zdf.de/a.xml": "https://utstreaming.zdf.de/a.xml",
"subtitles.swr.de/a.xml": "https://subtitles.swr.de/a.xml",
"/static/a.xml": "",
"https://www.ardmediathek.de/subtitle/1": "",
"https://www.ndr.de/x/ut123.html": "",
}
for in, want := range cases {
if got := subtitleURL(in); got != want {
t.Errorf("subtitleURL(%q) = %q, want %q", in, got, want)
}
}
}
func TestTitleTags(t *testing.T) {
cases := map[string][]string{
"Tatort: Foo (Audiodeskription)": {"Audiodeskription"},
"Foo (mit Gebärdensprache)": {"Gebärdensprache"},
"Foo (mit Gerbärdensprache)": {"Gebärdensprache"},
"Foo (Originalversion)": {"Originalversion"},
"Foo (OV)": {"Originalversion"},
"Foo (klare Sprache)": {"Klare Sprache"},
"Foo (S06/E05, mit Audiodeskription)": {"Audiodeskription"},
"Foo (Hörfassung)": {"Audiodeskription"},
"Foo (S01/E02)": nil,
"Foo (Audiodeskription) - Teil 2": nil,
}
for in, want := range cases {
if got := titleTags(in); !reflect.DeepEqual(got, want) {
t.Errorf("titleTags(%q) = %v, want %v", in, got, want)
}
}
}
func TestNormalize(t *testing.T) {
zdf := Entry{
Sender: "3Sat", Topic: "...von oben", Title: "Portugal",
URLSmall: "http://rodl.zdf.de/a/x_808k_p11v17.mp4",
URL: "https://nrodlzdf-a.akamaihd.net/a/x_3360k_p36v17.mp4",
URLHD: "https://nrodlzdf-a.akamaihd.net/a/x_6660k_p37v17.mp4",
}
v, why := Normalize(zdf)
if why != DropNone || v.Kind != KindMP4 || len(v.Files) != 3 {
t.Fatalf("zdf: %v %+v", why, v)
}
if v.Files[0].Height != 360 || v.Files[0].URL != "https://rodlzdf-a.akamaihd.net/a/x_808k_p11v17.mp4" || v.Files[2].Height != 1080 {
t.Errorf("zdf files: %+v", v.Files)
}
if v.Channel != "3sat-von-oben" {
t.Errorf("channel %q", v.Channel)
}
// Same label twice → keep the later slot. Unknown → slot fallback.
v, _ = Normalize(Entry{Sender: "X", Topic: "t", URLSmall: "https://a.example/a.mp4", URL: "https://a.example/b_1280x720.mp4", URLHD: "https://a.example/c.mp4"})
if len(v.Files) != 2 || v.Files[0].Height != 360 || !v.Files[0].Fallback || v.Files[1].Height != 720 || v.Files[1].URL != "https://a.example/c.mp4" {
t.Errorf("fallback/collapse: %+v", v.Files)
}
// Mixed MP4 + m3u8 → MP4 only.
v, _ = Normalize(Entry{Sender: "ARD", Topic: "t", URL: "https://odplanetschule-a.akamaihd.net/a_1280x720.mp4", URLHD: "https://swrplanetschulevod.akamaized.net/i/a,,.mp4/master.m3u8"})
if v.Kind != KindMP4 || len(v.Files) != 1 {
t.Errorf("mixed: %+v", v)
}
// SRF HLS variants.
base := "https://srf-vod-amd.akamaized.net/world/hls/x/y_,q40,q10,q20,q30,q50,q60,.mp4.csmil/"
v, _ = Normalize(Entry{Sender: "SRF", Topic: "t", URLSmall: base + "index-f4-v1-a1.m3u8", URL: base + "index-f1-v1-a1.m3u8", URLHD: base + "index-f6-v1-a1.m3u8"})
if v.Kind != KindHLS || len(v.Files) != 3 || v.Files[0].Height != 360 || v.Files[2].Height != 1080 {
t.Errorf("srf: %+v", v)
}
// ORF master.
v, _ = Normalize(Entry{Sender: "ORF", Topic: "t", URL: "https://apasfiis.sf.apa.at/ipad/x_Q6A.mp4/playlist.m3u8"})
if v.Kind != KindMaster || len(v.Files) != 1 {
t.Errorf("orf master: %+v", v)
}
// Drops.
for _, e := range []Entry{
{Sender: "ARD", Topic: "Livestream", URL: "https://x/master.m3u8"},
{Sender: "ARD", Topic: "Sportschau", URL: "https://sportschau-event.ard-mcdn.de/sportschau/event13/hls/de/master720p3200.m3u8"},
{Sender: "ARD", Topic: "x", URL: "https://wdrevent.akamaized.net/hls/live/2016700/x/master_1928.m3u8"},
{Sender: "ARD", Topic: "x", Title: "Wir haben genug - Wirtschaft ohne Wachstum", URL: "https://x/a.mp4"},
{Sender: "BR", Topic: "x", URL: "https://cdn-storage.br.denull"},
{Sender: "DW", Topic: "x", URL: "https://x/a.flv"},
} {
if _, why := Normalize(e); why == DropNone {
t.Errorf("not dropped: %+v", e)
}
}
// DW: .flv in the Klein slot is dropped, the rest kept.
v, _ = Normalize(Entry{Sender: "DW", Topic: "x", URLSmall: "https://x.de/a.flv", URL: "https://x.de/a_AVC_640x360.mp4"})
if v.Kind != KindMP4 || len(v.Files) != 1 {
t.Errorf("dw: %+v", v)
}
// mp3
v, _ = Normalize(Entry{Sender: "ARD", Topic: "x", URL: "https://x.de/a.mp3"})
if v.Kind != KindMP3 {
t.Errorf("mp3: %+v", v)
}
}
|