Skip to content

Commit

Permalink
Chat: Support open UGC video from share message
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Jan 8, 2025
1 parent 4014a5c commit ca1b802
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions wiliwili/include/utils/activity_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class Intent {
public:
// 开启各类视频
static void openAV(const std::string& avid, uint64_t cid = 0, int progress = -1);
static void openBV(const std::string& bvid, uint64_t cid = 0, int progress = -1);
static void openSeasonBySeasonId(uint64_t seasonId, int progress = -1);
static void openSeasonByEpId(uint64_t epId, int progress = -1);
Expand Down
18 changes: 17 additions & 1 deletion wiliwili/source/fragment/inbox_chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <algorithm>

#include "fragment/inbox_chat.hpp"

#include <utils/activity_helper.hpp>

#include "view/inbox_msg_card.hpp"
#include "view/custom_button.hpp"
#include "utils/number_helper.hpp"
Expand Down Expand Up @@ -62,7 +65,20 @@ class DataSourceMsgList : public RecyclingGridDataSource {

size_t getItemCount() override { return list.size(); }

void onItemSelected(RecyclingGrid* recycler, size_t index) override {}
void onItemSelected(RecyclingGrid* recycler, size_t index) override {
auto & r = this->list[index];
int source{};
if (r.content.at("source").is_number_integer())
source = r.content.at("source").get<int>();
if (r.msg_type == 7 && source == 5) {
// UGC video
std::string avid;
if (r.content.at("id").is_string())
avid = r.content.at("id").get<std::string>();
if (!avid.empty())
Intent::openAV(avid);
}
}

bool appendData(const bilibili::InboxMessageResultWrapper& result) {
bool skip_all = true;
Expand Down
27 changes: 27 additions & 0 deletions wiliwili/source/utils/activity_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@

#include "presenter/video_detail.hpp"

void Intent::openAV(const std::string& avid, uint64_t cid, int progress) {
// av to bv
// Based on https://github.com/bolanxian/metadata-fetcher/blob/master/src/utils/bv-encode.ts
constexpr int BASE = 58;
constexpr int64_t MAX = 1LL << 51;
constexpr int64_t XOR = 0x1552356C4CDB;
const std::string table = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf";
int64_t tmp = std::stoll(avid, nullptr, 10);
if (tmp < 0 || tmp >= MAX)
return;
tmp = (tmp | MAX) ^ XOR;
std::string x = "0000000000";
int i = 0;
while (i < x.length()) {
x[i++] = table[tmp % BASE];
tmp /= BASE;
}
if (tmp > 0)
return;
std::string bvid = "BV1000000000";
const int map[] = {2, 4, 6, 5, 7, 3, 8, 1, 0};
for (size_t j = 0; j < 9; j++) {
bvid[j + 3] = x[map[j]];
}
openBV(bvid, cid, progress);
}

void Intent::openBV(const std::string& bvid, uint64_t cid, int progress) {
auto activity = new PlayerActivity(bvid, cid, progress);
brls::Application::pushActivity(activity, brls::TransitionAnimation::NONE);
Expand Down

0 comments on commit ca1b802

Please sign in to comment.