mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -04:00
Handle ISO-639-2 to IETF BCP 47 translation
This commit is contained in:
parent
c11e1cc8f0
commit
40f02760ab
@ -15,6 +15,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/text/language"
|
||||||
"gopkg.in/vansante/go-ffprobe.v2"
|
"gopkg.in/vansante/go-ffprobe.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ type MediaInfo struct {
|
|||||||
Duration float32 `json:"duration"`
|
Duration float32 `json:"duration"`
|
||||||
/// The container of the video file of this episode.
|
/// The container of the video file of this episode.
|
||||||
Container *string `json:"container"`
|
Container *string `json:"container"`
|
||||||
/// The video codec and infromations.
|
/// The video codec and informations.
|
||||||
Video *Video `json:"video"`
|
Video *Video `json:"video"`
|
||||||
/// The list of videos if there are multiples.
|
/// The list of videos if there are multiples.
|
||||||
Videos []Video `json:"videos"`
|
Videos []Video `json:"videos"`
|
||||||
@ -69,7 +70,7 @@ type Audio struct {
|
|||||||
Index uint32 `json:"index"`
|
Index uint32 `json:"index"`
|
||||||
/// The title of the stream.
|
/// The title of the stream.
|
||||||
Title *string `json:"title"`
|
Title *string `json:"title"`
|
||||||
/// The language of this stream (as a ISO-639-2 language code)
|
/// The language of this stream (as a IETF-BCP-47 language code)
|
||||||
Language *string `json:"language"`
|
Language *string `json:"language"`
|
||||||
/// The human readable codec name.
|
/// The human readable codec name.
|
||||||
Codec string `json:"codec"`
|
Codec string `json:"codec"`
|
||||||
@ -86,7 +87,7 @@ type Subtitle struct {
|
|||||||
Index uint32 `json:"index"`
|
Index uint32 `json:"index"`
|
||||||
/// The title of the stream.
|
/// The title of the stream.
|
||||||
Title *string `json:"title"`
|
Title *string `json:"title"`
|
||||||
/// The language of this stream (as a ISO-639-2 language code)
|
/// The language of this stream (as a IETF-BCP-47 language code)
|
||||||
Language *string `json:"language"`
|
Language *string `json:"language"`
|
||||||
/// The codec of this stream.
|
/// The codec of this stream.
|
||||||
Codec string `json:"codec"`
|
Codec string `json:"codec"`
|
||||||
@ -170,6 +171,13 @@ func OrNull(str string) *string {
|
|||||||
return &str
|
return &str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NullIfUnd(str string) *string {
|
||||||
|
if str == "und" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &str
|
||||||
|
}
|
||||||
|
|
||||||
var SubtitleExtensions = map[string]string{
|
var SubtitleExtensions = map[string]string{
|
||||||
"subrip": "srt",
|
"subrip": "srt",
|
||||||
"ass": "ass",
|
"ass": "ass",
|
||||||
@ -255,10 +263,11 @@ func getInfo(path string) (*MediaInfo, error) {
|
|||||||
Duration: float32(mi.Format.DurationSeconds),
|
Duration: float32(mi.Format.DurationSeconds),
|
||||||
Container: OrNull(mi.Format.FormatName),
|
Container: OrNull(mi.Format.FormatName),
|
||||||
Videos: MapStream(mi.Streams, ffprobe.StreamVideo, func(stream *ffprobe.Stream, i uint32) Video {
|
Videos: MapStream(mi.Streams, ffprobe.StreamVideo, func(stream *ffprobe.Stream, i uint32) Video {
|
||||||
|
lang, _ := language.Parse(stream.Tags.Language)
|
||||||
return Video{
|
return Video{
|
||||||
Codec: stream.CodecName,
|
Codec: stream.CodecName,
|
||||||
MimeCodec: GetMimeCodec(stream),
|
MimeCodec: GetMimeCodec(stream),
|
||||||
Language: OrNull(stream.Tags.Language),
|
Language: NullIfUnd(lang.String()),
|
||||||
Quality: QualityFromHeight(uint32(stream.Height)),
|
Quality: QualityFromHeight(uint32(stream.Height)),
|
||||||
Width: uint32(stream.Width),
|
Width: uint32(stream.Width),
|
||||||
Height: uint32(stream.Height),
|
Height: uint32(stream.Height),
|
||||||
@ -266,10 +275,11 @@ func getInfo(path string) (*MediaInfo, error) {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Audios: MapStream(mi.Streams, ffprobe.StreamAudio, func(stream *ffprobe.Stream, i uint32) Audio {
|
Audios: MapStream(mi.Streams, ffprobe.StreamAudio, func(stream *ffprobe.Stream, i uint32) Audio {
|
||||||
|
lang, _ := language.Parse(stream.Tags.Language)
|
||||||
return Audio{
|
return Audio{
|
||||||
Index: i,
|
Index: i,
|
||||||
Title: OrNull(stream.Tags.Title),
|
Title: OrNull(stream.Tags.Title),
|
||||||
Language: OrNull(stream.Tags.Language),
|
Language: NullIfUnd(lang.String()),
|
||||||
Codec: stream.CodecName,
|
Codec: stream.CodecName,
|
||||||
MimeCodec: GetMimeCodec(stream),
|
MimeCodec: GetMimeCodec(stream),
|
||||||
IsDefault: stream.Disposition.Default != 0,
|
IsDefault: stream.Disposition.Default != 0,
|
||||||
@ -283,10 +293,11 @@ func getInfo(path string) (*MediaInfo, error) {
|
|||||||
x := fmt.Sprintf("%s/%s/subtitle/%d.%s", Settings.RoutePrefix, base64.StdEncoding.EncodeToString([]byte(path)), i, *extension)
|
x := fmt.Sprintf("%s/%s/subtitle/%d.%s", Settings.RoutePrefix, base64.StdEncoding.EncodeToString([]byte(path)), i, *extension)
|
||||||
link = &x
|
link = &x
|
||||||
}
|
}
|
||||||
|
lang, _ := language.Parse(stream.Tags.Language)
|
||||||
return Subtitle{
|
return Subtitle{
|
||||||
Index: uint32(i),
|
Index: uint32(i),
|
||||||
Title: OrNull(stream.Tags.Title),
|
Title: OrNull(stream.Tags.Title),
|
||||||
Language: OrNull(stream.Tags.Language),
|
Language: NullIfUnd(lang.String()),
|
||||||
Codec: stream.CodecName,
|
Codec: stream.CodecName,
|
||||||
Extension: extension,
|
Extension: extension,
|
||||||
IsDefault: stream.Disposition.Default != 0,
|
IsDefault: stream.Disposition.Default != 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user