This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Konqueror - associciate magnet: links with a shell script?

Tags: None
(comma "," separated)
dfaure
KDE Developer
Posts
14
Karma
0
OS

Mon Oct 08, 2012 10:10 am
OK, so I tried this.
* ~/.local/share/applications/transmission-get.desktop
* /usr/local/bin/transmission-get.sh with this line: kdialog --msgbox "$0 $1 called" (and chmod a+x)
* A test HTML file with this line: <a href="magnet:?xt=urn:btih:foo">click me</a>
-> at this point, ktorrent still opens, when clicking on the link.
* Deleted $KDEDIR/share/kde4/services/magnet.protocol and /usr/share/kde4/services/magnet.protocol (I never used that anyway). Ran kbuildsycoca4.
-> works, now when I click on the link I get my kdialog msgbox.

(The bit about $KDEDIR above is because I use a self-compiled KDE, into my own prefix. But the files from /usr are visible too, due to XDG_DATA_DIRS containing both paths)

More generally, use kde4-config --path services to see all directories where protocol files are searched for, and more specifically run this command to find magnet.protocol files:
kde4-config --path services --locate magnet.protocol
User avatar
latebeat
Registered Member
Posts
70
Karma
0
What's the purpose of your script exactly? Do u have a centralized maching downing the downloading of all ur torrents.
I'm asking because if that's what you want, check out this chrome extension https://chrome.google.com/webstore/deta ... fdghcmenci
it worked out for me pretty well with almost 0 initial setup time
DrTwox
Registered Member
Posts
19
Karma
0

Re:

Tue Oct 09, 2012 10:05 pm
dfaure wrote:OK, so I tried this.
* ~/.local/share/applications/transmission-get.desktop
* /usr/local/bin/transmission-get.sh with this line: kdialog --msgbox "$0 $1 called" (and chmod a+x)
* A test HTML file with this line: <a href="magnet:?xt=urn:btih:foo">click me</a>
-> at this point, ktorrent still opens, when clicking on the link.
* Deleted $KDEDIR/share/kde4/services/magnet.protocol and /usr/share/kde4/services/magnet.protocol (I never used that anyway). Ran kbuildsycoca4.
-> works, now when I click on the link I get my kdialog msgbox.


I just tested this method (using kdialog) and I still get the same error. Can you please post the transmission-get.desktop file you created? Here's what mine looks like:

Code: Select all
[Desktop Entry]
Type=Application
Exec=/usr/local/bin/transmission-get.sh "%u"
Icon=kget
MimeType=x-scheme-handler/magnet;
NoDisplay=true
Name=transmission-get.sh


dfaure wrote: ....and more specifically run this command to find magnet.protocol files:
kde4-config --path services --locate magnet.protocol


I tested with that command. No magnet.protocol files found on the system.

latebeat wrote:What's the purpose of your script exactly? Do u have a centralized box downloading all ur torrents.

Yes, I have Transmission running in daemon mode on my firewall/router. Nothing against Chrome, but I'd rather stick with Konqueror :)
User avatar
latebeat
Registered Member
Posts
70
Karma
0

Re: Re:

Tue Oct 09, 2012 10:16 pm
DrTwox wrote:
dfaure wrote:Nothing against Chrome, but I'd rather stick with Konqueror :)


Konqueror really?
Not even rekonq?!
You're really old-school ;)
dfaure
KDE Developer
Posts
14
Karma
0
OS

Thu Oct 11, 2012 10:52 am
DrTwox wrote:I just tested this method (using kdialog) and I still get the same error. Can you please post the transmission-get.desktop file you created? Here's what mine looks like:

Code: Select all
[Desktop Entry]
Type=Application
Exec=/usr/local/bin/transmission-get.sh "%u"
Icon=kget
MimeType=x-scheme-handler/magnet;
NoDisplay=true
Name=transmission-get.sh


Exactly the same here. (Just without the double-quotes around %u, shouldn't matter though)

There must be some leftover on your system. I assume you tried `kbuildsycoca4 --no-incremental` already?

Otherwise, try as another user, or on another machine?
DrTwox
Registered Member
Posts
19
Karma
0
dfaure wrote:There must be some leftover on your system. I assume you tried `kbuildsycoca4 --no-incremental` already?

I have just run `kbuildsycoca4 --noincremental` then rebooted and ran it again just to be sure, but I still get the same error. If there is some leftover magnet.protocol file, I (using the find command) can't find it anywhere. There are also no files in either of the paths given by `kde4-config --path services` that even have the word 'magnet' in them.

So I followed your advice and set up a new user on this machine. I copied the transmission-get.desktop file to the new user's .local/share/applications/ directory, ran `kbuildsycoca4 --noincremental`, clicked on a maget link and it worked! What else could be leftover in my home directory that is causing it to fail in my account?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Please post the output of the following:
Code: Select all
find ~/.local/ ~/.config/ ~/.kde4/  -name "*.protocol"


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
DrTwox
Registered Member
Posts
19
Karma
0
Code: Select all
$ find ~/.local/ ~/.config/ ~/.kde4/  -name "*.protocol"
find: `/home/drtwox/.kde4/': No such file or directory

So I changed ~/.kde4 to ~/.kde
Code: Select all
$ find ~/.local/ ~/.config/ ~/.kde/  -name "*.protocol"
$

It finds no files at all.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
While outside KDE, please move ~/.local/share/mime elsewhere, and also erase /var/tmp/kdecache-$USER/.
If you have made any custom file associations, they will likely be lost in the process, but this will ensure that any old associations with the protocols are hopefully removed.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
DrTwox
Registered Member
Posts
19
Karma
0
Edit: Removed duplicate post.

Last edited by DrTwox on Fri Oct 19, 2012 11:26 pm, edited 1 time in total.
DrTwox
Registered Member
Posts
19
Karma
0
Thank you to each person who offered help with this. Before the last suggestion was posted I gave up and just did a fresh install of the new Kubuntu release and I have got it working, except with one minor annoyance! When clicking a magnet link, instead of just opening the link with my script, Konqueror prompts me with a dialog:

This untrusted page links to
magnet:?xt=urn:btih:XXXXXXXXXXX
Do you want to follow the link?
[Follow] [Cancel]

This dialog doesn't pop up when using ktorrent, so it must be possible to disable it? How?

Again, thank you to all who offered help and support! Very appreciated.
dfaure
KDE Developer
Posts
14
Karma
0
OS
Ouch. Tricky issue. KAuthorized::authorizeUrlAction looks at the "protocol class", and accepts :internet -> :internet, and warns for :internet -> :local. With this way of using the magnet protocol, we have no .protocol file anymore, so no associated class, so KAuthorized sees a redirection from :internet to ":" (empty), and warns.

The introduction of x-scheme-handler/protocol support comes from a freedesktop.org "standard", but the "protocol class" thing is KDE-specific, so obviously it wasn't taken into account in that standard.

OK, I know what the solution is: giving preference to x-scheme-handler apps over old-style exec=... in the protocol file, and this way we can keep the magnet.protocol file around, to provide such information.

Fixed in http://commits.kde.org/kdelibs/74047642 ... 6d43cd3a7f
(will be in 4.9.3)

Class=:internet has to be added to magnet.protocol, though... Done:
http://commits.kde.org/ktorrent/51bdf13 ... 4693d2aeae

Sounds like magnet.protocol should be moved to more centralized location, though...
DrTwox
Registered Member
Posts
19
Karma
0

Tue Oct 23, 2012 6:31 am
All I can say is: fantastic job and thank you!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]