internal/providers/allanime/streams_test.go
72 lines · 2029 bytes
1package allanime
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestExpandWixmpLinksMatchesAniCLI(t *testing.T) {
9 t.Parallel()
10
11 input := "https://repackager.wixmp.com/video.wixstatic.com/video/4fa677_7daec0ccb9364ac7b032d43692c73617/,720p,480p,1080p,/mp4/file.mp4.urlset/master.m3u8"
12 links := expandWixmpLinks(input)
13 if len(links) != 3 {
14 t.Fatalf("expected 3 expanded links, got %d: %#v", len(links), links)
15 }
16 if !strings.HasPrefix(links[0], "https://video.wixstatic.com/video/4fa677_7daec0ccb9364ac7b032d43692c73617/1080p/mp4/file.mp4") {
17 t.Fatalf("expected 1080p wixstatic link first, got %q", links[0])
18 }
19}
20
21func TestGetLinksFromEncodedSourceUrlsSkipsUnreliableFast4speed(t *testing.T) {
22 t.Parallel()
23
24 sourceUrls := []allanimeSource{
25 {
26 SourceUrl: "https://tools.fast4speed.rsvp/media9/videos/example/dub/1?Authorization=test",
27 SourceName: "Yt-mp4",
28 Priority: 7.9,
29 },
30 }
31
32 _, _, err := getLinksFromEncodedSourceUrls(sourceUrls)
33 if err == nil {
34 t.Fatal("expected error when only direct fast4speed source is available")
35 }
36}
37
38func TestGetLinksFromEncodedSourceUrlsRequiresEncodedProviders(t *testing.T) {
39 t.Parallel()
40
41 sourceUrls := []allanimeSource{
42 {
43 SourceUrl: "https://tenant.sharepoint.com/video.mp4",
44 SourceName: "S-mp4",
45 Priority: 7.4,
46 },
47 }
48
49 _, _, err := getLinksFromEncodedSourceUrls(sourceUrls)
50 if err == nil {
51 t.Fatal("expected error when no encoded provider sources exist")
52 }
53}
54
55func TestParseAllanimeStreamInfScore(t *testing.T) {
56 t.Parallel()
57
58 line := `#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720,CODECS="avc1.64001f,mp4a.40.2"`
59 if got := parseAllanimeStreamInfScore(line); got != 1280 {
60 t.Fatalf("parseAllanimeStreamInfScore() = %d, want 1280", got)
61 }
62}
63
64func TestResolveAllanimeRelativeURL(t *testing.T) {
65 t.Parallel()
66
67 got := resolveAllanimeRelativeURL("https://example.com/path/", "720p/index.m3u8")
68 want := "https://example.com/path/720p/index.m3u8"
69 if got != want {
70 t.Fatalf("resolveAllanimeRelativeURL() = %q, want %q", got, want)
71 }
72}