Commit 4a6f620a10

4a6f620a10fef8653f7ac7e3ae6880bc86b473fc

parent: 6298516567

Unsigned

Wraient <wraient.911@gmail.com> · 2026-09-25 10:16 UTC

fix(anipub): decrypt megaplay AES-CBC enc field for stream URLs

Megaplay moved the HLS URL out of getSources.sources into an AES-CBC
encrypted enc field. Decrypt it with the key/IV from their player bundle
(lib/newclient.min.js), falling back only when sources.file is present.

Also deprecate broken providers so the default stack is senshi + anipub:
anineko.to is down (origin unreachable), allanime episode sources need
rotating signed anti-bot tokens (AA_CRYPTO_MISSING), animepahe is
Cloudflare-walled. All three stay selectable via Provider config.

Layout: unified · split

README.md +1 −1
@@ -399,7 +399,7 @@ If the browser reaches the localhost callback page but curd does not continue au
399399| `SaveMpvSpeed` | Boolean | `true`, `false` | Retains the playback speed set in MPV for next episode. |
400400| `SkipFiller` | Boolean | `true`, `false` | Skips filler episodes when supported. |
401401| `MenuOrder` | String | Comma-separated list | Controls which menu items appear and their order. Available options: `CURRENT`, `ALL`, `UNTRACKED`, `UPDATE`, `REMAP_PROVIDER`, `CONTINUE_LAST`, `PLANNING`, `COMPLETED`, `PAUSED`, `DROPPED`, `REWATCHING`, `TRACKER`, `PROVIDER`. Only listed items will be shown. Default: `CURRENT,ALL,UNTRACKED,UPDATE,REMAP_PROVIDER,CONTINUE_LAST,TRACKER,PROVIDER` |
402| `Provider` | List | `stacked`, `["anipub"]`, `["anineko"]`, `["allanime"]`, `["animepahe"]` | Sets the content-provider fallback list. `stacked` (default) uses the preferred order: senshi → anipub → anineko → allanime → animepahe. A single-provider list uses only that site. AllAnime and Animepahe are disabled by default unless included in `Provider`. Default: `stacked` |
402| `Provider` | List | `stacked`, `["anipub"]`, `["anineko"]`, `["allanime"]`, `["animepahe"]` | Sets the content-provider fallback list. `stacked` (default) uses the preferred order: senshi → anipub. anineko, allanime and animepahe are disabled by default (site down / anti-bot / Cloudflare) unless included in `Provider`. Default: `stacked` |
403403| `ManualProviderSearch` | Boolean | `true`, `false` | Skip automatic provider matching and always show provider search results for manual selection. Displays a hint with the tracker title, format (TV/Movie/etc.), episode count, and sub/dub mode. Default: `false` |
404404| `TrackingLocal` | Boolean | `true` | Legacy compatibility flag. Local playback history is always enabled. |
405405| `TrackingRemote` | Enum | `none`, `anilist`, `myanimelist`, `anilist+myanimelist` | Selects which remote tracker curd syncs with. |
internal/providers/allanime/register.go +1 −1
@@ -8,7 +8,7 @@ func init() {
88 Aliases: []string{"all-anime", "all anime"},
99 Referrer: "https://allanime.day/",
1010 DefaultDisabled: true,
11 DisableReason: "disabled by default; set Provider to include allanime to enable",
11 DisableReason: "episode sources require rotating signed anti-bot tokens (AA_CRYPTO_MISSING); set Provider to include allanime to try anyway",
1212 }, func() providers.Provider {
1313 return &Provider{}
1414 })
internal/providers/anineko/register.go +5 −3
@@ -4,9 +4,11 @@ import "github.com/wraient/curd/internal/providers"
44
55func init() {
66 providers.Register(providers.Meta{
7 Name: "anineko",
8 Aliases: []string{"ani-neko", "ani neko"},
9 Referrer: "https://anineko.to/",
7 Name: "anineko",
8 Aliases: []string{"ani-neko", "ani neko"},
9 Referrer: "https://anineko.to/",
10 DefaultDisabled: true,
11 DisableReason: "anineko.to is down (origin unreachable)",
1012 }, func() providers.Provider {
1113 return &Provider{}
1214 })
internal/providers/anipub/megaplay.go +61
@@ -1,6 +1,10 @@
11package anipub
22
33import (
4 "crypto/aes"
5 "crypto/cipher"
6 "encoding/base64"
7 "encoding/json"
48 "fmt"
59 "net/url"
610 "regexp"
@@ -50,6 +54,15 @@ func resolveMegaplayStream(videoLink, mode string) (string, string, error) {
5054 }
5155
5256 streamURL := strings.TrimSpace(payload.Sources.File)
57 if streamURL == "" && strings.TrimSpace(payload.Enc) != "" {
58 // Megaplay moved the stream URL into an AES-CBC encrypted "enc"
59 // field. Decrypt it the same way their web player does.
60 decrypted, err := decryptMegaplayEnc(payload.Enc)
61 if err != nil {
62 return "", "", fmt.Errorf("decrypt megaplay stream: %w", err)
63 }
64 streamURL = decrypted
65 }
5366 if streamURL == "" {
5467 return "", "", fmt.Errorf("megaplay stream url missing")
5568 }
@@ -57,6 +70,54 @@ func resolveMegaplayStream(videoLink, mode string) (string, string, error) {
5770 return streamURL, subtitle, nil
5871}
5972
73// megaplayEncKey and megaplayEncIV mirror the AES-CBC parameters in
74// megaplay.buzz's web player (lib/newclient.min.js). If they rotate the
75// bundle, this breaks and the values need re-extracting from the new JS.
76var (
77 megaplayEncKey = []byte("i?LMTAx0Q6,:}50U")
78 megaplayEncIV = []byte("W0;27ToaUpl_P%'c")
79)
80
81// decryptMegaplayEnc decrypts the "enc" field of a megaplay getSources
82// response and returns the stream file URL inside.
83func decryptMegaplayEnc(enc string) (string, error) {
84 s := strings.ReplaceAll(strings.ReplaceAll(strings.TrimSpace(enc), "-", "+"), "_", "/")
85 if m := len(s) % 4; m != 0 {
86 s += strings.Repeat("=", 4-m)
87 }
88 ciphertext, err := base64.StdEncoding.DecodeString(s)
89 if err != nil {
90 return "", fmt.Errorf("decode megaplay payload: %w", err)
91 }
92 if len(ciphertext) == 0 || len(ciphertext)%aes.BlockSize != 0 {
93 return "", fmt.Errorf("invalid megaplay payload length %d", len(ciphertext))
94 }
95 key := make([]byte, 32)
96 copy(key, megaplayEncKey)
97 block, err := aes.NewCipher(key)
98 if err != nil {
99 return "", err
100 }
101 plain := make([]byte, len(ciphertext))
102 cipher.NewCBCDecrypter(block, megaplayEncIV).CryptBlocks(plain, ciphertext)
103 pad := int(plain[len(plain)-1])
104 if pad <= 0 || pad > aes.BlockSize || pad > len(plain) {
105 return "", fmt.Errorf("invalid megaplay padding")
106 }
107 plain = plain[:len(plain)-pad]
108
109 var payload struct {
110 File string `json:"file"`
111 }
112 if err := json.Unmarshal(plain, &payload); err != nil {
113 return "", fmt.Errorf("parse decrypted megaplay payload: %w", err)
114 }
115 if strings.TrimSpace(payload.File) == "" {
116 return "", fmt.Errorf("decrypted megaplay payload has no file")
117 }
118 return strings.TrimSpace(payload.File), nil
119}
120
60121func parseVideoLink(videoLink string) (embedID, mode string, err error) {
61122 parsed, err := url.Parse(videoLink)
62123 if err != nil {
internal/providers/anipub/megaplay_decrypt_test.go added +64
@@ -0,0 +1,64 @@
1package anipub
2
3import (
4 "encoding/json"
5 "net/http"
6 "net/http/httptest"
7 "strings"
8 "testing"
9)
10
11const testMegaplayEnc = "wdeBruh3qqn_i5wUNnyaPcXqidp1UWP84FfPHzGyKXAz4mAVkH6j3DueswO2yXLWn8H-XMHNvbAo5Gsg7zIcFBuQI_zsUvMGI1gKwQsPTSHQHiF55R4BopgEQ-7jebQQ4C0Gu7YhaMucopp6d3Q8yAY9b5GdsSvPGq6CUn7SHyc"
12
13func TestDecryptMegaplayEnc(t *testing.T) {
14 got, err := decryptMegaplayEnc(testMegaplayEnc)
15 if err != nil {
16 t.Fatalf("decryptMegaplayEnc: %v", err)
17 }
18 want := "https://fetch.nexabloom.top/anime/bb6d2babd7797d94d8f4a8600bc9b44e/b7d51fb7e838ee9b60dcdb34b953bc07/master.m3u8"
19 if got != want {
20 t.Fatalf("got %q, want %q", got, want)
21 }
22}
23
24func TestDecryptMegaplayEncRejectsGarbage(t *testing.T) {
25 for _, enc := range []string{"", "!!!", "aGVsbG8="} {
26 if _, err := decryptMegaplayEnc(enc); err == nil {
27 t.Fatalf("expected error for %q", enc)
28 }
29 }
30}
31
32func TestResolveMegaplayStreamFallsBackToEnc(t *testing.T) {
33 megaplay := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
34 switch r.URL.Path {
35 case "/stream/s-2/42/sub":
36 w.Header().Set("Content-Type", "text/html")
37 _, _ = w.Write([]byte(`<div data-id="99"></div>`))
38 case "/stream/getSources":
39 _ = json.NewEncoder(w).Encode(megaplaySourcesResponse{Enc: testMegaplayEnc})
40 default:
41 http.NotFound(w, r)
42 }
43 }))
44 defer megaplay.Close()
45
46 client := &http.Client{Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
47 if strings.HasPrefix(req.URL.String(), megaplay.URL) {
48 return http.DefaultTransport.RoundTrip(req)
49 }
50 return textResponse(req, http.StatusNotFound, ""), nil
51 })}
52 withAnipubTestClient(t, client)
53 originalMega := megaplayBaseURL
54 t.Cleanup(func() { megaplayBaseURL = originalMega })
55 megaplayBaseURL = megaplay.URL
56
57 streamURL, _, err := resolveMegaplayStream("https://anipub.xyz/video/42/sub", "sub")
58 if err != nil {
59 t.Fatalf("resolveMegaplayStream: %v", err)
60 }
61 if !strings.HasSuffix(streamURL, "/master.m3u8") {
62 t.Fatalf("unexpected stream %q", streamURL)
63 }
64}
internal/providers/anipub/types.go +1
@@ -42,6 +42,7 @@ type megaplaySourcesResponse struct {
4242 Sources struct {
4343 File string `json:"file"`
4444 } `json:"sources"`
45 Enc string `json:"enc"`
4546 Tracks []struct {
4647 File string `json:"file"`
4748 Label string `json:"label"`
internal/stackcheck_test.go added +22
@@ -0,0 +1,22 @@
1package internal
2
3import (
4 "reflect"
5 "testing"
6)
7
8func TestDefaultStackIsSenshiAnipub(t *testing.T) {
9 got := defaultEnabledProviderStack()
10 want := []string{"senshi", "anipub"}
11 if !reflect.DeepEqual(got, want) {
12 t.Fatalf("default stack = %v, want %v", got, want)
13 }
14 for _, name := range []string{"anineko", "allanime", "animepahe"} {
15 if ProviderEnabled(name) {
16 t.Fatalf("%s should be disabled by default", name)
17 }
18 if ProviderDisabledReason(name) == "" {
19 t.Fatalf("%s should have a disable reason", name)
20 }
21 }
22}