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.cpp79
1 files changed, 41 insertions, 38 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index ed30aec..d9d9239 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -472,11 +472,37 @@ R"END(
return "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
}
+ static std::string cpn;
+
+ static bool generate_random_characters(char *buffer, int buffer_size, const char *alphabet, size_t alphabet_size) {
+ int fd = open("/dev/urandom", O_RDONLY);
+ if(fd == -1) {
+ perror("/dev/urandom");
+ return false;
+ }
+
+ if(read(fd, buffer, buffer_size) < buffer_size) {
+ fprintf(stderr, "Failed to read %d bytes from /dev/urandom\n", buffer_size);
+ close(fd);
+ return false;
+ }
+
+ for(int i = 0; i < buffer_size; ++i) {
+ unsigned char c = *(unsigned char*)&buffer[i];
+ buffer[i] = alphabet[c % alphabet_size];
+ }
+ close(fd);
+ return true;
+ }
+
static std::vector<CommandArg> get_cookies() {
std::lock_guard<std::mutex> lock(cookies_mutex);
if(cookies_filepath.empty()) {
YoutubeSignatureDecryptor::get_instance();
+ cpn.resize(16);
+ generate_random_characters(cpn.data(), cpn.size(), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_", 64);
+
Path cookies_filepath_p;
if(get_cookies_filepath(cookies_filepath_p, "youtube") != 0) {
show_notification("QuickMedia", "Failed to create youtube cookies file", Urgency::CRITICAL);
@@ -1331,14 +1357,20 @@ R"END(
std::unordered_set<std::string> channel_ids;
std::string subscriptions_str;
- if(file_get_content(subscriptions_path, subscriptions_str) == 0) {
- string_split(subscriptions_str, '\n', [&channel_ids](const char *str, size_t size) {
- std::string line(str, size);
- line = strip(line);
- if(!line.empty())
- channel_ids.insert(std::move(line));
- return true;
- });
+ FileType file_type = get_file_type(subscriptions_path);
+ if(file_type == FileType::REGULAR) {
+ if(file_get_content(subscriptions_path, subscriptions_str) == 0) {
+ string_split(subscriptions_str, '\n', [&channel_ids](const char *str, size_t size) {
+ std::string line(str, size);
+ line = strip(line);
+ if(!line.empty())
+ channel_ids.insert(std::move(line));
+ return true;
+ });
+ } else {
+ show_notification("QuickMedia", "Failed to read " + subscriptions_path.data, Urgency::CRITICAL);
+ abort();
+ }
}
auto it = channel_ids.find(channel_id);
@@ -2044,27 +2076,6 @@ R"END(
return PluginResult::OK;
}
- static bool generate_random_characters(char *buffer, int buffer_size, const char *alphabet, size_t alphabet_size) {
- int fd = open("/dev/urandom", O_RDONLY);
- if(fd == -1) {
- perror("/dev/urandom");
- return false;
- }
-
- if(read(fd, buffer, buffer_size) < buffer_size) {
- fprintf(stderr, "Failed to read %d bytes from /dev/urandom\n", buffer_size);
- close(fd);
- return false;
- }
-
- for(int i = 0; i < buffer_size; ++i) {
- unsigned char c = *(unsigned char*)&buffer[i];
- buffer[i] = alphabet[c % alphabet_size];
- }
- close(fd);
- return true;
- }
-
void YoutubeVideoPage::mark_watched() {
if(playback_url.empty()) {
fprintf(stderr, "Failed to mark video as watched because playback_url is empty\n");
@@ -2079,10 +2090,6 @@ R"END(
std::vector<CommandArg> cookies = get_cookies();
additional_args.insert(additional_args.end(), cookies.begin(), cookies.end());
- std::string cpn;
- cpn.resize(16);
- generate_random_characters(cpn.data(), cpn.size(), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_", 64);
-
std::string response;
DownloadResult download_result = download_to_string(playback_url + "&ver=2&cpn=" + cpn, response, std::move(additional_args), true);
if(download_result != DownloadResult::OK) {
@@ -2106,12 +2113,8 @@ R"END(
if(cipher_params.empty() || url.empty())
return false;
- std::string cpn;
- cpn.resize(16);
- generate_random_characters(cpn.data(), cpn.size(), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_", 64);
-
std::string url_decoded = url_param_decode(url);
- url_decoded += "&alr=yes&cver=2.20210615.01.00&altitags=395,394&cpn=" + cpn;
+ url_decoded += "&alr=yes&cver=2.20210615.01.00&cpn=" + cpn;
const std::string &s = cipher_params["s"];
const std::string &sp = cipher_params["sp"];