Compare commits
No commits in common. "ac01362ae560631b41bb753873d8cf98fe23026a" and "53bbded00fe64267a3481bbb7ad68c9f994da789" have entirely different histories.
ac01362ae5
...
53bbded00f
@ -1,53 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"git.milar.in/nyaanime/model"
|
|
||||||
"git.milar.in/nyaanime/parsers"
|
|
||||||
"gopkg.in/vansante/go-ffprobe.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO cache
|
|
||||||
func AnalyzeFile(path string) (*model.ParsedFile, error) {
|
|
||||||
props := &model.ParsedFile{File: path}
|
|
||||||
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
data, err := ffprobe.ProbeReader(context.Background(), file)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultVideoLang := ""
|
|
||||||
for _, s := range data.StreamType(ffprobe.StreamVideo) {
|
|
||||||
if s.Disposition.Default > 0 {
|
|
||||||
props.Resolution = model.Resolution(s.Height)
|
|
||||||
defaultVideoLang = parsers.ParseLanguage(s.Tags.Language)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range data.StreamType(ffprobe.StreamAudio) {
|
|
||||||
if s.Tags.Language != "" {
|
|
||||||
props.Languages = append(props.Languages, parsers.ParseLanguage(s.Tags.Language))
|
|
||||||
} else if s.Disposition.Default > 0 {
|
|
||||||
props.Languages = append(props.Languages, defaultVideoLang)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, s := range data.StreamType(ffprobe.StreamSubtitle) {
|
|
||||||
if s.Tags.Language != "" {
|
|
||||||
props.Subtitles = append(props.Subtitles, parsers.ParseLanguage(s.Tags.Language))
|
|
||||||
} else if s.Disposition.Default > 0 {
|
|
||||||
props.Subtitles = append(props.Subtitles, defaultVideoLang)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return props, nil
|
|
||||||
}
|
|
@ -19,8 +19,11 @@ var (
|
|||||||
|
|
||||||
AnimePath = envvars.String("ANIME_PATH", "")
|
AnimePath = envvars.String("ANIME_PATH", "")
|
||||||
|
|
||||||
AnimeEpFilepathPatternStr = envvars.String("EPISODE_FILEPATH_PATTERN", `{{.Anime.Title.UserPreferred}}/{{.Anime.Title.UserPreferred}} Episode {{.Episode}}.{{.Ext}}`)
|
AnimeEpFilepathPattern = envvars.Object(
|
||||||
AnimeEpFilepathPattern = template.Must(template.New("EPISODE_FILEPATH_PATTERN").Parse(AnimeEpFilepathPatternStr))
|
"EPISODE_FILEPATH_PATTERN",
|
||||||
|
template.Must(template.New("anime-episode-filepath-pattern").Parse(`{{.Anime.Title.UserPreferred}}/{{.Anime.Title.UserPreferred}} Episode {{.Episode}}.{{.Ext}}`)),
|
||||||
|
template.New("anime-episode-filepath-pattern").Parse,
|
||||||
|
)
|
||||||
|
|
||||||
// essential torrent properties
|
// essential torrent properties
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"git.milar.in/milarin/slices"
|
"git.milar.in/milarin/slices"
|
||||||
"git.milar.in/nyaanime/model"
|
"git.milar.in/nyaanime/model"
|
||||||
|
"git.milar.in/nyaanime/parsers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAnimeEpProps(animeEp model.AnimeEpisode) (*FilePriority, bool) {
|
func GetAnimeEpProps(animeEp model.AnimeEpisode) (*FilePriority, bool) {
|
||||||
@ -17,7 +18,7 @@ func GetAnimeEpProps(animeEp model.AnimeEpisode) (*FilePriority, bool) {
|
|||||||
var mostPrio *FilePriority
|
var mostPrio *FilePriority
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
props, err := AnalyzeFile(file)
|
props, err := parsers.AnalyzeFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -12,10 +12,10 @@ require (
|
|||||||
git.milar.in/milarin/tprint v0.0.7
|
git.milar.in/milarin/tprint v0.0.7
|
||||||
git.milar.in/nyaanime/model v0.0.0-20230113095840-5eb2822653c3
|
git.milar.in/nyaanime/model v0.0.0-20230113095840-5eb2822653c3
|
||||||
git.milar.in/nyaanime/parsers v0.0.0-20221207192513-e7bce7c418d8
|
git.milar.in/nyaanime/parsers v0.0.0-20221207192513-e7bce7c418d8
|
||||||
gopkg.in/vansante/go-ffprobe.v2 v2.1.1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||||
github.com/rivo/uniseg v0.3.4 // indirect
|
github.com/rivo/uniseg v0.3.4 // indirect
|
||||||
|
gopkg.in/vansante/go-ffprobe.v2 v2.1.1 // indirect
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user