aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-13 17:20:47 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-13 17:20:47 +0100
commit2079ac8649a160b53f9f4772290bf1171dd8ed6a (patch)
treec59c43163fcb2150475b554164dce8ccd0db2367
parent3e55199544908a8026b4fe621b2b6af7770ce4a4 (diff)
Temporary fix soundcloud download by using youtube-dl
-rw-r--r--TODO4
-rw-r--r--plugins/Soundcloud.hpp6
-rw-r--r--src/QuickMedia.cpp15
-rw-r--r--src/plugins/Soundcloud.cpp38
4 files changed, 57 insertions, 6 deletions
diff --git a/TODO b/TODO
index b7b15e1..984d467 100644
--- a/TODO
+++ b/TODO
@@ -204,4 +204,6 @@ Allow specifying start/end range for video/music downloads.
Limit text input length for 4chan posts to the server limit.
Allow creating a new thread on 4chan.
Add flag to quickmedia to use svp, by making svp use the same input ipc socket as quickmedia (and load the svp script manually).
-Support directly going to a youtube channel for a url. This is helpful for opening channel urls directly with quickmedia and also going to another channel from a youtube description. \ No newline at end of file
+Support directly going to a youtube channel for a url. This is helpful for opening channel urls directly with quickmedia and also going to another channel from a youtube description.
+Support downloading soundcloud/youtube playlists.
+Support downloading .m3u8 files, such as soundcloud music without using youtube-dl. \ No newline at end of file
diff --git a/plugins/Soundcloud.hpp b/plugins/Soundcloud.hpp
index eeb1f46..6f96481 100644
--- a/plugins/Soundcloud.hpp
+++ b/plugins/Soundcloud.hpp
@@ -58,10 +58,14 @@ namespace QuickMedia {
class SoundcloudAudioPage : public VideoPage {
public:
- SoundcloudAudioPage(Program *program, const std::string &url) : VideoPage(program, url) {}
+ SoundcloudAudioPage(Program *program, const std::string &url, std::string permalink_url) : VideoPage(program, url), permalink_url(std::move(permalink_url)) {}
const char* get_title() const override { return ""; }
bool autoplay_next_item() override { return true; }
std::string url_get_playable_url(const std::string &url) override;
+ std::string get_download_url(int max_height) override;
bool video_should_be_skipped(const std::string &url) override { return url == "track" || url.find("/stream/users/") != std::string::npos; }
+ private:
+ // TODO: Remove when youtube-dl is no longer required to download music
+ std::string permalink_url;
};
} \ No newline at end of file
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index a1320e0..69252fa 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2559,8 +2559,18 @@ namespace QuickMedia {
return false;
}
+ // TODO: Remove when youtube-dl is no longer required to download soundcloud music
+ static bool is_soundcloud(const std::string &url) {
+ return url.find("soundcloud.com") != std::string::npos;
+ }
+
static bool url_should_download_with_youtube_dl(const std::string &url) {
- return url.find("pornhub.com") != std::string::npos || url.find("xhamster.com") != std::string::npos || url.find("spankbang.com") != std::string::npos || url.find("xvideos.com") != std::string::npos;
+ return url.find("pornhub.com") != std::string::npos
+ || url.find("xhamster.com") != std::string::npos
+ || url.find("spankbang.com") != std::string::npos
+ || url.find("xvideos.com") != std::string::npos
+ // TODO: Remove when youtube-dl is no longer required to download soundcloud music
+ || is_soundcloud(url);
}
void Program::video_page_download_video(const std::string &url, sf::WindowHandle video_player_window) {
@@ -2568,6 +2578,9 @@ namespace QuickMedia {
std::string video_id;
separate_audio_option |= youtube_url_extract_id(url, video_id);
+ if(is_soundcloud(url))
+ separate_audio_option = false;
+
if(!separate_audio_option) {
download_async_gui(url, file_manager_start_dir.string(), no_video);
return;
diff --git a/src/plugins/Soundcloud.cpp b/src/plugins/Soundcloud.cpp
index ffd202c..676db3a 100644
--- a/src/plugins/Soundcloud.cpp
+++ b/src/plugins/Soundcloud.cpp
@@ -11,6 +11,12 @@
namespace QuickMedia {
static std::string client_id;
+ // Temporary download workaround using youtube-dl. TODO: Remove this and download .m3u8 files directly
+ class SoundcloudTrack : public BodyItemExtra {
+ public:
+ std::string permalink_url;
+ };
+
class SoundcloudPlaylist : public BodyItemExtra {
public:
BodyItems tracks;
@@ -88,9 +94,19 @@ namespace QuickMedia {
}
const Json::Value &media_json = item_json["media"];
- if(media_json.isObject())
+ if(media_json.isObject()) {
body_item->url = get_best_transcoding_audio_url(media_json);
+ if(!body_item->url.empty()) {
+ const Json::Value &permalink_url = item_json["permalink_url"];
+ if(permalink_url.isString()) {
+ auto track = std::make_shared<SoundcloudTrack>();
+ track->permalink_url = permalink_url.asString();
+ body_item->extra = std::move(track);
+ }
+ }
+ }
+ std::string first_track_artwork_url;
bool is_playlist = false;
if(body_item->url.empty()) {
const Json::Value &tracks_json = item_json["tracks"];
@@ -102,6 +118,8 @@ namespace QuickMedia {
auto track = parse_collection_item(track_json);
if(track) {
+ if(first_track_artwork_url.empty())
+ first_track_artwork_url = track->thumbnail_url;
playlist->tracks.push_back(std::move(track));
} else {
const Json::Value &track_id_json = track_json["id"];
@@ -129,7 +147,7 @@ namespace QuickMedia {
const Json::Value &artwork_url_json = item_json["artwork_url"];
const Json::Value &avatar_url_json = item_json["avatar_url"];
if(artwork_url_json.isString()) {
- // For larger thumbnails
+ // For larger thumbnails. TODO: Use this when upscaling ui
/*
if(strstr(artwork_url_json.asCString(), "-large") != 0) {
std::string artwork_url = artwork_url_json.asString();
@@ -151,6 +169,10 @@ namespace QuickMedia {
body_item->thumbnail_size.x = 100;
body_item->thumbnail_size.y = 100;
body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE;
+ } else if(!first_track_artwork_url.empty()) {
+ body_item->thumbnail_url = std::move(first_track_artwork_url);
+ body_item->thumbnail_size.x = 100;
+ body_item->thumbnail_size.y = 100;
} else {
body_item->thumbnail_size.x = 100;
body_item->thumbnail_size.y = 100;
@@ -252,7 +274,13 @@ namespace QuickMedia {
if(!url_json.isString())
return PluginResult::ERR;
- result_tabs.push_back(Tab{nullptr, std::make_unique<SoundcloudAudioPage>(program, url_json.asString()), nullptr});
+ // TODO: Remove when youtube-dl is no longer required to download music
+ std::string permalink_url;
+ SoundcloudTrack *track = static_cast<SoundcloudTrack*>(submit_body_item->extra.get());
+ if(track)
+ permalink_url = track->permalink_url;
+
+ result_tabs.push_back(Tab{nullptr, std::make_unique<SoundcloudAudioPage>(program, url_json.asString(), std::move(permalink_url)), nullptr});
}
return PluginResult::OK;
@@ -457,4 +485,8 @@ namespace QuickMedia {
return url_json.asString();
}
+
+ std::string SoundcloudAudioPage::get_download_url(int) {
+ return permalink_url;
+ }
} \ No newline at end of file