diff --git a/shell.nix b/shell.nix index 62457365..6af174cf 100644 --- a/shell.nix +++ b/shell.nix @@ -36,6 +36,7 @@ in postgresql_15 pgformatter biome + go-migrate ]; DOTNET_ROOT = "${dotnet}"; diff --git a/transcoder/migrations/000001_init_db.down.sql b/transcoder/migrations/000001_init_db.down.sql new file mode 100644 index 00000000..e69de29b diff --git a/transcoder/migrations/000001_init_db.up.sql b/transcoder/migrations/000001_init_db.up.sql new file mode 100644 index 00000000..d182de68 --- /dev/null +++ b/transcoder/migrations/000001_init_db.up.sql @@ -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; diff --git a/transcoder/src/info.go b/transcoder/src/info.go index eea3b6b2..a8480fab 100644 --- a/transcoder/src/info.go +++ b/transcoder/src/info.go @@ -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 { diff --git a/transcoder/utils.go b/transcoder/utils.go index cd88c545..a143cd78 100644 --- a/transcoder/utils.go +++ b/transcoder/utils.go @@ -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 {