-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathseason.go
More file actions
80 lines (71 loc) · 2.12 KB
/
season.go
File metadata and controls
80 lines (71 loc) · 2.12 KB
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
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
type SeasonEpisodes struct {
Data []SeasonEpisode `json:"data"`
}
type SeasonEpisode struct {
ID string `json:"id"`
Versions []*DubVersion `json:"versions"`
SeasonNumber int `json:"season_number"`
EpisodeNumber int `json:"episode_number"`
SeriesTitle string `json:"series_title"`
AudioLocale string `json:"audio_locale"`
Title string `json:"title"`
AvailabilityStarts string `json:"availability_starts"`
}
func getSeasonEpisodes(contentId string) []SeasonEpisode {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://www.crunchyroll.com/content/v2/cms/seasons/%s/episodes?preferred_audio_language=ja-JP&locale=en-US", contentId), nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0")
resp, err := DoRequest(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var episodes SeasonEpisodes
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
if err = json.Unmarshal(body, &episodes); err != nil {
panic(err)
}
return episodes.Data
}
type Seasons struct {
Data []Season `json:"data"`
}
type Season struct {
ID string `json:"id"`
SeasonNumber int `json:"season_number"`
}
func getSeasons(contentId string) []Season {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://www.crunchyroll.com/content/v2/cms/series/%s/seasons?force_locale=&preferred_audio_language=ja-JP&locale=en-US", contentId), nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0")
resp, err := DoRequest(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var seasons Seasons
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
if err = json.Unmarshal(body, &seasons); err != nil {
panic(err)
}
return seasons.Data
}