mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Transcoder: Fix missing last chapter
This commit is contained in:
parent
9222b2e2d3
commit
8a2343e76b
@ -252,13 +252,14 @@ func getInfo(path string) (*MediaInfo, error) {
|
||||
|
||||
// fmt.Printf("%s", mi.Option("info_parameters", ""))
|
||||
|
||||
// duration in seconds
|
||||
duration := ParseFloat(mi.Parameter(mediainfo.StreamGeneral, 0, "Duration")) / 1000
|
||||
ret := MediaInfo{
|
||||
Path: path,
|
||||
// Remove leading .
|
||||
Extension: filepath.Ext(path)[1:],
|
||||
Size: ParseUint64(mi.Parameter(mediainfo.StreamGeneral, 0, "FileSize")),
|
||||
// convert ms to seconds
|
||||
Duration: ParseFloat(mi.Parameter(mediainfo.StreamGeneral, 0, "Duration")) / 1000,
|
||||
Duration: duration,
|
||||
Container: OrNull(mi.Parameter(mediainfo.StreamGeneral, 0, "Format")),
|
||||
Videos: Map(make([]Video, ParseUint(mi.Parameter(mediainfo.StreamVideo, 0, "StreamCount"))), func(_ Video, i int) Video {
|
||||
return Video{
|
||||
@ -310,7 +311,7 @@ func getInfo(path string) (*MediaInfo, error) {
|
||||
Link: link,
|
||||
}
|
||||
}),
|
||||
Chapters: getChapters(chapters_begin, chapters_end, mi),
|
||||
Chapters: getChapters(chapters_begin, chapters_end, mi, duration),
|
||||
Fonts: Map(
|
||||
attachments,
|
||||
func(font string, _ int) string {
|
||||
@ -345,8 +346,8 @@ func chapterTimeIsValid(chapterTime string) bool {
|
||||
return len(chapterTime) > 0 && unicode.IsDigit(rune(chapterTime[0]))
|
||||
}
|
||||
|
||||
func getChapters(chapters_begin uint32, chapters_end uint32, mi *mediainfo.File) []Chapter {
|
||||
chapterCount := max(chapters_end-chapters_begin, 1) - 1
|
||||
func getChapters(chapters_begin uint32, chapters_end uint32, mi *mediainfo.File, duration float32) []Chapter {
|
||||
chapterCount := max(chapters_end-chapters_begin, 1)
|
||||
chapterIterationCount := chapterCount
|
||||
|
||||
for i := uint32(0); i < chapterIterationCount; i++ {
|
||||
@ -360,11 +361,16 @@ func getChapters(chapters_begin uint32, chapters_end uint32, mi *mediainfo.File)
|
||||
if !chapterTimeIsValid(startTime) {
|
||||
return Chapter{}
|
||||
}
|
||||
// +1 is safe, the value at chapters_end contains the right duration
|
||||
rawEndTime := mi.GetI(mediainfo.StreamMenu, 0, int(chapters_begin)+i+1, mediainfo.InfoName)
|
||||
parsedEndTime := duration
|
||||
if chapterTimeIsValid(rawEndTime) {
|
||||
parsedEndTime = ParseTime(rawEndTime)
|
||||
}
|
||||
return Chapter{
|
||||
StartTime: ParseTime(startTime),
|
||||
// +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),
|
||||
EndTime: parsedEndTime,
|
||||
Name: mi.GetI(mediainfo.StreamMenu, 0, int(chapters_begin)+i, mediainfo.InfoText),
|
||||
}
|
||||
}), func(chapter Chapter, i int) bool {
|
||||
return chapter != Chapter{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user