first commit
This commit is contained in:
40
models/race.go
Normal file
40
models/race.go
Normal file
@ -0,0 +1,40 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.rouggy.com/rouggy/RaceBot/database"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
type Race struct {
|
||||
gorm.Model
|
||||
Hash string `gorm:"column:hash;type:varchar(50)" form:"hash" json:"hash" binding:"max=50"`
|
||||
TorrentName string `gorm:"column:torrent_name;varchar(100);not null" form:"torrent_name" json:"torrent_name" binding:"required,max=100"`
|
||||
Category string `gorm:"column:category;varchar(50);not null" form:"category" json:"category" binding:"max=50"`
|
||||
ContentPath string `gorm:"column:content_path;varchar(100);not null" form:"content_path" json:"content_path" binding:"max=100"`
|
||||
RootPath string `gorm:"column:root_path;varchar(100)" form:"root_path" json:"root_path" binding:"max=100"`
|
||||
Size string `gorm:"column:size;varchar(15)" form:"size" json:"size" binding:"max=15"`
|
||||
Won bool `gorm:"column:won;bool" form:"won" json:"won"`
|
||||
}
|
||||
|
||||
func NewRace() *Race {
|
||||
r := &Race{}
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Race) SaveRace() (*Race, error) {
|
||||
db := database.GetDB()
|
||||
err := db.Create(&r).Error
|
||||
if err != nil {
|
||||
return &Race{}, err
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (r *Race) GetRaceByName(title string) (*Race, error) {
|
||||
db := database.GetDB()
|
||||
err := db.Where(Race{TorrentName: title}).Find(&r).Error
|
||||
if err != nil {
|
||||
return &Race{}, err
|
||||
}
|
||||
return r, nil
|
||||
}
|
83
models/release.go
Normal file
83
models/release.go
Normal file
@ -0,0 +1,83 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.rouggy.com/rouggy/RaceBot/database"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/moistari/rls"
|
||||
)
|
||||
|
||||
type Release struct {
|
||||
gorm.Model
|
||||
Type string `gorm:"column:type;varchar(10);not null" form:"type" json:"type" binding:"required,max=10"`
|
||||
TorrentName string `gorm:"column:torrent_name;varchar(100);not null" form:"torrent_name" json:"torrent_name" binding:"required,max=100"`
|
||||
Title string `gorm:"column:title;varchar(100);not null" form:"title" json:"title" binding:"required,max=100"`
|
||||
Season int `gorm:"column:season;integer" form:"season" json:"season" binding:"required,max=100"`
|
||||
Episode int `gorm:"column:episode;integer" form:"episode" json:"episode" binding:"required,max=100"`
|
||||
Subtitle string `gorm:"column:subtitle;varchar(10)" form:"subtitle" json:"subtitle" binding:"max=10"`
|
||||
Source string `gorm:"column:source;varchar(15)" form:"source" json:"source" binding:"max=15"`
|
||||
Resolution string `gorm:"column:resolution;varchar(10)" form:"resolution" json:"resolution" binding:"max=10"`
|
||||
Codec string `gorm:"many2many:release_codecs;column:codec;varchar(10)" form:"codec" json:"codec" binding:"max=10"`
|
||||
HDR string `gorm:"many2many:releases_hdr;column:hdr;varchar(10)" form:"hdr" json:"hdr" binding:"max=10"`
|
||||
Audio string `gorm:"many2many:releases_audio;column:audio;varchar(10)" form:"audio" json:"audio" binding:"max=10"`
|
||||
Channels string `gorm:"column:channels;varchar(10)" form:"channels" json:"channels" binding:"max=10"`
|
||||
Group string `gorm:"column:group;varchar(20)" form:"group" json:"group" binding:"max=20"`
|
||||
Other string `gorm:"many2many:releases_other;column:other;varchar(20)" form:"other" json:"other" binding:"max=20"`
|
||||
Language string `gorm:"many2many:releases_languages;column:language;varchar(20)" form:"language" json:"language" binding:"max=20"`
|
||||
ReleaseType string `gorm:"column:release_type;varchar(20)" form:"release_type" json:"release_type" binding:"max=20"`
|
||||
Year int `gorm:"column:year;integer" form:"year" json:"year" binding:"max=4"`
|
||||
}
|
||||
|
||||
func NewRelease() *Release {
|
||||
r := &Release{}
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *Release) ParseString(title string) {
|
||||
rel := rls.ParseString(title)
|
||||
|
||||
r.TorrentName = title
|
||||
r.Source = rel.Source
|
||||
r.Resolution = rel.Resolution
|
||||
if rel.Audio != nil {
|
||||
r.Audio = rel.Audio[0]
|
||||
}
|
||||
r.Audio = rel.Channels
|
||||
r.Codec = rel.Codec[0]
|
||||
if rel.HDR != nil {
|
||||
r.HDR = rel.HDR[0]
|
||||
}
|
||||
if rel.Other != nil {
|
||||
r.Other = rel.Other[0]
|
||||
}
|
||||
if rel.Language != nil {
|
||||
r.Language = rel.Language[0]
|
||||
}
|
||||
|
||||
if r.Title == "" {
|
||||
r.Title = rel.Title
|
||||
}
|
||||
|
||||
if r.Season == 0 {
|
||||
r.Season = rel.Series
|
||||
}
|
||||
if r.Episode == 0 {
|
||||
r.Episode = rel.Episode
|
||||
}
|
||||
|
||||
if r.Year == 0 {
|
||||
r.Year = rel.Year
|
||||
}
|
||||
|
||||
if r.Group == "" {
|
||||
r.Group = rel.Group
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Release) SaveRelease() (*Release, error) {
|
||||
db := database.GetDB()
|
||||
err := db.Create(&r).Error
|
||||
if err != nil {
|
||||
return &Release{}, err
|
||||
}
|
||||
return r, nil
|
||||
}
|
Reference in New Issue
Block a user