Skip to content

Commit

Permalink
include images and videos in community posts
Browse files Browse the repository at this point in the history
  • Loading branch information
travv0 committed Apr 5, 2024
1 parent ea3aaf4 commit ed77b63
Showing 1 changed file with 49 additions and 6 deletions.
55 changes: 49 additions & 6 deletions Youtube.fs
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,55 @@ let getYoutubeUpdates () : string option list =
yield! result ]

type ContentText =
{ text: string }
{ text: string
url: string option }

static member Decoder =
Decode.map
(fun text -> { text = text })
Decode.map2
(fun text url -> { text = text; url = url })
(Decode.field "text" Decode.string)
(Decode.optional "url" Decode.string)

type Thumbnail =
{ url: string
width: int
height: int }

static member Decoder =
Decode.map3
(fun url width height ->
{ url = url
width = width
height = height })
(Decode.field "url" Decode.string)
(Decode.field "width" Decode.int)
(Decode.field "height" Decode.int)

type Image =
{ thumbnails: Thumbnail list }

static member Decoder =
Decode.map
(fun thumbnails -> { thumbnails = thumbnails })
(Decode.field "thumbnails" (Decode.list Thumbnail.Decoder))

type Community =
{ id: string
contentText: ContentText list }
contentText: ContentText list
videoId: string option
images: Image list }

static member Decoder =
Decode.map2
(fun id contentText -> { id = id; contentText = contentText })
Decode.map4
(fun id contentText videoId images ->
{ id = id
contentText = contentText
videoId = videoId
images = images })
(Decode.field "id" Decode.string)
(Decode.field "contentText" (Decode.list ContentText.Decoder))
(Decode.field "videoId" (Decode.option Decode.string))
(Decode.field "images" (Decode.list Image.Decoder))

type Channel =
{ id: string
Expand Down Expand Up @@ -261,6 +294,16 @@ let getCommunityUpdates () : string list =
+ (post.contentText
|> List.map (fun x -> x.text)
|> String.concat "")
+ (match post.videoId with
| Some videoId ->
$"\n\nhttps://www.youtube.com/watch?v=%s{videoId}"
| None -> "")
+ (post.images
|> List.map (fun i -> Seq.tryLast i.thumbnails)
|> List.choose id
|> List.map (fun t -> t.url)
|> List.map (fun url -> $"\n[Image]({url})")
|> String.concat "")
+ $"\n\nSee full post at https://www.youtube.com/post/%s{post.id}"

let postIds = channel.Community |> List.map (fun x -> x.id)
Expand Down

0 comments on commit ed77b63

Please sign in to comment.