diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-13 17:20:47 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-13 17:20:47 +0100 |
commit | 2079ac8649a160b53f9f4772290bf1171dd8ed6a (patch) | |
tree | c59c43163fcb2150475b554164dce8ccd0db2367 /src/plugins | |
parent | 3e55199544908a8026b4fe621b2b6af7770ce4a4 (diff) |
Temporary fix soundcloud download by using youtube-dl
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Soundcloud.cpp | 38 |
1 files changed, 35 insertions, 3 deletions
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 |