bluesky appview implementation using microcosm and other services server.reddwarf.app
appview bluesky reddwarf microcosm

PostView_Embed video

Changed files
+82 -16
cmd
appview
shims
lex
app
bsky
feed
defs
utils
+1
cmd/appview/main.go
··· 807 807 808 808 Code: https://tangled.org/whey.party/red-dwarf-server 809 809 Protocol: https://atproto.com 810 + Try it on: https://new.reddwarf.app 810 811 `) 811 812 }) 812 813 router_raw.Run(":7152")
+76 -16
shims/lex/app/bsky/feed/defs/embed.go
··· 41 41 return embedImage, nil 42 42 } 43 43 if feedPost.Embed.EmbedVideo != nil { 44 - return nil, nil 44 + //return nil, nil 45 + videocdn := "https://video.bsky.app" // todo move this 46 + embedVideo := EmbedVideoViewExtractor(ctx, aturi, feedPost.Embed.EmbedVideo, sl, cs, imgcdn, videocdn, viewer) 47 + return embedVideo, nil 45 48 //embedType = "EmbedVideo" 46 - return &appbsky.FeedDefs_PostView_Embed{ 47 - // EmbedImages_View *EmbedImages_View 48 - // EmbedVideo_View *EmbedVideo_View 49 - EmbedVideo_View: &appbsky.EmbedVideo_View{ 50 - // LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.embed.video#view"` 51 - // Alt *string `json:"alt,omitempty" cborgen:"alt,omitempty"` 52 - // AspectRatio *EmbedDefs_AspectRatio `json:"aspectRatio,omitempty" cborgen:"aspectRatio,omitempty"` 53 - // Cid string `json:"cid" cborgen:"cid"` 54 - // Playlist string `json:"playlist" cborgen:"playlist"` 55 - // Thumbnail *string `json:"thumbnail,omitempty" cborgen:"thumbnail,omitempty"` 56 - }, 57 - // EmbedExternal_View *EmbedExternal_View 58 - // EmbedRecord_View *EmbedRecord_View 59 - // EmbedRecordWithMedia_View *EmbedRecordWithMedia_View 60 - }, nil 49 + // return &appbsky.FeedDefs_PostView_Embed{ 50 + // // EmbedImages_View *EmbedImages_View 51 + // // EmbedVideo_View *EmbedVideo_View 52 + // EmbedVideo_View: &appbsky.EmbedVideo_View{ 53 + // // LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.embed.video#view"` 54 + // LexiconTypeID: "app.bsky.embed.video#view", 55 + // // Alt *string `json:"alt,omitempty" cborgen:"alt,omitempty"` 56 + // Alt: 57 + // // AspectRatio *EmbedDefs_AspectRatio `json:"aspectRatio,omitempty" cborgen:"aspectRatio,omitempty"` 58 + // // Cid string `json:"cid" cborgen:"cid"` 59 + // // Playlist string `json:"playlist" cborgen:"playlist"` 60 + // // Thumbnail *string `json:"thumbnail,omitempty" cborgen:"thumbnail,omitempty"` 61 + // }, 62 + // // EmbedExternal_View *EmbedExternal_View 63 + // // EmbedRecord_View *EmbedRecord_View 64 + // // EmbedRecordWithMedia_View *EmbedRecordWithMedia_View 65 + // }, nil 61 66 } 62 67 if feedPost.Embed.EmbedExternal != nil { 63 68 embedExternal := EmbedExternalViewExtractor(ctx, aturi, feedPost.Embed.EmbedExternal, sl, cs, imgcdn, viewer) ··· 156 161 } 157 162 } 158 163 if feedPost.Embed.EmbedRecordWithMedia.Media.EmbedVideo != nil { 164 + videocdn := "https://video.bsky.app" // todo move this 165 + embedVideo := EmbedVideoViewExtractor(ctx, aturi, feedPost.Embed.EmbedVideo, sl, cs, imgcdn, videocdn, viewer) 166 + embedmediaview = &appbsky.EmbedRecordWithMedia_View_Media{ 167 + // EmbedImages_View *EmbedImages_View 168 + // EmbedVideo_View *EmbedVideo_View 169 + EmbedVideo_View: embedVideo.EmbedVideo_View, 170 + // EmbedVideo_View: &appbsky.EmbedVideo_View{ 171 + 172 + // }, 173 + // EmbedExternal_View *EmbedExternal_View 174 + } 159 175 // // video extractor 160 176 // embedmediaview = &appbsky.EmbedRecordWithMedia_View_Media{ 161 177 // // EmbedImages_View *EmbedImages_View ··· 242 258 243 259 } 244 260 261 + func EmbedVideoViewExtractor(ctx context.Context, aturi syntax.ATURI, embedVideo *appbsky.EmbedVideo, sl *microcosm.MicrocosmClient, cs *microcosm.MicrocosmClient, imgcdn string, videocdn string, viewer *utils.DID) *appbsky.FeedDefs_PostView_Embed { 262 + // u := utils.MakeImageCDN(utils.DID(aturi.Authority().String()), imgcdn, "feed_thumbnail", rawimg.Image.Ref.String()) 263 + // feed_thumbnail = u 264 + // uf := utils.MakeImageCDN(utils.DID(aturi.Authority().String()), imgcdn, "feed_fullsize", rawimg.Image.Ref.String()) 265 + // feed_fullsize = uf 266 + /* 267 + uri at://did:plc:mdjhvva6vlrswsj26cftjttd/app.bsky.feed.post/3m7lci6jy4k2m 268 + video cid "bafkreifqh5647m6rsmuxpajitmbjigkg5xdfl6p4v4losks76w77vvtau4" 269 + playlist "https://video.bsky.app/watch/did%3Aplc%3Amdjhvva6vlrswsj26cftjttd/bafkreifqh5647m6rsmuxpajitmbjigkg5xdfl6p4v4losks76w77vvtau4/playlist.m3u8" 270 + {videocdn}/watch/{uri encoded did}/{video cid}/playlist.m3u8 271 + thumbnail "https://video.bsky.app/watch/did%3Aplc%3Amdjhvva6vlrswsj26cftjttd/bafkreifqh5647m6rsmuxpajitmbjigkg5xdfl6p4v4losks76w77vvtau4/thumbnail.jpg" 272 + {videocdn}/watch/{uri encoded did}/{video cid}/thumbnail.jpg 273 + */ 274 + playlist := utils.MakeVideoCDN(utils.DID(aturi.Authority().String()), videocdn, "playlist.m3u8", embedVideo.Video.Ref.String()) 275 + thumbnail := utils.MakeVideoCDN(utils.DID(aturi.Authority().String()), videocdn, "thumbnail.jpg", embedVideo.Video.Ref.String()) 276 + return &appbsky.FeedDefs_PostView_Embed{ 277 + // EmbedImages_View *EmbedImages_View 278 + // EmbedVideo_View *EmbedVideo_View 279 + EmbedVideo_View: &appbsky.EmbedVideo_View{ 280 + // LexiconTypeID string `json:"$type" cborgen:"$type,const=app.bsky.embed.video#view"` 281 + LexiconTypeID: "app.bsky.embed.video#view", 282 + // Alt *string `json:"alt,omitempty" cborgen:"alt,omitempty"` 283 + Alt: embedVideo.Alt, 284 + // AspectRatio *EmbedDefs_AspectRatio `json:"aspectRatio,omitempty" cborgen:"aspectRatio,omitempty"` 285 + AspectRatio: embedVideo.AspectRatio, 286 + // Cid string `json:"cid" cborgen:"cid"` 287 + Cid: embedVideo.Video.Ref.String(), 288 + // Playlist string `json:"playlist" cborgen:"playlist"` 289 + Playlist: playlist, 290 + // Thumbnail *string `json:"thumbnail,omitempty" cborgen:"thumbnail,omitempty"` 291 + Thumbnail: &thumbnail, 292 + }, 293 + // EmbedExternal_View *EmbedExternal_View 294 + // EmbedRecord_View *EmbedRecord_View 295 + // EmbedRecordWithMedia_View *EmbedRecordWithMedia_View 296 + } 297 + 298 + } 299 + 245 300 func EmbedExternalViewExtractor(ctx context.Context, aturi syntax.ATURI, embedExternal *appbsky.EmbedExternal, sl *microcosm.MicrocosmClient, cs *microcosm.MicrocosmClient, imgcdn string, viewer *utils.DID) *appbsky.FeedDefs_PostView_Embed { 246 301 // todo: gif embeds needs special handling i think? maybe? 247 302 //return nil, nil ··· 326 381 } 327 382 if postView.Embed.EmbedVideo_View != nil { 328 383 //has = "video" 384 + embeds = []*appbsky.EmbedRecord_ViewRecord_Embeds_Elem{ 385 + { 386 + EmbedVideo_View: postView.Embed.EmbedVideo_View, 387 + }, 388 + } 329 389 } 330 390 if postView.Embed.EmbedExternal_View != nil { 331 391 embeds = []*appbsky.EmbedRecord_ViewRecord_Embeds_Elem{
+5
shims/utils/utils.go
··· 39 39 func MakeImageCDN(did DID, imgcdn string, kind string, cid string) string { 40 40 return imgcdn + "/img/" + kind + "/plain/" + string(did) + "/" + cid + "@jpeg" 41 41 } 42 + 43 + func MakeVideoCDN(did DID, videocdn string, kind string, cid string) string { 44 + //{videocdn}/watch/{uri encoded did}/{video cid}/thumbnail.jpg 45 + return videocdn + "/watch/" + string(did) + "/" + cid + "/" + kind 46 + }