From 0fd9f29832d3de48618b4fe1a4c0996fe68b2e19 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 13 Feb 2022 21:43:08 +0800 Subject: [PATCH] fix(route): telegram channel videos (#9087) --- lib/v2/telegram/channel.js | 22 +++++++++++++--------- lib/v2/telegram/templates/video.art | 5 +++++ 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 lib/v2/telegram/templates/video.art diff --git a/lib/v2/telegram/channel.js b/lib/v2/telegram/channel.js index 06bf33e17d..8280411834 100644 --- a/lib/v2/telegram/channel.js +++ b/lib/v2/telegram/channel.js @@ -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 += ``; + 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; diff --git a/lib/v2/telegram/templates/video.art b/lib/v2/telegram/templates/video.art new file mode 100644 index 0000000000..9fc08e5561 --- /dev/null +++ b/lib/v2/telegram/templates/video.art @@ -0,0 +1,5 @@ +{{ if source }} +` +{{ else }} +Media is too big +{{ /if }} \ No newline at end of file