refactor: remove unused parameters and redundant errors
This commit is contained in:
@@ -464,8 +464,8 @@ func decryptTobeparsed(encoded string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if version == 1 {
|
if version == 1 {
|
||||||
plainText, err := tryDecryptCTR(block, iv, cipherText)
|
plainText := tryDecryptCTR(block, iv, cipherText)
|
||||||
if err == nil && json.Valid(plainText) {
|
if json.Valid(plainText) {
|
||||||
return plainText, nil
|
return plainText, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -484,13 +484,13 @@ func decryptTobeparsed(encoded string) ([]byte, error) {
|
|||||||
return nil, fmt.Errorf("decryption failed")
|
return nil, fmt.Errorf("decryption failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryDecryptCTR(block cipher.Block, iv []byte, cipherText []byte) ([]byte, error) {
|
func tryDecryptCTR(block cipher.Block, iv []byte, cipherText []byte) []byte {
|
||||||
ctrIV := append([]byte{}, iv...)
|
ctrIV := append([]byte{}, iv...)
|
||||||
ctrIV = append(ctrIV, 0x00, 0x00, 0x00, 0x02)
|
ctrIV = append(ctrIV, 0x00, 0x00, 0x00, 0x02)
|
||||||
ctr := cipher.NewCTR(block, ctrIV)
|
ctr := cipher.NewCTR(block, ctrIV)
|
||||||
plainText := make([]byte, len(cipherText))
|
plainText := make([]byte, len(cipherText))
|
||||||
ctr.XORKeyStream(plainText, cipherText)
|
ctr.XORKeyStream(plainText, cipherText)
|
||||||
return plainText, nil
|
return plainText
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search queries AllAnime for shows matching the given search term.
|
// Search queries AllAnime for shows matching the given search term.
|
||||||
|
|||||||
@@ -430,11 +430,7 @@ func TestTryDecryptCTR(t *testing.T) {
|
|||||||
iv := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b}
|
iv := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b}
|
||||||
cipherText := []byte("test plaintext ")
|
cipherText := []byte("test plaintext ")
|
||||||
|
|
||||||
plainText, err := tryDecryptCTR(block, iv, cipherText)
|
plainText := tryDecryptCTR(block, iv, cipherText)
|
||||||
if err != nil {
|
|
||||||
t.Errorf("tryDecryptCTR error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = plainText
|
_ = plainText
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,11 +58,11 @@ func (e *providerExtractor) ExtractVideoLinks(ctx context.Context, providerPath
|
|||||||
return nil, fmt.Errorf("read provider response: %w", err)
|
return nil, fmt.Errorf("read provider response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return e.parseProviderResponse(ctx, string(body))
|
return e.parseProviderResponse(ctx, string(body)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseProviderResponse extracts stream sources from provider JSON response.
|
// parseProviderResponse extracts stream sources from provider JSON response.
|
||||||
func (e *providerExtractor) parseProviderResponse(ctx context.Context, response string) ([]StreamSource, error) {
|
func (e *providerExtractor) parseProviderResponse(ctx context.Context, response string) []StreamSource {
|
||||||
sources := make([]StreamSource, 0)
|
sources := make([]StreamSource, 0)
|
||||||
providerReferer := e.referer
|
providerReferer := e.referer
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ func (e *providerExtractor) parseProviderResponse(ctx context.Context, response
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sources, nil
|
return sources
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseM3U8 fetches a master playlist and extracts individual stream URLs with bandwidth-derived quality.
|
// parseM3U8 fetches a master playlist and extracts individual stream URLs with bandwidth-derived quality.
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (s *Service) ProxyStream(ctx context.Context, targetURL string, referer str
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.handleProxyResponse(ctx, resp, targetURL, referer, rangeHeader)
|
return s.handleProxyResponse(ctx, resp, targetURL, referer)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, nil, nil, nil, fmt.Errorf("upstream request failed after %d retries: %w", maxRetries+1, lastErr)
|
return 0, nil, nil, nil, fmt.Errorf("upstream request failed after %d retries: %w", maxRetries+1, lastErr)
|
||||||
@@ -55,7 +55,7 @@ func (s *Service) ProxyStream(ctx context.Context, targetURL string, referer str
|
|||||||
|
|
||||||
// handleProxyResponse processes the upstream response.
|
// handleProxyResponse processes the upstream response.
|
||||||
// rewrites m3u8 playlists to proxy through our backend.
|
// rewrites m3u8 playlists to proxy through our backend.
|
||||||
func (s *Service) handleProxyResponse(ctx context.Context, resp *http.Response, targetURL string, referer string, rangeHeader string) (int, http.Header, []byte, io.ReadCloser, error) {
|
func (s *Service) handleProxyResponse(ctx context.Context, resp *http.Response, targetURL string, referer string) (int, http.Header, []byte, io.ReadCloser, error) {
|
||||||
|
|
||||||
// check if response is an m3u8 playlist that needs rewriting
|
// check if response is an m3u8 playlist that needs rewriting
|
||||||
if isM3U8(targetURL, resp.Header.Get("Content-Type")) {
|
if isM3U8(targetURL, resp.Header.Get("Content-Type")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user