fix(route): telegram channel videos (#9087)

This commit is contained in:
Ethan Shen 2022-02-13 21:43:08 +08:00 committed by GitHub
parent 6f8f2ce0a5
commit 0fd9f29832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -1,6 +1,8 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const username = ctx.params.username;
@ -127,15 +129,17 @@ module.exports = async (ctx) => {
let messageVideos = '';
if (item.find('.tgme_widget_message_video_player').length) {
item.find('.tgme_widget_message_video_player').each(function () {
messageVideos += `<video src="${$(this).find('.tgme_widget_message_video').attr('src')}"
controls="controls"
poster="${
$(this)
.find('.tgme_widget_message_video_thumb')
.css('background-image')
.match(/url\('(.*)'\)/)[1]
}"
style="width: 100%"></video>`;
const source = $(this).find('.tgme_widget_message_video').attr('src');
if (source) {
const poster = $(this)
.find('.tgme_widget_message_video_thumb')
.css('background-image')
.match(/url\('(.*)'\)/)[1];
messageVideos += art(path.join(__dirname, 'templates/video.art'), {
source,
poster,
});
}
});
}
return messageVideos;

View File

@ -0,0 +1,5 @@
{{ if source }}
<video src="{{ source }}" controls="controls" poster="{{ poster }}" style="width: 100%"></video>`
{{ else }}
<b>Media is too big</b>
{{ /if }}