aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
parent3e55199544908a8026b4fe621b2b6af7770ce4a4 (diff)
Temporary fix soundcloud download by using youtube-dl
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp15
-rw-r--r--src/plugins/Soundcloud.cpp38
2 files changed, 49 insertions, 4 deletions
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