{"id":1333,"date":"2012-01-24T23:39:24","date_gmt":"2012-01-24T21:39:24","guid":{"rendered":"http:\/\/www.void.gr\/kargig\/blog\/?p=1333"},"modified":"2012-10-08T21:13:24","modified_gmt":"2012-10-08T18:13:24","slug":"open-magnet-urls-with-xdg-open","status":"publish","type":"post","link":"https:\/\/www.void.gr\/kargig\/blog\/2012\/01\/24\/open-magnet-urls-with-xdg-open\/","title":{"rendered":"open magnet URLs with xdg-open"},"content":{"rendered":"<p>Browsers on Linux should use xdg-open to open URLs. From xdg-open&#8217;s description:<\/p>\n<blockquote><p>xdg-open opens a file or URL in the user&#8217;s preferred application. If a URL is<br \/>\nprovided the URL will be opened in the user&#8217;s preferred web browser. If a file<br \/>\nis provided the file will be opened in the preferred application for files of<br \/>\nthat type. xdg-open supports file, ftp, http and https URLs.<\/p><\/blockquote>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Magnet\">Magnet<\/a> is a new type of URLs that&#8217;s currently not supported by xdg-open. It&#8217;s very easy to add a quick hack to support it though. Just copy xdg-open to a local binary path (e.g \/usr\/local\/bin or preferably $HOME\/bin) and apply the following patch. Change <em>deluge<\/em> with your preferred torrent application.<\/p>\n<p><pre><code2>--- \/usr\/bin\/xdg-open&nbsp;&nbsp;2010-09-15 14:08:29.000000000 +0300\n+++ bin\/xdg-open&nbsp;&nbsp;2012-01-24 22:05:03.935338593 +0200\n@@ -437,6 +437,11 @@\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit_success\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi\n+&nbsp;&nbsp;&nbsp;&nbsp;elif (echo &quot;$1&quot; | grep -q &#039;^magnet:&#039;); then\n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deluge &quot;$1&quot; \n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if [ $? -eq 0 ]; then\n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit_success\n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi\n&nbsp;&nbsp;&nbsp;&nbsp; fi\n \n&nbsp;&nbsp;&nbsp;&nbsp; sensible-browser &quot;$1&quot;\n<\/code2><\/pre><\/p>\n<p>For those who don&#8217;t know how to patch a file, here it is in full: <a href=\"\/kargig\/blog\/wp-content\/xdg-open\">patched xdg-open to open magnet URLs<\/a><\/p>\n<p>Works fine on my Debian using <a href=\"https:\/\/www.google.com\/chrome\">Chrome<\/a> which properly uses xdg-open to handle URLs. <a href=\"http:\/\/www.mozilla.org\/en-US\/firefox\/\">Firefox<\/a> after version 3.5 became a piece of bloatware and it&#8217;s not possible to open magnet links using <em>about:config settings<\/em> or xdg-open. For <a href=\"http:\/\/www.opera.com\/\">Opera<\/a> just go to Settings->Preferences->Programs and add new protocol with name <em>magnet<\/em>. At <em>Open with other application<\/em>, use the path that you saved the patched xdg-open.<\/p>\n<p>Now go download some creative commons licensed files.<\/p>\n<p>*UPDATE*<br \/>\nPatch for latest xdg-utils (since some people complained that previous patch does not apply):<br \/>\n<pre><code2>\n\n--- xdg-open&nbsp;&nbsp;2012-02-18 14:22:48.058497027 +0200\n+++ xdg-open&nbsp;&nbsp;2012-02-18 14:24:04.326875223 +0200\n@@ -440,6 +440,11 @@\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit_success\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi\n+&nbsp;&nbsp;&nbsp;&nbsp;elif (echo &quot;$1&quot; | grep -q &#039;^magnet:&#039;); then\n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deluge &quot;$1&quot; \n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if [ $? -eq 0 ]; then\n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit_success\n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi\n&nbsp;&nbsp;&nbsp;&nbsp; fi\n \n&nbsp;&nbsp;&nbsp;&nbsp; IFS=&quot;:&quot;\n<\/code2><\/pre><\/p>\n<p>*UPDATE 2*<br \/>\nFor Firefox\/Iceweasel one can do the following:<br \/>\ngo to about:config and right-click. Then click on New->Boolean->network.protocol-handler.expose.magnet -> Value -> false<br \/>\nUpon the next click Firefox\/Iceweasel will ask you to choose a program to open magnet links, choose the patched xdg-open posted above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Browsers on Linux should use xdg-open to open URLs. From xdg-open&#8217;s description: xdg-open opens a file or URL in the user&#8217;s preferred application. If a URL is provided the URL will be opened in the user&#8217;s preferred web browser. If a file is provided the file will be opened in the preferred application for files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"footnotes":""},"categories":[5,3],"tags":[25,452,33,451,114,125,595,449,453,450,500],"class_list":["post-1333","post","type-post","status-publish","format-standard","hentry","category-internet","category-linux","tag-bash","tag-chrome","tag-debian","tag-deluge","tag-firefox","tag-iceweasel","tag-linux","tag-magnet","tag-opera","tag-torrent","tag-xdg"],"aioseo_notices":[],"views":85422,"_links":{"self":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/1333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/comments?post=1333"}],"version-history":[{"count":6,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/1333\/revisions"}],"predecessor-version":[{"id":1339,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/1333\/revisions\/1339"}],"wp:attachment":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/categories?post=1333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/tags?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}