add support for video file
This commit is contained in:
+20
-5
@@ -20,7 +20,7 @@ except ImportError:
|
||||
css_compress = lambda x: x
|
||||
|
||||
from .msg import *
|
||||
from common.textutil import ensure_unicode
|
||||
from common.textutil import ensure_unicode, get_file_b64
|
||||
from common.progress import ProgressReporter
|
||||
from common.timer import timing
|
||||
from .smiley import SmileyProvider
|
||||
@@ -31,9 +31,13 @@ TEMPLATES_FILES = {TYPE_MSG: "TP_MSG",
|
||||
TYPE_SPEAK: "TP_SPEAK",
|
||||
TYPE_EMOJI: "TP_EMOJI",
|
||||
TYPE_CUSTOM_EMOJI: "TP_EMOJI",
|
||||
TYPE_LINK: "TP_MSG"}
|
||||
TEMPLATES = {k: ensure_unicode(open(os.path.join(STATIC_PATH, '{}.html'.format(v))).read())
|
||||
for k, v in TEMPLATES_FILES.items()}
|
||||
TYPE_LINK: "TP_MSG",
|
||||
TYPE_VIDEO_FILE: "TP_VIDEO_FILE"
|
||||
}
|
||||
TEMPLATES = {
|
||||
k: open(os.path.join(STATIC_PATH, '{}.html'.format(v))).read()
|
||||
for k, v in TEMPLATES_FILES.items()
|
||||
}
|
||||
|
||||
class HTMLRender(object):
|
||||
def __init__(self, parser, res=None):
|
||||
@@ -148,7 +152,18 @@ class HTMLRender(object):
|
||||
content = u'URL:<a target="_blank" href="{0}">{0}</a>'.format(url)
|
||||
format_dict['content'] = content
|
||||
return template.format(**format_dict)
|
||||
# TODO handle TYPE_VIDEO_FILE
|
||||
elif msg.type == TYPE_VIDEO_FILE:
|
||||
video = self.res.get_video(msg.imgPath)
|
||||
if video.endswith(".mp4"):
|
||||
video_str = get_file_b64(video)
|
||||
format_dict["video_str"] = video_str
|
||||
return template.format(**format_dict)
|
||||
elif video.endswith(".jpg"):
|
||||
# only has thumbnail
|
||||
image_str = get_file_b64(video)
|
||||
format_dict["img"] = (image_str, 'jpeg')
|
||||
return TEMPLATES[TYPE_IMG].format(**format_dict)
|
||||
return f"VIDEO FILE {msg.imgPath}"
|
||||
elif msg.type == TYPE_WX_VIDEO:
|
||||
# TODO: fetch video from resource
|
||||
return fallback()
|
||||
|
||||
+11
-1
@@ -25,6 +25,7 @@ INTERNAL_EMOJI_DIR = os.path.join(LIB_PATH, 'static', 'internal_emoji')
|
||||
VOICE_DIRNAME = 'voice2'
|
||||
IMG_DIRNAME = 'image2'
|
||||
EMOJI_DIRNAME = 'emoji'
|
||||
VIDEO_DIRNAME = 'video'
|
||||
|
||||
JPEG_QUALITY = 50
|
||||
|
||||
@@ -84,6 +85,7 @@ class Resource(object):
|
||||
self.img_dir = os.path.join(res_dir, IMG_DIRNAME)
|
||||
self.voice_dir = os.path.join(res_dir, VOICE_DIRNAME)
|
||||
self.emoji_dir = os.path.join(res_dir, EMOJI_DIRNAME)
|
||||
self.video_dir = os.path.join(res_dir, VIDEO_DIRNAME)
|
||||
self.avt_reader = AvatarReader(res_dir, avt_db)
|
||||
|
||||
def get_voice_filename(self, imgpath):
|
||||
@@ -171,7 +173,6 @@ class Resource(object):
|
||||
return (big[0], "")
|
||||
return (big[0], ths[0])
|
||||
|
||||
|
||||
def get_img(self, fnames):
|
||||
"""
|
||||
:params fnames: possible file paths
|
||||
@@ -258,3 +259,12 @@ class Resource(object):
|
||||
# first 1k in emoji is encrypted
|
||||
logger.warn("Cannot get emoji {} in {}".format(md5, group))
|
||||
return None, None
|
||||
|
||||
def get_video(self, videoid):
|
||||
video_file = os.path.join(self.video_dir, videoid + ".mp4")
|
||||
video_thumbnail_file = os.path.join(self.video_dir, videoid + ".jpg")
|
||||
if os.path.exists(video_file):
|
||||
return video_file
|
||||
elif os.path.exists(video_thumbnail_file):
|
||||
return video_thumbnail_file
|
||||
return ""
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<div class="chatItem {sender_label}">
|
||||
<div class="chatItemContent">
|
||||
<span class="avatar"></span>
|
||||
<div class="cloud cloudVideo">
|
||||
<div class="cloudPannel" title="{time}" {nickname}>
|
||||
<div class="cloudBody">
|
||||
<video controls width="300">
|
||||
<source type="video/mp4" src="data:video/mp4;base64,{video_str}" />
|
||||
</video>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user