mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Added context to the crunchyroll struct
This commit is contained in:
parent
a6c14cb6c9
commit
ac7904668f
3 changed files with 12 additions and 3 deletions
|
|
@ -2,6 +2,7 @@ package crunchyroll
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -32,6 +33,8 @@ const (
|
||||||
type Crunchyroll struct {
|
type Crunchyroll struct {
|
||||||
// Client is the http.Client to perform all requests over
|
// Client is the http.Client to perform all requests over
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
|
// Context can be used to stop requests with Client and is context.Background by default
|
||||||
|
Context context.Context
|
||||||
// Locale specifies in which language all results should be returned / requested
|
// Locale specifies in which language all results should be returned / requested
|
||||||
Locale LOCALE
|
Locale LOCALE
|
||||||
// SessionID is the crunchyroll session id which was used for authentication
|
// SessionID is the crunchyroll session id which was used for authentication
|
||||||
|
|
@ -88,6 +91,7 @@ func LoginWithCredentials(user string, password string, locale LOCALE, client *h
|
||||||
func LoginWithSessionID(sessionID string, locale LOCALE, client *http.Client) (*Crunchyroll, error) {
|
func LoginWithSessionID(sessionID string, locale LOCALE, client *http.Client) (*Crunchyroll, error) {
|
||||||
crunchy := &Crunchyroll{
|
crunchy := &Crunchyroll{
|
||||||
Client: client,
|
Client: client,
|
||||||
|
Context: context.Background(),
|
||||||
Locale: locale,
|
Locale: locale,
|
||||||
SessionID: sessionID,
|
SessionID: sessionID,
|
||||||
cache: true,
|
cache: true,
|
||||||
|
|
|
||||||
|
|
@ -363,11 +363,10 @@ func (d Downloader) downloadSegment(format *Format, segment *m3u8.MediaSegment,
|
||||||
|
|
||||||
// https://github.com/oopsguy/m3u8/blob/4150e93ec8f4f8718875a02973f5d792648ecb97/tool/crypt.go#L25
|
// https://github.com/oopsguy/m3u8/blob/4150e93ec8f4f8718875a02973f5d792648ecb97/tool/crypt.go#L25
|
||||||
func (d Downloader) decryptSegment(client *http.Client, segment *m3u8.MediaSegment, block cipher.Block, iv []byte) ([]byte, error) {
|
func (d Downloader) decryptSegment(client *http.Client, segment *m3u8.MediaSegment, block cipher.Block, iv []byte) ([]byte, error) {
|
||||||
req, err := http.NewRequest(http.MethodGet, segment.URI, nil)
|
req, err := http.NewRequestWithContext(d.Context, http.MethodGet, segment.URI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.WithContext(d.Context)
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package crunchyroll
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Subtitle struct {
|
type Subtitle struct {
|
||||||
|
|
@ -13,7 +14,12 @@ type Subtitle struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Subtitle) Save(writer io.Writer) error {
|
func (s Subtitle) Save(writer io.Writer) error {
|
||||||
resp, err := s.crunchy.Client.Get(s.URL)
|
req, err := http.NewRequestWithContext(s.crunchy.Context, http.MethodGet, s.URL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := s.crunchy.Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue