Init first transcoder migration

This commit is contained in:
Zoe Roux 2024-07-15 12:17:21 +07:00
parent 605756a794
commit 5854c731a3
5 changed files with 24 additions and 5 deletions

View File

@ -36,6 +36,7 @@ in
postgresql_15
pgformatter
biome
go-migrate
];
DOTNET_ROOT = "${dotnet}";

View File

@ -0,0 +1,18 @@
begin;
create table if not exists info(
sha varchar(20) not null primary key,
path varchar(4096) not null unique,
extension varchar(256),
mime_codec varchar(1024),
size bigint not null,
duration real not null,
container varchar(256)
);
create table if not exists videos(
sha varchar(20) not null primary key,
)
commit;

View File

@ -30,7 +30,7 @@ type MediaInfo struct {
/// The whole mimetype (defined as the RFC 6381). ex: `video/mp4; codecs="avc1.640028, mp4a.40.2"`
MimeCodec *string `json:"mimeCodec"`
/// The file size of the video file.
Size uint64 `json:"size"`
Size int64 `json:"size"`
/// The length of the media in seconds.
Duration float32 `json:"duration"`
/// The container of the video file of this episode.
@ -129,8 +129,8 @@ func ParseUint(str string) uint32 {
return uint32(i)
}
func ParseUint64(str string) uint64 {
i, err := strconv.ParseUint(str, 10, 64)
func ParseInt64(str string) int64 {
i, err := strconv.ParseInt(str, 10, 64)
if err != nil {
println(str)
return 0
@ -260,7 +260,7 @@ func getInfo(path string) (*MediaInfo, error) {
Path: path,
// Remove leading .
Extension: filepath.Ext(path)[1:],
Size: ParseUint64(mi.Format.Size),
Size: ParseInt64(mi.Format.Size),
Duration: float32(mi.Format.DurationSeconds),
Container: OrNull(mi.Format.FormatName),
Videos: MapStream(mi.Streams, ffprobe.StreamVideo, func(stream *ffprobe.Stream, i uint32) Video {

View File

@ -52,7 +52,7 @@ func getHash(path string) (string, error) {
h.Write([]byte(path))
h.Write([]byte(info.ModTime().String()))
sha := hex.EncodeToString(h.Sum(nil))
return version + sha, nil
return sha, nil
}
func SanitizePath(path string) error {