mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Move and refactor files and some more changes :3
This commit is contained in:
parent
781e520591
commit
303689ecbb
29 changed files with 1305 additions and 1160 deletions
63
utils/format.go
Normal file
63
utils/format.go
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ByteDream/crunchyroll-go/v3"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type FormatInformation struct {
|
||||
// the Format to download
|
||||
Format *crunchyroll.Format
|
||||
|
||||
// additional formats which are only used by archive.go
|
||||
AdditionalFormats []*crunchyroll.Format
|
||||
|
||||
Title string `json:"title"`
|
||||
SeriesName string `json:"series_name"`
|
||||
SeasonName string `json:"season_name"`
|
||||
SeasonNumber int `json:"season_number"`
|
||||
EpisodeNumber int `json:"episode_number"`
|
||||
Resolution string `json:"resolution"`
|
||||
FPS float64 `json:"fps"`
|
||||
Audio crunchyroll.LOCALE `json:"audio"`
|
||||
Subtitle crunchyroll.LOCALE `json:"subtitle"`
|
||||
}
|
||||
|
||||
func (fi FormatInformation) FormatString(source string) string {
|
||||
fields := reflect.TypeOf(fi)
|
||||
values := reflect.ValueOf(fi)
|
||||
|
||||
for i := 0; i < fields.NumField(); i++ {
|
||||
var valueAsString string
|
||||
switch value := values.Field(i); value.Kind() {
|
||||
case reflect.String:
|
||||
valueAsString = value.String()
|
||||
case reflect.Int:
|
||||
valueAsString = fmt.Sprintf("%02d", value.Int())
|
||||
case reflect.Float64:
|
||||
valueAsString = fmt.Sprintf("%.2f", value.Float())
|
||||
case reflect.Bool:
|
||||
valueAsString = fields.Field(i).Tag.Get("json")
|
||||
if !value.Bool() {
|
||||
valueAsString = "no " + valueAsString
|
||||
}
|
||||
}
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
for _, char := range []string{"/"} {
|
||||
valueAsString = strings.ReplaceAll(valueAsString, char, "")
|
||||
}
|
||||
} else {
|
||||
for _, char := range []string{"\\", "<", ">", ":", "\"", "/", "|", "?", "*"} {
|
||||
valueAsString = strings.ReplaceAll(valueAsString, char, "")
|
||||
}
|
||||
}
|
||||
|
||||
source = strings.ReplaceAll(source, "{"+fields.Field(i).Tag.Get("json")+"}", valueAsString)
|
||||
}
|
||||
|
||||
return source
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue