Initial commit
This commit is contained in:
commit
605652b0e3
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"nuxt.isNuxtApp": false
|
||||
}
|
23
anilibria/GetTeam.go
Normal file
23
anilibria/GetTeam.go
Normal file
@ -0,0 +1,23 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"git.thefoxon.ru/anilibria/anilibria-go/model"
|
||||
)
|
||||
|
||||
func GetTeam() (team *model.Team, err error) {
|
||||
|
||||
reqBody, status, err := request("GET", "/v3/team", nil)
|
||||
|
||||
if status != 200 {
|
||||
return nil, errors.New(errorFetchTeam)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(reqBody, &team); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
24
anilibria/GetTitleByCode.go
Normal file
24
anilibria/GetTitleByCode.go
Normal file
@ -0,0 +1,24 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.thefoxon.ru/anilibria/anilibria-go/model"
|
||||
)
|
||||
|
||||
func GetTitleByCode(code string) (title *model.Title, err error) {
|
||||
|
||||
reqBody, status, err := request("GET", fmt.Sprintf("/v3/title?code=%s", code), nil)
|
||||
|
||||
if status != 200 {
|
||||
return nil, errors.New(errorFetchTitle)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(reqBody, &title); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
28
anilibria/GetTitleByID.go
Normal file
28
anilibria/GetTitleByID.go
Normal file
@ -0,0 +1,28 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.thefoxon.ru/anilibria/anilibria-go/model"
|
||||
)
|
||||
|
||||
func GetTitleByID(id uint64) (title *model.Title, err error) {
|
||||
|
||||
if id == 0 {
|
||||
return nil, errors.New(errorTitleIdIsZero)
|
||||
}
|
||||
|
||||
reqBody, status, err := request("GET", fmt.Sprintf("/v3/title?id=%d", id), nil)
|
||||
|
||||
if status != 200 {
|
||||
return nil, errors.New(errorFetchTitle)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(reqBody, &title); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
28
anilibria/GetTitleByTorrentID.go
Normal file
28
anilibria/GetTitleByTorrentID.go
Normal file
@ -0,0 +1,28 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.thefoxon.ru/anilibria/anilibria-go/model"
|
||||
)
|
||||
|
||||
func GetTitleByTorrentID(id uint64) (title *model.Title, err error) {
|
||||
|
||||
if id == 0 {
|
||||
return nil, errors.New(errorTitleIdIsZero)
|
||||
}
|
||||
|
||||
reqBody, status, err := request("GET", fmt.Sprintf("/v3/title?torrent_id=%d", id), nil)
|
||||
|
||||
if status != 200 {
|
||||
return nil, errors.New(errorFetchTitle)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(reqBody, &title); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
23
anilibria/GetTitleChanges.go
Normal file
23
anilibria/GetTitleChanges.go
Normal file
@ -0,0 +1,23 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"git.thefoxon.ru/anilibria/anilibria-go/model"
|
||||
)
|
||||
|
||||
func GetTitleChanges() (titles *[]model.TitleList, err error) {
|
||||
|
||||
reqBody, status, err := request("GET", "/v3/title/changes", nil)
|
||||
|
||||
if status != 200 {
|
||||
return nil, errors.New(errorFetchTitle)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(reqBody, &titles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
23
anilibria/GetTitleList.go
Normal file
23
anilibria/GetTitleList.go
Normal file
@ -0,0 +1,23 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"git.thefoxon.ru/anilibria/anilibria-go/model"
|
||||
)
|
||||
|
||||
func GetTitleList() (title *[]model.Title, err error) {
|
||||
|
||||
reqBody, status, err := request("GET", "/v3/title/list", nil)
|
||||
|
||||
if status != 200 {
|
||||
return nil, errors.New(errorFetchTitle)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(reqBody, &title); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
23
anilibria/GetTitleRandom.go
Normal file
23
anilibria/GetTitleRandom.go
Normal file
@ -0,0 +1,23 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"git.thefoxon.ru/anilibria/anilibria-go/model"
|
||||
)
|
||||
|
||||
func GetTitleRandom() (titles *model.TitleList, err error) {
|
||||
|
||||
reqBody, status, err := request("GET", "/v3/title/random", nil)
|
||||
|
||||
if status != 200 {
|
||||
return nil, errors.New(errorFetchTitle)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(reqBody, &titles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
23
anilibria/GetTitleUpdates.go
Normal file
23
anilibria/GetTitleUpdates.go
Normal file
@ -0,0 +1,23 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"git.thefoxon.ru/anilibria/anilibria-go/model"
|
||||
)
|
||||
|
||||
func GetTitleUpdates() (titles *[]model.TitleList, err error) {
|
||||
|
||||
reqBody, status, err := request("GET", "/v3/title/updates", nil)
|
||||
|
||||
if status != 200 {
|
||||
return nil, errors.New(errorFetchTitle)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(reqBody, &titles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
9
anilibria/errors.go
Normal file
9
anilibria/errors.go
Normal file
@ -0,0 +1,9 @@
|
||||
package anilibria
|
||||
|
||||
const (
|
||||
// GetTitleErrors
|
||||
errorFetchTitle = "Error fetch title"
|
||||
errorTitleIdIsZero = "Error title ID is zero"
|
||||
// GetTeamErrors
|
||||
errorFetchTeam = "Error fetch team"
|
||||
)
|
35
anilibria/request.go
Normal file
35
anilibria/request.go
Normal file
@ -0,0 +1,35 @@
|
||||
package anilibria
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func request(method string, url string, body io.Reader) ([]byte, int, error) {
|
||||
var err error
|
||||
var req *http.Request
|
||||
var res *http.Response
|
||||
var client *http.Client = http.DefaultClient
|
||||
|
||||
url = getURL(url)
|
||||
|
||||
if req, err = http.NewRequest(method, url, body); err != nil {
|
||||
return nil, -1, err
|
||||
}
|
||||
|
||||
if res, err = client.Do(req); err != nil {
|
||||
return nil, -1, err
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
data, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, res.StatusCode, err
|
||||
}
|
||||
return data, res.StatusCode, nil
|
||||
}
|
||||
|
||||
func getURL(path string) string {
|
||||
return fmt.Sprintf("%s%s", BASE_URL, path)
|
||||
}
|
3
anilibria/vars.go
Normal file
3
anilibria/vars.go
Normal file
@ -0,0 +1,3 @@
|
||||
package anilibria
|
||||
|
||||
var BASE_URL string = "http://api.anilibria.tv"
|
3
go.mod
Normal file
3
go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module git.thefoxon.ru/anilibria/anilibria-go
|
||||
|
||||
go 1.21.1
|
7
model/Episodes.go
Normal file
7
model/Episodes.go
Normal file
@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
type Episodes struct {
|
||||
First int `json:"first"`
|
||||
Last int `json:"last"`
|
||||
String string `json:"string"`
|
||||
}
|
8
model/Pagination.go
Normal file
8
model/Pagination.go
Normal file
@ -0,0 +1,8 @@
|
||||
package model
|
||||
|
||||
type Pagination struct {
|
||||
Pages int64 `json:"pages"`
|
||||
CurrentPage int64 `json:"current_page"`
|
||||
ItemsPerPage int64 `json:"items_per_page"`
|
||||
TotalItems int64 `json:"total_items"`
|
||||
}
|
37
model/Player.go
Normal file
37
model/Player.go
Normal file
@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
type Player struct {
|
||||
AlternativePlayer string `json:"alternative_player"`
|
||||
Host string `json:"host"`
|
||||
IsRutube bool `json:"is_rutube"`
|
||||
Episodes Episodes `json:"episodes"`
|
||||
List map[string]playerEpisode `json:"list"`
|
||||
Rutube map[string]rutubeEpisod `json:"rutube"`
|
||||
}
|
||||
|
||||
type playerEpisode struct {
|
||||
Episode int `json:"episode"`
|
||||
Name string `json:"name"`
|
||||
UUID string `json:"uuid"`
|
||||
CreatedTimestamp int `json:"created_timestamp"`
|
||||
Preview string `json:"preview"`
|
||||
Skips playerSkips `json:"skips"`
|
||||
Hls playerHls `json:"hls"`
|
||||
}
|
||||
|
||||
type playerSkips struct {
|
||||
Opening []any `json:"opening"`
|
||||
Ending []any `json:"ending"`
|
||||
}
|
||||
|
||||
type playerHls struct {
|
||||
Fhd string `json:"fhd"`
|
||||
Hd string `json:"hd"`
|
||||
Sd string `json:"sd"`
|
||||
}
|
||||
|
||||
type rutubeEpisod struct {
|
||||
Episode int `json:"episode"`
|
||||
CreatedTimestamp int `json:"created_timestamp"`
|
||||
RutubeID string `json:"rutube_id"`
|
||||
}
|
9
model/Team.go
Normal file
9
model/Team.go
Normal file
@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
type Team struct {
|
||||
Voice []string `json:"voice"`
|
||||
Translator []string `json:"translator"`
|
||||
Editing []string `json:"editing"`
|
||||
Decor []string `json:"decor"`
|
||||
Timing []string `json:"timing"`
|
||||
}
|
69
model/Title.go
Normal file
69
model/Title.go
Normal file
@ -0,0 +1,69 @@
|
||||
package model
|
||||
|
||||
type Title struct {
|
||||
ID int `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Names titleNames `json:"names"`
|
||||
Franchises []any `json:"franchises"`
|
||||
Announce any `json:"announce"`
|
||||
Status titleStatus `json:"status"`
|
||||
Posters titlePosters `json:"posters"`
|
||||
Updated int `json:"updated"`
|
||||
LastChange int `json:"last_change"`
|
||||
Type titleType `json:"type"`
|
||||
Genres []string `json:"genres"`
|
||||
Team Team `json:"team"`
|
||||
Season titleSeason `json:"season"`
|
||||
Description string `json:"description"`
|
||||
InFavorites int `json:"in_favorites"`
|
||||
Blocked titleBlocked `json:"blocked"`
|
||||
Player Player `json:"player"`
|
||||
Torrents titleTorrents `json:"torrents"`
|
||||
}
|
||||
|
||||
type titleNames struct {
|
||||
Ru string `json:"ru"`
|
||||
En string `json:"en"`
|
||||
Alternative any `json:"alternative"`
|
||||
}
|
||||
|
||||
type titleStatus struct {
|
||||
String string `json:"string"`
|
||||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
type titlePoster struct {
|
||||
URL string `json:"url"`
|
||||
RawBase64File any `json:"raw_base64_file"`
|
||||
}
|
||||
|
||||
type titlePosters struct {
|
||||
Small titlePoster `json:"small"`
|
||||
Medium titlePoster `json:"medium"`
|
||||
Original titlePoster `json:"original"`
|
||||
}
|
||||
|
||||
type titleType struct {
|
||||
FullString string `json:"full_string"`
|
||||
Code int `json:"code"`
|
||||
String string `json:"string"`
|
||||
Episodes int `json:"episodes"`
|
||||
Length int `json:"length"`
|
||||
}
|
||||
|
||||
type titleSeason struct {
|
||||
String string `json:"string"`
|
||||
Code int `json:"code"`
|
||||
Year int `json:"year"`
|
||||
WeekDay int `json:"week_day"`
|
||||
}
|
||||
|
||||
type titleBlocked struct {
|
||||
Blocked bool `json:"blocked"`
|
||||
Bakanim bool `json:"bakanim"`
|
||||
}
|
||||
|
||||
type titleTorrents struct {
|
||||
Episodes Episodes `json:"episodes"`
|
||||
List []Torrent `json:"list"`
|
||||
}
|
6
model/TitleList.go
Normal file
6
model/TitleList.go
Normal file
@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type TitleList struct {
|
||||
List []Title `json:"list"`
|
||||
Pagination Pagination `json:"pagination"`
|
||||
}
|
26
model/Torrent.go
Normal file
26
model/Torrent.go
Normal file
@ -0,0 +1,26 @@
|
||||
package model
|
||||
|
||||
type Torrent struct {
|
||||
TorrentID int `json:"torrent_id"`
|
||||
Episodes Episodes `json:"episodes"`
|
||||
Quality torrentQuality `json:"quality"`
|
||||
Leechers int `json:"leechers"`
|
||||
Seeders int `json:"seeders"`
|
||||
Downloads int `json:"downloads"`
|
||||
TotalSize int64 `json:"total_size"`
|
||||
SizeString string `json:"size_string"`
|
||||
URL string `json:"url"`
|
||||
Magnet string `json:"magnet"`
|
||||
UploadedTimestamp int `json:"uploaded_timestamp"`
|
||||
Hash string `json:"hash"`
|
||||
Metadata any `json:"metadata"`
|
||||
RawBase64File *string `json:"raw_base64_file"`
|
||||
}
|
||||
|
||||
type torrentQuality struct {
|
||||
String string `json:"string"`
|
||||
Type string `json:"type"`
|
||||
Resolution string `json:"resolution"`
|
||||
Encoder string `json:"encoder"`
|
||||
LqAudio any `json:"lq_audio"`
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user