mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Added context to downloader and moved method from utils to downloader
This commit is contained in:
parent
c557486089
commit
0a4b9ec96e
2 changed files with 53 additions and 39 deletions
32
utils.go
32
utils.go
|
|
@ -1,11 +1,7 @@
|
|||
package crunchyroll
|
||||
|
||||
import (
|
||||
"crypto/cipher"
|
||||
"encoding/json"
|
||||
"github.com/grafov/m3u8"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func decodeMapToStruct(m interface{}, s interface{}) error {
|
||||
|
|
@ -16,34 +12,6 @@ func decodeMapToStruct(m interface{}, s interface{}) error {
|
|||
return json.Unmarshal(jsonBody, s)
|
||||
}
|
||||
|
||||
// https://github.com/oopsguy/m3u8/blob/4150e93ec8f4f8718875a02973f5d792648ecb97/tool/crypt.go#L25
|
||||
func decryptSegment(client *http.Client, segment *m3u8.MediaSegment, block cipher.Block, iv []byte) ([]byte, error) {
|
||||
resp, err := client.Get(segment.URI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
raw, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blockMode := cipher.NewCBCDecrypter(block, iv[:block.BlockSize()])
|
||||
decrypted := make([]byte, len(raw))
|
||||
blockMode.CryptBlocks(decrypted, raw)
|
||||
raw = pkcs5UnPadding(decrypted)
|
||||
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
// https://github.com/oopsguy/m3u8/blob/4150e93ec8f4f8718875a02973f5d792648ecb97/tool/crypt.go#L47
|
||||
func pkcs5UnPadding(origData []byte) []byte {
|
||||
length := len(origData)
|
||||
unPadding := int(origData[length-1])
|
||||
return origData[:(length - unPadding)]
|
||||
}
|
||||
|
||||
func regexGroups(parsed [][]string, subexpNames ...string) map[string]string {
|
||||
groups := map[string]string{}
|
||||
for _, match := range parsed {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue