This commit is contained in:
2024-11-25 17:38:16 +07:00
parent b031b9d09b
commit e2282af31c
7 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,59 @@
package release
import (
"path/filepath"
"strings"
"git.rouggy.com/rouggy/GoUploadAssistant/internal/utils"
"github.com/moistari/rls"
)
type Release struct {
TorrentName string
Title string
Season int
Episode int
Year int
Resolution string
Source string
HDR string
Audio string
AudioChannels string
Group string
Language string
}
func Parse(path string) *Release {
var title string
if utils.IsFolderRelease(path) {
title = filepath.Base(path)
} else {
title = strings.Replace(filepath.Base(path), ".mkv", "", 1)
}
rel := rls.ParseString(title)
r := Release{}
r.TorrentName = title
r.Title = rel.Title
r.Season = rel.Series
r.Episode = rel.Episode
r.Source = rel.Source
r.Resolution = rel.Resolution
r.Year = rel.Year
if len(rel.HDR) > 0 {
r.HDR = rel.HDR[0]
}
if len(rel.Audio) > 0 {
r.Audio = rel.Audio[0]
}
r.AudioChannels = rel.Channels
r.Group = rel.Group
return &r
}

19
internal/utils/utils.go Normal file
View File

@ -0,0 +1,19 @@
package utils
import (
"fmt"
"os"
)
func IsFolderRelease(path string) bool {
info, err := os.Stat(path)
if err != nil {
fmt.Println(err)
}
if info.IsDir() {
return true
} else {
return false
}
}