This repository has been archived by the owner on Sep 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
movie_listing.go
92 lines (79 loc) · 2.7 KB
/
movie_listing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package crunchyroll
import (
"encoding/json"
"fmt"
"net/http"
)
// MovieListing contains information about something which is called
// movie listing. I don't know what this means thb.
type MovieListing struct {
crunchy *Crunchyroll
ID string `json:"id"`
Title string `json:"title"`
Slug string `json:"slug"`
SlugTitle string `json:"slug_title"`
Description string `json:"description"`
Images struct {
Thumbnail [][]Image `json:"thumbnail"`
} `json:"images"`
DurationMS int `json:"duration_ms"`
IsPremiumOnly bool `json:"is_premium_only"`
ListeningID string `json:"listening_id"`
IsMature bool `json:"is_mature"`
AvailableOffline bool `json:"available_offline"`
IsSubbed bool `json:"is_subbed"`
IsDubbed bool `json:"is_dubbed"`
Playback string `json:"playback"`
AvailabilityNotes string `json:"availability_notes"`
}
// MovieListingFromID returns a movie listing by its api id.
func MovieListingFromID(crunchy *Crunchyroll, id string) (*MovieListing, error) {
resp, err := crunchy.request(fmt.Sprintf("https://beta-api.crunchyroll.com/cms/v2/%s/movie_listing/%s&locale=%s&Signature=%s&Policy=%s&Key-Pair-Id=%s",
crunchy.Config.Bucket,
id,
crunchy.Locale,
crunchy.Config.Signature,
crunchy.Config.Policy,
crunchy.Config.KeyPairID), http.MethodGet)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var jsonBody map[string]interface{}
json.NewDecoder(resp.Body).Decode(&jsonBody)
movieListing := &MovieListing{
crunchy: crunchy,
ID: id,
}
if err = decodeMapToStruct(jsonBody, movieListing); err != nil {
return nil, err
}
return movieListing, nil
}
// AudioLocale is same as Episode.AudioLocale.
func (ml *MovieListing) AudioLocale() (LOCALE, error) {
resp, err := ml.crunchy.request(fmt.Sprintf("https://beta-api.crunchyroll.com/cms/v2/%s/videos/%s/streams?locale=%s&Signature=%s&Policy=%s&Key-Pair-Id=%s",
ml.crunchy.Config.Bucket,
ml.ID,
ml.crunchy.Locale,
ml.crunchy.Config.Signature,
ml.crunchy.Config.Policy,
ml.crunchy.Config.KeyPairID), http.MethodGet)
if err != nil {
return "", err
}
defer resp.Body.Close()
var jsonBody map[string]interface{}
json.NewDecoder(resp.Body).Decode(&jsonBody)
return LOCALE(jsonBody["audio_locale"].(string)), nil
}
// Streams returns all streams which are available for the movie listing.
func (ml *MovieListing) Streams() ([]*Stream, error) {
return fromVideoStreams(ml.crunchy, fmt.Sprintf("https://beta-api.crunchyroll.com/cms/v2/%s/videos/%s/streams?locale=%s&Signature=%s&Policy=%s&Key-Pair-Id=%s",
ml.crunchy.Config.Bucket,
ml.ID,
ml.crunchy.Locale,
ml.crunchy.Config.Signature,
ml.crunchy.Config.Policy,
ml.crunchy.Config.KeyPairID))
}