Skip to content

Commit

Permalink
feat(media-go): add transcodedurl field to get transcoded hls stream
Browse files Browse the repository at this point in the history
  • Loading branch information
ananyo141 committed Mar 16, 2024
1 parent 40ff0f7 commit 3d954f1
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 34 deletions.
32 changes: 18 additions & 14 deletions media-handler/db/video_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"log"
"path/filepath"
"time"

"media-handler/graph/model"
Expand Down Expand Up @@ -105,16 +106,18 @@ func (db *DB) CreateVideo(video model.CreateVideoInput, source string, userid in
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
timeCreated := time.Now()
transcodedPath := "/transcoded-bucket/hls_encoded/" + filepath.Base(source) + "/playlist.m3u8"
insertedVideo, err := videoCollec.InsertOne(ctx,
bson.M{
"title": video.Title,
"description": video.Description,
"userId": userid,
"source": source,
"likes": []int{},
"comments": []model.Comment{},
"createdAt": timeCreated,
"updatedAt": timeCreated,
"title": video.Title,
"description": video.Description,
"userId": userid,
"source": source,
"transcodedUrl": transcodedPath,
"likes": []int{},
"comments": []model.Comment{},
"createdAt": timeCreated,
"updatedAt": timeCreated,
})

if err != nil {
Expand All @@ -124,12 +127,13 @@ func (db *DB) CreateVideo(video model.CreateVideoInput, source string, userid in
insertedID := insertedVideo.InsertedID.(primitive.ObjectID).Hex()
// FIXME: use a struct to avoid repeating the same code
returnVideo := model.Video{ID: insertedID,
Title: video.Title,
Description: video.Description,
UserID: userid,
Source: source,
CreatedAt: time.Now(),
UpdatedAt: time.Now()}
Title: video.Title,
Description: video.Description,
UserID: userid,
Source: source,
TranscodedURL: &transcodedPath,
CreatedAt: time.Now(),
UpdatedAt: time.Now()}
return &returnVideo, err
}

Expand Down
83 changes: 73 additions & 10 deletions media-handler/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions media-handler/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions media-handler/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Video {
title: String!
description: String!
source: String!
transcodedUrl: String
userId: Int!
user: User
likes: [Int!]!
Expand Down
1 change: 1 addition & 0 deletions media-handler/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d954f1

Please sign in to comment.