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

Allow external applications to add downloads #628

Closed
d-k-bo opened this issue Oct 18, 2023 · 16 comments · Fixed by #640 or #657
Closed

Allow external applications to add downloads #628

d-k-bo opened this issue Oct 18, 2023 · 16 comments · Fixed by #640 or #657
Labels
feature New feature or request in-beta This issue is fixed in a beta version
Milestone

Comments

@d-k-bo
Copy link

d-k-bo commented Oct 18, 2023

I am working on Televido, an application to access media from German public broadcasting services. I want to offer users the ability to download shows. Since some channels need a more advanced downloader such as yt-dlp, I think it would be the best to rely on Parabolic if it is installed. I can image that there are many other projects with similar needs.


I propose that Parabolic supports opening URLs via the Open method of the org.freedesktop.Application interface. Calling this method should start Parabolic and open the “Add Download” dialog with the “Media URL” field prefilled.

Currently, this method call isn't handled and throws an error:

GDBus.Error:org.freedesktop.DBus.Error.NotSupported: Application does not open files

I think this could be implemented by adding a handler for the GApplication::open signal and setting the G_APPLICATION_HANDLES_OPEN flag. I guess that this would also enable the option to supply the URL as a command line argument.


For reference, some video players support starting playback like this. E.g. when you have Celluloid installed and open D-Spy, you can play a video by passing (['https://youtu.be/8eXj97stbG8'], {}) as a parameter to the org.freedesktop.Application.Open call.

@nlogozzo nlogozzo added this to the V2023.10.0 milestone Oct 18, 2023
@nlogozzo nlogozzo added the feature New feature or request label Oct 18, 2023
@nlogozzo
Copy link
Member

Hi! This sounds like a great idea :)

I'll make it so Parabolic can accept URLs in the command-line args (which is what the open flag relies on) which will open the app with the Add Download Dialog open and the URL already validated.

@d-k-bo
Copy link
Author

d-k-bo commented Nov 8, 2023

Nice to see that it has been implemented. Thanks!

I will look into integrating it into my application soon(-ish).

@nlogozzo
Copy link
Member

nlogozzo commented Nov 8, 2023

Nice to see that it has been implemented. Thanks!

I will look into integrating it into my application soon(-ish).

No worries. Should have a beta release by the end of this week that you can install through flatpak and ensure it works correctly with your app. Will let you know when it's out!

@nlogozzo nlogozzo added the in-beta This issue is fixed in a beta version label Nov 11, 2023
@nlogozzo
Copy link
Member

https://github.com/NickvisionApps/Parabolic/releases/tag/2023.11.0-beta2

Will be available via flathub-beta within the hour!

@d-k-bo
Copy link
Author

d-k-bo commented Nov 13, 2023

Thanks for working on this. While opening a URL using the command line works flawlessly, DBus activation does not yet seem to work.

I noticed 2 problems:


When using the org.freedesktop.Application.Open method, the DBus service crashes.

Example:

#!/usr/bin/env python3

import dbus

if __name__ == "__main__":
    bus = dbus.SessionBus()
    proxy = bus.get_object(
        "org.nickvision.tubeconverter", "/org/nickvision/tubeconverter"
    )
    open = proxy.get_dbus_method("Open", "org.freedesktop.Application")
    open(["https://youtu.be/8eXj97stbG8"], {})

Output of /usr/bin/flatpak run --branch=beta --arch=x86_64 --command=/app/bin/org.nickvision.tubeconverter org.nickvision.tubeconverter --gapplication-service (which is also executed by the DBus service)

UnhandledException - unhandled exception: System.InvalidCastException: Unable to cast object of type 'System.IntPtr' to type 'Gio.File[]'.
   at GObject.Value.Extract[T]()
   at Gio.Application.OpenSignalArgs.get_Files()
   at NickvisionTubeConverter.GNOME.Program.OnOpen(Application sender, OpenSignalArgs e) in /run/build/org.nickvision.tubeconverter/NickvisionTubeConverter.GNOME/Program.cs:line 122
   at GObject.Signal`2.<>c__DisplayClass11_0.<Connect>b__0(Value returnValue, Value[] parameters)
   at GObject.Closure.InternalCallback(IntPtr closure, IntPtr returnValuePtr, UInt32 nParamValues, ValueData[] paramValuesData, IntPtr invocationHint, IntPtr userData)

Unfortunately, I don't know enough about C# and Gir.Core to debug the root cause of this.


I noticed that when I start Parabolic with --gapplication-service, it already activates the application (which results in a window being opened). AFAICT, other apps run silently in the background in this case — until they are either activated via DBus or a timeout passed.

I am not sure how the command line flag is handled internally, but it may be related to #91. I am uncertain how much this issue really matters.

@nlogozzo nlogozzo reopened this Nov 13, 2023
@nlogozzo
Copy link
Member

Ah I think I know the issue...Will fix, thank you!

@nlogozzo
Copy link
Member

Could you install the flatpak file from this build: https://github.com/NickvisionApps/Parabolic/actions/runs/6852129882 and run the app to test it.

Make sure you have both the stable and beta builds uninstalled otherwise dbus might trigger the wrong build:

flatpak uninstall org.nickvision.tubeconverter//stable 
flatpak uninstall
org.nickvision.tubeconverter//beta
flatpak uninstall org.nickvision.tubeconverter//master #if you've ever installed a .flatpak file version before

@d-k-bo
Copy link
Author

d-k-bo commented Nov 13, 2023

The second problem is now fixed!

Unfortunately, flatpak run org.nickvision.tubeconverter https://youtu.be/8eXj97stbG8 now results in the same error as calling the Open method :/

UnhandledException - unhandled exception: System.InvalidCastException: Unable to cast object of type 'System.IntPtr' to type 'Gio.File[]'.
   at GObject.Value.Extract[T]()
   at Gio.Application.OpenSignalArgs.get_Files()
   at NickvisionTubeConverter.GNOME.Program.OnOpen(Application sender, OpenSignalArgs e) in /run/build/org.nickvision.tubeconverter/NickvisionTubeConverter.GNOME/Program.cs:line 128
   at GObject.Signal`2.<>c__DisplayClass11_0.<Connect>b__0(Value returnValue, Value[] parameters)
   at GObject.Closure.InternalCallback(IntPtr closure, IntPtr returnValuePtr, UInt32 nParamValues, ValueData[] paramValuesData, IntPtr invocationHint, IntPtr userData)

@nlogozzo
Copy link
Member

@d-k-bo Ok could you try this build: https://github.com/NickvisionApps/Parabolic/actions/runs/6853398652

Remember to uninstall the old versions first.

It shouldn't crash anymore, and passing via command line should work again, but i don't know if it will actually open via dbus or not.

If dbus doesn't work, then I think it's an issue with the C# gtk bindings, but in that case I can use manual c calls and get it working.

@nlogozzo
Copy link
Member

nlogozzo commented Nov 14, 2023

@d-k-bo Any update with that build?

@d-k-bo
Copy link
Author

d-k-bo commented Nov 14, 2023

Sorry, I hadn't the time to look into it until now. (Again, thanks for investing your time into this feature!)

I just tested both builds. Opening a URL via the command line works fine again. Calling Open opens the main Parabolic video, but without opening the “Add Download” dialog (it behaves the same as calling the Activate method).

@nlogozzo
Copy link
Member

Alright, then I'll have to do manual C calls. Give me a few hours :)

@nlogozzo
Copy link
Member

@d-k-bo Ok this should be the one that works! CLI and DBus: https://github.com/NickvisionApps/Parabolic/actions/runs/6871301515

@d-k-bo
Copy link
Author

d-k-bo commented Nov 15, 2023

It works! 🥳️

Thank you very much!

@nlogozzo
Copy link
Member

It works! 🥳️

Thank you very much!

Glad to hear! Hope to have a stable release out by Friday/the beginning of next week.

@nlogozzo
Copy link
Member

https://github.com/NickvisionApps/Parabolic/releases/tag/2023.11.0-rc1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request in-beta This issue is fixed in a beta version
Projects
None yet
2 participants