-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add export subtitle route and basic video ui
- Loading branch information
1 parent
e12c0c3
commit bae8f4f
Showing
11 changed files
with
164 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package subtitle | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"connectrpc.com/connect" | ||
subtitle_proto "github.com/nandesh-dev/subtle/generated/proto/subtitle" | ||
"github.com/nandesh-dev/subtle/pkgs/db" | ||
"github.com/nandesh-dev/subtle/pkgs/srt" | ||
"github.com/nandesh-dev/subtle/pkgs/subtitle" | ||
) | ||
|
||
func (s ServiceHandler) ExportSubtitle(ctx context.Context, req *connect.Request[subtitle_proto.ExportSubtitleRequest]) (*connect.Response[subtitle_proto.ExportSubtitleResponse], error) { | ||
var subtitleEntry db.Subtitle | ||
if err := db.DB().Where(&db.Subtitle{ID: int(req.Msg.SubtitleId)}).Preload("Segments").First(&subtitleEntry).Error; err != nil { | ||
return nil, fmt.Errorf("Error getting subtitle entry from database: %v", err) | ||
} | ||
|
||
if req.Msg.ExportFormat != "srt" { | ||
return nil, fmt.Errorf("Invalid export format: %v", req.Msg.ExportFormat) | ||
} | ||
|
||
sub := subtitle.NewTextSubtitle() | ||
|
||
for _, segmentEntry := range subtitleEntry.Segments { | ||
sub.AddSegment(*subtitle.NewTextSegment(segmentEntry.StartTime, segmentEntry.EndTime, segmentEntry.Text)) | ||
} | ||
|
||
out := srt.EncodeSubtitle(*sub) | ||
|
||
path := filepath.Join(req.Msg.ExportDirectoryPath, req.Msg.ExportFilename+".srt") | ||
if err := os.WriteFile(path, []byte(out), 0644); err != nil { | ||
return nil, fmt.Errorf("Error writting file to disk: %v", err) | ||
} | ||
|
||
return &connect.Response[subtitle_proto.ExportSubtitleResponse]{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package subtitle | ||
|
||
import ( | ||
"context" | ||
|
||
"connectrpc.com/connect" | ||
subtitle_proto "github.com/nandesh-dev/subtle/generated/proto/subtitle" | ||
) | ||
|
||
func (s ServiceHandler) GetAvailableExportFormats(ctx context.Context, req *connect.Request[subtitle_proto.GetAvailableExportFormatsRequest]) (*connect.Response[subtitle_proto.GetAvailableExportFormatsResponse], error) { | ||
res := subtitle_proto.GetAvailableExportFormatsResponse{ | ||
Formats: []string{"srt"}, | ||
} | ||
return connect.NewResponse(&res), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package subtitle | ||
|
||
import "github.com/nandesh-dev/subtle/generated/proto/subtitle/subtitleconnect" | ||
|
||
type ServiceHandler struct { | ||
subtitleconnect.UnimplementedSubtitleServiceHandler | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
syntax = "proto3"; | ||
|
||
package subtitle; | ||
|
||
option go_package = "github.com/nandesh-dev/subtle/generated/proto/subtitle"; | ||
|
||
service SubtitleService { | ||
rpc GetAvailableExportFormats(GetAvailableExportFormatsRequest) returns (GetAvailableExportFormatsResponse); | ||
rpc ExportSubtitle(ExportSubtitleRequest) returns (ExportSubtitleResponse); | ||
} | ||
|
||
message GetAvailableExportFormatsRequest {} | ||
|
||
message GetAvailableExportFormatsResponse { | ||
repeated string formats = 1; | ||
} | ||
|
||
message Subtitle { | ||
int32 id = 1; | ||
|
||
string title = 2; | ||
string language = 3; | ||
|
||
bool importIsExternal = 4; | ||
string exportPath = 5; | ||
} | ||
|
||
message ExportSubtitleRequest { | ||
int32 subtitleId = 1; | ||
|
||
string exportDirectoryPath = 2; | ||
string exportFilename = 3; | ||
string exportFormat = 4; | ||
} | ||
|
||
message ExportSubtitleResponse {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters