mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 13:17:08 +02:00
feat: add support for Spotify links
Open `open.spotify.com` links in the desktop application
This commit is contained in:
parent
bfeb225bc2
commit
0cf36db010
3 changed files with 47 additions and 0 deletions
|
@ -17,6 +17,8 @@
|
|||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
||||
namespace AyuUrlHandlers
|
||||
{
|
||||
|
||||
|
@ -67,4 +69,39 @@ bool HandleAyu(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TryHandleSpotify(const QString& url)
|
||||
{
|
||||
if (!url.contains("spotify.com")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// docs on their url scheme
|
||||
// https://www.iana.org/assignments/uri-schemes/prov/spotify
|
||||
|
||||
using namespace qthelp;
|
||||
auto matchOptions = RegExOption::CaseInsensitive;
|
||||
// https://regex101.com/r/l4Ogzf/2
|
||||
auto match = regex_match(
|
||||
u"^(https?:\\/\\/)?([a-zA-Z0-9_]+)\\.spotify\\.com\\/(?<type>track|album|artist|user|playlist)\\/(?<identifier>[a-zA-Z0-9_\\/]+?)((\\?si=.+)?)$"_q,
|
||||
url,
|
||||
matchOptions);
|
||||
if (match) {
|
||||
const auto type = match->captured("type").toLower();
|
||||
const auto identifier = match->captured("identifier").replace("/", ":");
|
||||
|
||||
// '/' -> ':' for links like:
|
||||
// https://open.spotify.com/user/1185903410/playlist/6YAnJeVC7tgOiocOG23Dd
|
||||
// so it'll look like
|
||||
// spotify:user:1185903410:playlist:6YAnJeVC7tgOiocOG23Dd
|
||||
|
||||
const auto res = QString("spotify:%1:%2").arg(type).arg(identifier);
|
||||
|
||||
if (!res.isEmpty()) {
|
||||
return QDesktopServices::openUrl(QUrl(res));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,4 +24,6 @@ bool HandleAyu(
|
|||
const Match &match,
|
||||
const QVariant &context);
|
||||
|
||||
bool TryHandleSpotify(const QString& url);
|
||||
|
||||
}
|
|
@ -30,6 +30,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/window_session_controller.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
// AyuGram includes
|
||||
#include "ayu/ayu_url_handlers.h"
|
||||
|
||||
|
||||
namespace Core {
|
||||
namespace {
|
||||
|
||||
|
@ -234,6 +238,10 @@ bool UiIntegration::handleUrlClick(
|
|||
return true;
|
||||
}
|
||||
|
||||
if (AyuUrlHandlers::TryHandleSpotify(url)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto parsed = UrlForAutoLogin(url);
|
||||
const auto domain = DomainForAutoLogin(parsed);
|
||||
const auto skip = context.value<ClickHandlerContext>().skipBotAutoLogin;
|
||||
|
|
Loading…
Add table
Reference in a new issue