aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/Lbry.cpp47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/plugins/Lbry.cpp b/src/plugins/Lbry.cpp
index 1ce23c0..34ce982 100644
--- a/src/plugins/Lbry.cpp
+++ b/src/plugins/Lbry.cpp
@@ -8,6 +8,11 @@
// TODO: Images, music, regular files
namespace QuickMedia {
+ class LbryBodyItemData : public BodyItemExtra {
+ public:
+ std::string streaming_url;
+ };
+
static void *search_type_video = (void*)0;
static void *search_type_channel = (void*)1;
@@ -94,6 +99,9 @@ namespace QuickMedia {
if(!hash_json.isString() || !sd_hash_json.isString())
return nullptr;
+ auto extra = std::make_shared<LbryBodyItemData>();
+ extra->streaming_url = canonical_url_json.asString();
+ body_item->extra = std::move(extra);
body_item->url = "https://player.odycdn.com/api/v4/streams/tc/" + name_json.asString() + "/" + hash_json.asString() + "/" + sd_hash_json.asString() + "/master.m3u8";
body_item->userdata = search_type_video;
}
@@ -284,10 +292,12 @@ namespace QuickMedia {
}
PluginResult LbrySearchPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
- if(args.userdata == search_type_video)
- result_tabs.push_back(Tab{ nullptr, std::make_unique<LbryVideoPage>(program, args.title, args.url), nullptr });
- else if(args.userdata == search_type_channel)
+ if(args.userdata == search_type_video) {
+ const LbryBodyItemData *body_item_data = static_cast<const LbryBodyItemData*>(args.extra.get());
+ result_tabs.push_back(Tab{ nullptr, std::make_unique<LbryVideoPage>(program, args.title, args.url, body_item_data->streaming_url), nullptr });
+ } else if(args.userdata == search_type_channel) {
result_tabs.push_back(Tab{ create_body(false, true), std::make_unique<LbryChannelPage>(program, args.title, args.url), create_search_bar("Search...", 500) });
+ }
return PluginResult::OK;
}
@@ -355,7 +365,8 @@ namespace QuickMedia {
}
PluginResult LbryChannelPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
- result_tabs.push_back(Tab{ nullptr, std::make_unique<LbryVideoPage>(program, args.title, args.url), nullptr });
+ const LbryBodyItemData *body_item_data = static_cast<const LbryBodyItemData*>(args.extra.get());
+ result_tabs.push_back(Tab{ nullptr, std::make_unique<LbryVideoPage>(program, args.title, args.url, body_item_data->streaming_url), nullptr });
return PluginResult::OK;
}
@@ -363,13 +374,19 @@ namespace QuickMedia {
return get_page("", 0, result_items);
}
- static PluginResult video_get_stream_url(Page *page, const std::string &video_url, std::vector<M3U8Stream> &streams, std::string &err_str) {
-#if 0
+ static PluginResult video_get_stream_url(Page *page, const std::string &streaming_url, const std::string &video_url, std::vector<M3U8Stream> &streams, std::string &direct_video_url, std::string &err_str) {
+ std::string website_data;
+ DownloadResult result = download_to_string(video_url.c_str(), website_data, {}, true);
+ if(result == DownloadResult::OK) {
+ streams = m3u8_get_streams(website_data);
+ return PluginResult::OK;
+ }
+
std::string url = "https://api.na-backend.odysee.com/api/v1/proxy?m=get";
Json::Value request_params_json(Json::objectValue);
request_params_json["save_file"] = false;
- request_params_json["uri"] = video_url;
+ request_params_json["uri"] = streaming_url;
Json::Value request_json(Json::objectValue);
request_json["id"] = (int64_t)time(nullptr) * 1000;
@@ -406,16 +423,8 @@ namespace QuickMedia {
if(!streaming_url_json.isString())
return PluginResult::ERR;
- streaming_url = streaming_url_json.asString();
- return PluginResult::OK;
-#else
- std::string website_data;
- DownloadResult result = download_to_string(video_url.c_str(), website_data, {}, true);
- if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
-
- streams = m3u8_get_streams(website_data);
+ direct_video_url = streaming_url_json.asString();
return PluginResult::OK;
-#endif
}
// TODO: Support |max_height|. This can be done by gettin video source hash and checking for sd_hash and then resolution.
@@ -430,6 +439,9 @@ namespace QuickMedia {
has_embedded_audio = true;
ext = ".mp4"; // TODO: Check if this is always correct
+ if(!direct_video_url.empty())
+ return direct_video_url;
+
if(streams.empty())
return url;
@@ -461,9 +473,10 @@ namespace QuickMedia {
PluginResult LbryVideoPage::load(const SubmitArgs &args, VideoInfo &video_info, std::string &err_str) {
streams.clear();
+ direct_video_url.clear();
video_info.title = args.title;
//title = this->title;
video_info.duration = 0.0;
- return video_get_stream_url(this, url, streams, err_str);
+ return video_get_stream_url(this, streaming_url, url, streams, direct_video_url, err_str);
}
} \ No newline at end of file