mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-08 10:44:20 -04:00
Add audio bitrate and video is default in info
This commit is contained in:
parent
c0f8f22e6a
commit
7d3c73a1e9
@ -25,6 +25,7 @@ create table videos(
|
||||
width integer not null,
|
||||
height integer not null,
|
||||
bitrate integer not null,
|
||||
is_default boolean not null,
|
||||
|
||||
keyframes double precision[],
|
||||
|
||||
@ -38,6 +39,7 @@ create table audios(
|
||||
language varchar(256),
|
||||
codec varchar(256) not null,
|
||||
mime_codec varchar(256),
|
||||
bitrate integer not null,
|
||||
is_default boolean not null,
|
||||
|
||||
keyframes double precision[],
|
||||
|
@ -18,10 +18,10 @@ import (
|
||||
const InfoVersion = 1
|
||||
|
||||
type Versions struct {
|
||||
Info int32
|
||||
Extract int32
|
||||
Thumbs int32
|
||||
Keyframes int32
|
||||
Info int32 `json:"info"`
|
||||
Extract int32 `json:"extract"`
|
||||
Thumbs int32 `json:"thumbs"`
|
||||
Keyframes int32 `json:"keyframes"`
|
||||
}
|
||||
|
||||
type MediaInfo struct {
|
||||
@ -42,9 +42,6 @@ type MediaInfo struct {
|
||||
/// Version of the metadata. This can be used to invalidate older metadata from db if the extraction code has changed.
|
||||
Versions Versions `json:"versions"`
|
||||
|
||||
// TODO: remove this
|
||||
Video *Video
|
||||
|
||||
/// The list of videos if there are multiples.
|
||||
Videos []Video `json:"videos"`
|
||||
/// The list of audio tracks.
|
||||
@ -76,6 +73,8 @@ type Video struct {
|
||||
Height uint32 `json:"height"`
|
||||
/// The average bitrate of the video in bytes/s
|
||||
Bitrate uint32 `json:"bitrate"`
|
||||
/// Is this stream the default one of it's type?
|
||||
IsDefault bool `json:"isDefault"`
|
||||
|
||||
/// Keyframes of this video
|
||||
Keyframes *Keyframe `json:"-"`
|
||||
@ -92,6 +91,8 @@ type Audio struct {
|
||||
Codec string `json:"codec"`
|
||||
/// The codec of this stream (defined as the RFC 6381).
|
||||
MimeCodec *string `json:"mimeCodec"`
|
||||
/// The average bitrate of the audio in bytes/s
|
||||
Bitrate uint32 `json:"bitrate"`
|
||||
/// Is this stream the default one of it's type?
|
||||
IsDefault bool `json:"isDefault"`
|
||||
|
||||
@ -256,6 +257,7 @@ func RetriveMediaInfo(path string, sha string) (*MediaInfo, error) {
|
||||
// ffmpeg does not report bitrate in mkv files, fallback to bitrate of the whole container
|
||||
// (bigger than the result since it contains audio and other videos but better than nothing).
|
||||
Bitrate: ParseUint(cmp.Or(stream.BitRate, mi.Format.BitRate)),
|
||||
IsDefault: stream.Disposition.Default != 0,
|
||||
}
|
||||
}),
|
||||
Audios: MapStream(mi.Streams, ffprobe.StreamAudio, func(stream *ffprobe.Stream, i uint32) Audio {
|
||||
@ -266,6 +268,7 @@ func RetriveMediaInfo(path string, sha string) (*MediaInfo, error) {
|
||||
Language: NullIfUnd(lang.String()),
|
||||
Codec: stream.CodecName,
|
||||
MimeCodec: GetMimeCodec(stream),
|
||||
Bitrate: ParseUint(cmp.Or(stream.BitRate, mi.Format.BitRate)),
|
||||
IsDefault: stream.Disposition.Default != 0,
|
||||
}
|
||||
}),
|
||||
|
@ -117,7 +117,7 @@ func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, erro
|
||||
}
|
||||
|
||||
rows, err := s.database.Query(
|
||||
`select v.idx, v.title, v.language, v.codec, v.mime_codec, v.width, v.height, v.bitrate, v.keyframes
|
||||
`select v.idx, v.title, v.language, v.codec, v.mime_codec, v.width, v.height, v.bitrate, v.is_default, v.keyframes
|
||||
from videos as v where v.sha=$1`,
|
||||
sha,
|
||||
)
|
||||
@ -126,7 +126,7 @@ func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, erro
|
||||
}
|
||||
for rows.Next() {
|
||||
var v Video
|
||||
err := rows.Scan(&v.Index, &v.Title, &v.Language, &v.Codec, &v.MimeCodec, &v.Width, &v.Height, &v.Bitrate, &v.Keyframes)
|
||||
err := rows.Scan(&v.Index, &v.Title, &v.Language, &v.Codec, &v.MimeCodec, &v.Width, &v.Height, &v.Bitrate, &v.IsDefault, &v.Keyframes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -135,7 +135,7 @@ func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, erro
|
||||
}
|
||||
|
||||
rows, err = s.database.Query(
|
||||
`select a.idx, a.title, a.language, a.codec, a.mime_codec, a.is_default, a.keyframes
|
||||
`select a.idx, a.title, a.language, a.codec, a.mime_codec, a.bitrate, a.is_default, a.keyframes
|
||||
from audios as a where a.sha=$1`,
|
||||
sha,
|
||||
)
|
||||
@ -144,7 +144,7 @@ func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, erro
|
||||
}
|
||||
for rows.Next() {
|
||||
var a Audio
|
||||
err := rows.Scan(&a.Index, &a.Title, &a.Language, &a.Codec, &a.MimeCodec, &a.IsDefault, &a.Keyframes)
|
||||
err := rows.Scan(&a.Index, &a.Title, &a.Language, &a.Codec, &a.MimeCodec, &a.Bitrate, &a.IsDefault, &a.Keyframes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -232,8 +232,8 @@ func (s *MetadataService) storeFreshMetadata(path string, sha string) (*MediaInf
|
||||
).Scan(&ret.Versions.Extract, &ret.Versions.Thumbs, &ret.Versions.Keyframes)
|
||||
for _, v := range ret.Videos {
|
||||
tx.Exec(`
|
||||
insert into videos(sha, idx, title, language, codec, mime_codec, width, height, bitrate)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||
insert into videos(sha, idx, title, language, codec, mime_codec, width, height, is_default, bitrate)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
on conflict (sha, idx) do update set
|
||||
sha = excluded.sha,
|
||||
idx = excluded.idx,
|
||||
@ -243,15 +243,16 @@ func (s *MetadataService) storeFreshMetadata(path string, sha string) (*MediaInf
|
||||
mime_codec = excluded.mime_codec,
|
||||
width = excluded.width,
|
||||
height = excluded.height,
|
||||
is_default = excluded.is_default,
|
||||
bitrate = excluded.bitrate
|
||||
`,
|
||||
ret.Sha, v.Index, v.Title, v.Language, v.Codec, v.MimeCodec, v.Width, v.Height, v.Bitrate,
|
||||
ret.Sha, v.Index, v.Title, v.Language, v.Codec, v.MimeCodec, v.Width, v.Height, v.IsDefault, v.Bitrate,
|
||||
)
|
||||
}
|
||||
for _, a := range ret.Audios {
|
||||
tx.Exec(`
|
||||
insert into audios(sha, idx, title, language, codec, mime_codec, is_default)
|
||||
values ($1, $2, $3, $4, $5, $6, $7)
|
||||
insert into audios(sha, idx, title, language, codec, mime_codec, is_default, bitrate)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
on conflict (sha, idx) do update set
|
||||
sha = excluded.sha,
|
||||
idx = excluded.idx,
|
||||
@ -259,9 +260,10 @@ func (s *MetadataService) storeFreshMetadata(path string, sha string) (*MediaInf
|
||||
language = excluded.language,
|
||||
codec = excluded.codec,
|
||||
mime_codec = excluded.mime_codec,
|
||||
is_default = excluded.is_default
|
||||
is_default = excluded.is_default,
|
||||
bitrate = excluded.bitrate
|
||||
`,
|
||||
ret.Sha, a.Index, a.Title, a.Language, a.Codec, a.MimeCodec, a.IsDefault,
|
||||
ret.Sha, a.Index, a.Title, a.Language, a.Codec, a.MimeCodec, a.IsDefault, a.Bitrate,
|
||||
)
|
||||
}
|
||||
for _, s := range ret.Subtitles {
|
||||
|
Loading…
x
Reference in New Issue
Block a user