aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Youtube.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Youtube.cpp')
-rw-r--r--src/plugins/Youtube.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 1ca25a3..2418073 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -647,9 +647,33 @@ namespace QuickMedia {
return PluginResult::OK;
}
+ PluginResult YoutubeChannelPage::lazy_fetch(BodyItems &result_items) {
+ std::vector<CommandArg> additional_args = {
+ { "-H", "x-spf-referer: " + url },
+ { "-H", "x-youtube-client-name: 1" },
+ { "-H", "x-spf-previous: " + url },
+ { "-H", "x-youtube-client-version: 2.20200626.03.00" },
+ { "-H", "referer: " + url }
+ };
+
+ //std::vector<CommandArg> cookies = get_cookies();
+ //additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
+
+ Json::Value json_root;
+ DownloadResult result = download_json(json_root, url + "/videos?pbj=1", std::move(additional_args), true);
+ if(result != DownloadResult::OK) return download_result_to_plugin_result(result);
+ result_items = parse_channel_videos(json_root, continuation_token, added_videos);
+ return PluginResult::OK;
+ }
+
+ PluginResult YoutubeRelatedVideosPage::submit(const std::string&, const std::string&, std::vector<Tab> &result_tabs) {
+ result_tabs.push_back(Tab{nullptr, std::make_unique<YoutubeVideoPage>(program), nullptr});
+ return PluginResult::OK;
+ }
+
// TODO: Make this faster by using string search instead of parsing html.
// TODO: If the result is a play
- BodyItems YoutubeVideoPage::get_related_media(const std::string &url) {
+ BodyItems YoutubeVideoPage::get_related_media(const std::string &url, std::string &channel_url) {
BodyItems result_items;
std::string modified_url = remove_index_from_playlist_url(url);
@@ -677,6 +701,18 @@ namespace QuickMedia {
if(!json_item.isObject())
continue;
+ if(channel_url.empty()) {
+ const Json::Value &player_response_json = json_item["playerResponse"];
+ if(player_response_json.isObject()) {
+ const Json::Value &video_details_json = player_response_json["videoDetails"];
+ if(video_details_json.isObject()) {
+ const Json::Value &channel_id_json = video_details_json["channelId"];
+ if(channel_id_json.isString())
+ channel_url = "https://www.youtube.com/channel/" + channel_id_json.asString();
+ }
+ }
+ }
+
const Json::Value &response_json = json_item["response"];
if(!response_json.isObject())
continue;
@@ -730,4 +766,17 @@ namespace QuickMedia {
return result_items;
}
+
+ std::unique_ptr<Page> YoutubeVideoPage::create_search_page(Program *program, int &search_delay) {
+ search_delay = 350;
+ return std::make_unique<YoutubeSearchPage>(program);
+ }
+
+ std::unique_ptr<RelatedVideosPage> YoutubeVideoPage::create_related_videos_page(Program *program, const std::string&, const std::string&) {
+ return std::make_unique<YoutubeRelatedVideosPage>(program);
+ }
+
+ std::unique_ptr<LazyFetchPage> YoutubeVideoPage::create_channels_page(Program *program, const std::string &channel_url) {
+ return std::make_unique<YoutubeChannelPage>(program, channel_url, "", "Channel videos");
+ }
} \ No newline at end of file