From e58fccafeaae8781800c3a829ea7960ed144c4c6 Mon Sep 17 00:00:00 2001 From: xfangfang <2553041586@qq.com> Date: Tue, 25 Jun 2024 15:01:09 +0800 Subject: [PATCH] SearchActivity: Display video duration in the bottom right corner --- wiliwili/include/fragment/search_tab.hpp | 5 +++-- wiliwili/include/utils/number_helper.hpp | 4 ++++ wiliwili/source/utils/number_helper.cpp | 13 +++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/wiliwili/include/fragment/search_tab.hpp b/wiliwili/include/fragment/search_tab.hpp index 59a9055c..1bf29b68 100644 --- a/wiliwili/include/fragment/search_tab.hpp +++ b/wiliwili/include/fragment/search_tab.hpp @@ -29,14 +29,15 @@ typedef brls::Event UpdateSearchEvent; class DataSourceSearchVideoList : public RecyclingGridDataSource { public: - DataSourceSearchVideoList(bilibili::VideoItemSearchListResult result) : list(std::move(result)) {} + explicit DataSourceSearchVideoList(bilibili::VideoItemSearchListResult result) : list(std::move(result)) {} RecyclingGridItem* cellForRow(RecyclingGrid* recycler, size_t index) override { //从缓存列表中取出 或者 新生成一个表单项 RecyclingGridItemVideoCard* item = (RecyclingGridItemVideoCard*)recycler->dequeueReusableCell("Cell"); bilibili::VideoItemSearchResult& r = this->list[index]; - item->setCard(r.cover + ImageHelper::h_ext, r.title, r.subtitle, r.pubdate, r.play, r.danmaku, ""); + item->setCard(r.cover + ImageHelper::h_ext, r.title, r.subtitle, r.pubdate, r.play, r.danmaku, + wiliwili::uglyString2Time(r.rightBottomBadge)); return item; } diff --git a/wiliwili/include/utils/number_helper.hpp b/wiliwili/include/utils/number_helper.hpp index 4909b74f..87d84076 100644 --- a/wiliwili/include/utils/number_helper.hpp +++ b/wiliwili/include/utils/number_helper.hpp @@ -38,6 +38,10 @@ std::string getRandomHex(int length, bool lowerCase = true); //4180 => 01:09:40 std::string sec2Time(size_t t); +// 我不知道为什么B站要返回一个字符串来显示视频的长度,然后在前端把这个字符串转换成更好看的时间,这真的很蠢 +// 120:12 => 02:00:12 +std::string uglyString2Time(const std::string& str); + // 100 => 0:01:40 // 4180 => 1:09:40 std::string sec2TimeDLNA(size_t t); diff --git a/wiliwili/source/utils/number_helper.cpp b/wiliwili/source/utils/number_helper.cpp index 393c874f..7bbcd312 100644 --- a/wiliwili/source/utils/number_helper.cpp +++ b/wiliwili/source/utils/number_helper.cpp @@ -96,6 +96,19 @@ std::string wiliwili::sec2Time(size_t t) { return wiliwili::pre0(hour, 2) + ":" + wiliwili::pre0(minute, 2) + ":" + wiliwili::pre0(sec, 2); } +std::string wiliwili::uglyString2Time(const std::string& str) { + if(str.empty()) return ""; + auto res = pystring::split(str, ":"); + if (res.size() != 2) return str; + try { + int min = std::stoi(res[0]); + int sec = std::stoi(res[1]); + return wiliwili::sec2Time(min * 60 + sec); + } catch (...) { + return str; + } +} + std::string wiliwili::sec2TimeDLNA(size_t t) { size_t hour = t / 3600; size_t minute = t / 60 % 60;