Commit 4a6f620a10
Unsigned
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 | |||
| 399 | | `SaveMpvSpeed` | Boolean | `true`, `false` | Retains the playback speed set in MPV for next episode. | | 399 | | `SaveMpvSpeed` | Boolean | `true`, `false` | Retains the playback speed set in MPV for next episode. | |
| 400 | | `SkipFiller` | Boolean | `true`, `false` | Skips filler episodes when supported. | | 400 | | `SkipFiller` | Boolean | `true`, `false` | Skips filler episodes when supported. | |
| 401 | | `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` | | 401 | | `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` | |
| 403 | | `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` | | 403 | | `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` | |
| 404 | | `TrackingLocal` | Boolean | `true` | Legacy compatibility flag. Local playback history is always enabled. | | 404 | | `TrackingLocal` | Boolean | `true` | Legacy compatibility flag. Local playback history is always enabled. | |
| 405 | | `TrackingRemote` | Enum | `none`, `anilist`, `myanimelist`, `anilist+myanimelist` | Selects which remote tracker curd syncs with. | | 405 | | `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() { | |||
| 8 | Aliases: []string{"all-anime", "all anime"}, | 8 | Aliases: []string{"all-anime", "all anime"}, |
| 9 | Referrer: "https://allanime.day/", | 9 | Referrer: "https://allanime.day/", |
| 10 | DefaultDisabled: true, | 10 | 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", |
| 12 | }, func() providers.Provider { | 12 | }, func() providers.Provider { |
| 13 | return &Provider{} | 13 | return &Provider{} |
| 14 | }) | 14 | }) |
internal/providers/anineko/register.go +5 −3
| @@ -4,9 +4,11 @@ import "github.com/wraient/curd/internal/providers" | |||
| 4 | 4 | ||
| 5 | func init() { | 5 | func init() { |
| 6 | providers.Register(providers.Meta{ | 6 | providers.Register(providers.Meta{ |
| 7 | Name: "anineko", | 7 | Name: "anineko", |
| 8 | Aliases: []string{"ani-neko", "ani neko"}, | 8 | Aliases: []string{"ani-neko", "ani neko"}, |
| 9 | Referrer: "https://anineko.to/", | 9 | Referrer: "https://anineko.to/", |
| 10 | DefaultDisabled: true, | ||
| 11 | DisableReason: "anineko.to is down (origin unreachable)", | ||
| 10 | }, func() providers.Provider { | 12 | }, func() providers.Provider { |
| 11 | return &Provider{} | 13 | return &Provider{} |
| 12 | }) | 14 | }) |
internal/providers/anipub/megaplay.go +61
| @@ -1,6 +1,10 @@ | |||
| 1 | package anipub | 1 | package anipub |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "crypto/aes" | ||
| 5 | "crypto/cipher" | ||
| 6 | "encoding/base64" | ||
| 7 | "encoding/json" | ||
| 4 | "fmt" | 8 | "fmt" |
| 5 | "net/url" | 9 | "net/url" |
| 6 | "regexp" | 10 | "regexp" |
| @@ -50,6 +54,15 @@ func resolveMegaplayStream(videoLink, mode string) (string, string, error) { | |||
| 50 | } | 54 | } |
| 51 | 55 | ||
| 52 | streamURL := strings.TrimSpace(payload.Sources.File) | 56 | 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 | } | ||
| 53 | if streamURL == "" { | 66 | if streamURL == "" { |
| 54 | return "", "", fmt.Errorf("megaplay stream url missing") | 67 | return "", "", fmt.Errorf("megaplay stream url missing") |
| 55 | } | 68 | } |
| @@ -57,6 +70,54 @@ func resolveMegaplayStream(videoLink, mode string) (string, string, error) { | |||
| 57 | return streamURL, subtitle, nil | 70 | return streamURL, subtitle, nil |
| 58 | } | 71 | } |
| 59 | 72 | ||
| 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. | ||
| 76 | var ( | ||
| 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. | ||
| 83 | func 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 | |||
| 60 | func parseVideoLink(videoLink string) (embedID, mode string, err error) { | 121 | func parseVideoLink(videoLink string) (embedID, mode string, err error) { |
| 61 | parsed, err := url.Parse(videoLink) | 122 | parsed, err := url.Parse(videoLink) |
| 62 | if err != nil { | 123 | if err != nil { |
internal/providers/anipub/megaplay_decrypt_test.go added +64
| @@ -0,0 +1,64 @@ | |||
| 1 | package anipub | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "encoding/json" | ||
| 5 | "net/http" | ||
| 6 | "net/http/httptest" | ||
| 7 | "strings" | ||
| 8 | "testing" | ||
| 9 | ) | ||
| 10 | |||
| 11 | const testMegaplayEnc = "wdeBruh3qqn_i5wUNnyaPcXqidp1UWP84FfPHzGyKXAz4mAVkH6j3DueswO2yXLWn8H-XMHNvbAo5Gsg7zIcFBuQI_zsUvMGI1gKwQsPTSHQHiF55R4BopgEQ-7jebQQ4C0Gu7YhaMucopp6d3Q8yAY9b5GdsSvPGq6CUn7SHyc" | ||
| 12 | |||
| 13 | func 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 | |||
| 24 | func 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 | |||
| 32 | func 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 { | |||
| 42 | Sources struct { | 42 | Sources struct { |
| 43 | File string `json:"file"` | 43 | File string `json:"file"` |
| 44 | } `json:"sources"` | 44 | } `json:"sources"` |
| 45 | Enc string `json:"enc"` | ||
| 45 | Tracks []struct { | 46 | Tracks []struct { |
| 46 | File string `json:"file"` | 47 | File string `json:"file"` |
| 47 | Label string `json:"label"` | 48 | Label string `json:"label"` |
internal/stackcheck_test.go added +22
| @@ -0,0 +1,22 @@ | |||
| 1 | package internal | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "reflect" | ||
| 5 | "testing" | ||
| 6 | ) | ||
| 7 | |||
| 8 | func 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 | } | ||