mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-08 10:44:20 -04:00
Add chapters in info
This commit is contained in:
parent
1cb54f44b1
commit
a6076eb856
@ -11,7 +11,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
github.com/zelenin/go-mediainfo v1.0.0 // indirect
|
||||
github.com/zoriya/go-mediainfo v0.0.0-20240113000440-36f500affcfd // indirect
|
||||
golang.org/x/crypto v0.17.0 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
|
@ -13,8 +13,10 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
github.com/zelenin/go-mediainfo v1.0.0 h1:P0rKGyrSwKBCj37Ul7TLkrhf5OVBPlh3fFe9ZqjiaKQ=
|
||||
github.com/zelenin/go-mediainfo v1.0.0/go.mod h1:6jxR5y1gDozFdCD7NYq/kUjCo5nqeogYCal6wpv81nY=
|
||||
github.com/zoriya/go-mediainfo v0.0.0-20240112235842-ce0c807be738 h1:FV9TIvf/T84cRxRdBN6brSWKq+PqrGHmqbeDhmI+3tc=
|
||||
github.com/zoriya/go-mediainfo v0.0.0-20240112235842-ce0c807be738/go.mod h1:jzun1oQGoJSh65g1XKaolTmjd6HW/34WHH7VMdJdbvM=
|
||||
github.com/zoriya/go-mediainfo v0.0.0-20240113000440-36f500affcfd h1:AOdEpcmYJkmIW4I76TQim6LT4+9duYTdXNgkQsPHpuA=
|
||||
github.com/zoriya/go-mediainfo v0.0.0-20240113000440-36f500affcfd/go.mod h1:jzun1oQGoJSh65g1XKaolTmjd6HW/34WHH7VMdJdbvM=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/zelenin/go-mediainfo"
|
||||
"github.com/zoriya/go-mediainfo"
|
||||
)
|
||||
|
||||
type MediaInfo struct {
|
||||
@ -96,7 +96,7 @@ type Chapter struct {
|
||||
func ParseFloat(str string) float32 {
|
||||
f, err := strconv.ParseFloat(str, 32)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return 0
|
||||
}
|
||||
return float32(f)
|
||||
}
|
||||
@ -104,11 +104,20 @@ func ParseFloat(str string) float32 {
|
||||
func ParseUint(str string) uint32 {
|
||||
i, err := strconv.ParseUint(str, 10, 32)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return 0
|
||||
}
|
||||
return uint32(i)
|
||||
}
|
||||
|
||||
func ParseTime(str string) float32 {
|
||||
x := strings.Split(str, ":")
|
||||
hours, minutes, sms := ParseFloat(x[0]), ParseFloat(x[1]), x[2]
|
||||
y := strings.Split(sms, ".")
|
||||
seconds, ms := ParseFloat(y[0]), ParseFloat(y[1])
|
||||
|
||||
return (hours*60.+minutes)*60. + seconds + ms/1000.
|
||||
}
|
||||
|
||||
// Stolen from the cmp.Or code that is not yet released
|
||||
// Or returns the first of its arguments that is not equal to the zero value.
|
||||
// If no argument is non-zero, it returns the zero value.
|
||||
@ -162,6 +171,9 @@ func GetInfo(path string) (MediaInfo, error) {
|
||||
sha = hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
chapters_begin := ParseUint(mi.Parameter(mediainfo.StreamMenu, 0, "Chapters_Pos_Begin"))
|
||||
chapters_end := ParseUint(mi.Parameter(mediainfo.StreamMenu, 0, "Chapters_Pos_End"))
|
||||
|
||||
return MediaInfo{
|
||||
Sha: sha,
|
||||
Path: path,
|
||||
@ -217,5 +229,13 @@ func GetInfo(path string) (MediaInfo, error) {
|
||||
Link: link,
|
||||
}
|
||||
}),
|
||||
Chapters: Map(make([]Chapter, chapters_end-chapters_begin-1), func(i int) Chapter {
|
||||
return Chapter{
|
||||
StartTime: ParseTime(mi.GetI(mediainfo.StreamMenu, 0, int(chapters_begin)+i, mediainfo.InfoName)),
|
||||
// +1 is safe, the value at chapters_end contains the right duration
|
||||
EndTime: ParseTime(mi.GetI(mediainfo.StreamMenu, 0, int(chapters_begin)+i+1, mediainfo.InfoName)),
|
||||
Name: mi.GetI(mediainfo.StreamMenu, 0, int(chapters_begin)+i, mediainfo.InfoText),
|
||||
}
|
||||
}),
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user