Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let QMPlay2 handle youtube:XXYYZZ URIs #619

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ if(WIN32)
target_link_libraries(${PROJECT_NAME} Qt5::WinExtras winmm)
elseif(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/macOS/BundleInfo.plist.in")
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/macOS/BundleInfo.plist.in"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.zaps166.${PROJECT_NAME}")
target_link_libraries(${PROJECT_NAME} ${APPKIT_LIBRARY} ${IOKIT_LIBRARY})
endif()
if(USE_TAGLIB AND (NOT WIN32 OR CMAKE_HOST_WIN32))
Expand Down
2 changes: 1 addition & 1 deletion src/gui/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static QCommandLineParser *createCmdParser(bool descriptions)
}
static QString fileArg(const QString &arg)
{
if (!arg.contains("://"))
if (!arg.contains("://") && !arg.startsWith("youtube:"))
{
const QFileInfo argInfo(arg);
if (!argInfo.isAbsolute())
Expand Down
4 changes: 3 additions & 1 deletion src/gui/MainWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,9 @@ bool MainWidget::eventFilter(QObject *obj, QEvent *event)
#ifdef Q_OS_MACOS
else if (event->type() == QEvent::FileOpen)
{
filesToAdd.append(((QFileOpenEvent *)event)->file());
auto url = ((QFileOpenEvent *)event)->url();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add auto fileOpenEvent = (QFileOpenEvent *)event; and use it?

filesToAdd.append(url.scheme() == "file" ? ((QFileOpenEvent *)event)->file()
: Functions::maybeExtensionAddress(url.url()));
fileOpenTimer.start(10);
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions src/gui/Unix/QMPlay2_youtube.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Exec=QMPlay2 --show %u
Icon=QMPlay2
Name=Play youtube:VID URI in QMPlay2
StartupNotify=false
Type=Application
Categories=Qt;AudioVideo;Player;Audio;Video;
MimeType=x-scheme-handler/youtube;
NoDisplay=true
11 changes: 11 additions & 0 deletions src/gui/macOS/BundleInfo.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@
<string>Viewer</string>
</dict>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>YouTube video ID</string>
<key>CFBundleURLSchemes</key>
<array>
<string>youtube</string>
</array>
</dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
Expand Down
27 changes: 22 additions & 5 deletions src/qmplay2/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,30 @@ QStringList Functions::getUrlsFromMimeData(const QMimeData *mimeData, const bool

QString Functions::maybeExtensionAddress(const QString &url)
{
for (const QMPlay2Extensions *QMPlay2Ext : QMPlay2Extensions::QMPlay2ExtensionsList())
if (url.startsWith("youtube:"))
{
const QString prefix = QMPlay2Ext->matchAddress(url);
if (!prefix.isEmpty())
return prefix + "://{" + url + "}";
// we want to support both youtube:vID and youtube://vID but the latter form
// is often passed to us as "youtube://vid" (vID interpreted as the remote host).
// So we also support the full URI form with an empty host string and strip
// the leading '/' from the path to recover the intact vID. This implementation
// also supports youtube:/vID as a side effect ... why not!
auto vid = url.mid(8);
while (vid.at(0) == '/')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crash if vid is empty string.

Btw. do we really need the youtube:/ (single slash) ? 😄

{
vid.remove(0, 1);
}
return maybeExtensionAddress("http://www.youtube.com/watch?v=" + vid);
}
else
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else not needed - previous block of code returns - no need to add indentation and else.

{
for (const QMPlay2Extensions *QMPlay2Ext : QMPlay2Extensions::QMPlay2ExtensionsList())
{
const QString prefix = QMPlay2Ext->matchAddress(url);
if (!prefix.isEmpty())
return prefix + "://{" + url + "}";
}
return url;
}
return url;
}

bool Functions::splitPrefixAndUrlIfHasPluginPrefix(const QString &entireUrl, QString *addressPrefixName, QString *url, QString *param)
Expand Down