Add support for mp4 videos
This commit is contained in:
@@ -111,26 +111,28 @@ proc parseConversation*(node: XmlNode): Conversation =
|
||||
result.replies.add parseTweets(thread)
|
||||
|
||||
proc parseVideo*(node: JsonNode): Video =
|
||||
let track = node{"track"}
|
||||
let contentType = track["contentType"].to(string)
|
||||
let
|
||||
track = node{"track"}
|
||||
cType = track["contentType"].to(string)
|
||||
pType = track["playbackType"].to(string)
|
||||
|
||||
case contentType
|
||||
case cType
|
||||
of "media_entity":
|
||||
result = Video(
|
||||
contentType: m3u8,
|
||||
thumb: node["posterImage"].to(string),
|
||||
id: track["contentId"].to(string),
|
||||
length: track["durationMs"].to(int),
|
||||
playbackType: if "mp4" in pType: mp4 else: m3u8,
|
||||
contentId: track["contentId"].to(string),
|
||||
durationMs: track["durationMs"].to(int),
|
||||
views: track["viewCount"].to(string),
|
||||
url: track["playbackUrl"].to(string),
|
||||
available: track{"mediaAvailability"}["status"].to(string) == "available"
|
||||
)
|
||||
of "vmap":
|
||||
result = Video(
|
||||
contentType: vmap,
|
||||
thumb: node["posterImage"].to(string),
|
||||
url: track["vmapUrl"].to(string),
|
||||
length: track["durationMs"].to(int),
|
||||
playbackType: vmap,
|
||||
durationMs: track["durationMs"].to(int),
|
||||
url: track["vmapUrl"].to(string)
|
||||
)
|
||||
else:
|
||||
echo "Can't parse video of type ", contentType
|
||||
echo "Can't parse video of type ", cType
|
||||
|
||||
result.thumb = node["posterImage"].to(string)
|
||||
|
||||
@@ -32,15 +32,15 @@ db("cache.db", "", "", ""):
|
||||
|
||||
type
|
||||
VideoType* = enum
|
||||
vmap, m3u8
|
||||
vmap, m3u8, mp4
|
||||
|
||||
Video* = object
|
||||
contentType*: VideoType
|
||||
contentId*: string
|
||||
playbackType*: VideoType
|
||||
durationMs*: int
|
||||
url*: string
|
||||
thumb*: string
|
||||
id*: string
|
||||
views*: string
|
||||
length*: int
|
||||
available*: bool
|
||||
|
||||
Gif* = object
|
||||
|
||||
@@ -88,12 +88,19 @@
|
||||
#
|
||||
#proc renderVideo(video: Video): string =
|
||||
<div class="attachments">
|
||||
<div class="gallery-row" style="max-height: unset;">
|
||||
<div class="attachment image">
|
||||
<div class="gallery-video">
|
||||
<div class="attachment video-container">
|
||||
#case video.playbackType
|
||||
#of mp4:
|
||||
<video poster=${video.thumb.getSigUrl("pic")} controls>
|
||||
<source src=${video.url.getSigUrl("video")} type="video/mp4">
|
||||
</video>
|
||||
#of m3u8, vmap:
|
||||
<video poster=${video.thumb.getSigUrl("pic")} autoplay muted loop></video>
|
||||
<div class="video-overlay">
|
||||
<p>Video playback not supported</p>
|
||||
</div>
|
||||
#end case
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user