How to open magnet torrent links from Firefox in rTorrent?












5















I am using the command-line torrent client rTorrent under Xenial Xerus and I would like to:




  1. Find and click on a magnet torrent link with Firefox

  2. Have the magnet link opened automatically in rTorrent and start downloading


I believe a script is needed to be called from within Firefox, but the writing of such a script has so far defeated me...










share|improve this question

























  • Indeed this is what I am doing at the moment but I am after a more automated approach...

    – andrew.46
    Jun 15 '16 at 0:29













  • Check support.mozilla.org/en-US/questions/1012864

    – eri0o
    Oct 15 '17 at 2:32
















5















I am using the command-line torrent client rTorrent under Xenial Xerus and I would like to:




  1. Find and click on a magnet torrent link with Firefox

  2. Have the magnet link opened automatically in rTorrent and start downloading


I believe a script is needed to be called from within Firefox, but the writing of such a script has so far defeated me...










share|improve this question

























  • Indeed this is what I am doing at the moment but I am after a more automated approach...

    – andrew.46
    Jun 15 '16 at 0:29













  • Check support.mozilla.org/en-US/questions/1012864

    – eri0o
    Oct 15 '17 at 2:32














5












5








5








I am using the command-line torrent client rTorrent under Xenial Xerus and I would like to:




  1. Find and click on a magnet torrent link with Firefox

  2. Have the magnet link opened automatically in rTorrent and start downloading


I believe a script is needed to be called from within Firefox, but the writing of such a script has so far defeated me...










share|improve this question
















I am using the command-line torrent client rTorrent under Xenial Xerus and I would like to:




  1. Find and click on a magnet torrent link with Firefox

  2. Have the magnet link opened automatically in rTorrent and start downloading


I believe a script is needed to be called from within Firefox, but the writing of such a script has so far defeated me...







16.04 command-line scripts firefox rtorrent






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 9 '18 at 22:28









Matthias Braun

257310




257310










asked Jun 14 '16 at 22:50









andrew.46andrew.46

21.4k1469147




21.4k1469147













  • Indeed this is what I am doing at the moment but I am after a more automated approach...

    – andrew.46
    Jun 15 '16 at 0:29













  • Check support.mozilla.org/en-US/questions/1012864

    – eri0o
    Oct 15 '17 at 2:32



















  • Indeed this is what I am doing at the moment but I am after a more automated approach...

    – andrew.46
    Jun 15 '16 at 0:29













  • Check support.mozilla.org/en-US/questions/1012864

    – eri0o
    Oct 15 '17 at 2:32

















Indeed this is what I am doing at the moment but I am after a more automated approach...

– andrew.46
Jun 15 '16 at 0:29







Indeed this is what I am doing at the moment but I am after a more automated approach...

– andrew.46
Jun 15 '16 at 0:29















Check support.mozilla.org/en-US/questions/1012864

– eri0o
Oct 15 '17 at 2:32





Check support.mozilla.org/en-US/questions/1012864

– eri0o
Oct 15 '17 at 2:32










2 Answers
2






active

oldest

votes


















5





+50









The problems usually lie with mime type and default handlers.



Firstly, have you changed Firefox's about:config settings? ie:



network.protocol-handler.expose.magnet -> false


and reset other options
as per this Firefox deluge Q&A.



Have you set up rTorrent to watch any particular directory?



FILE: ~/.rtorrent.rc



# Maximum and minimum number of peers to connect to per torrent.
min_peers = 50
max_peers = 80

# Maximum number of simultanious uploads per torrent.
max_uploads = 5

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 50

# Default directory to save the downloaded torrents.
directory = $HOME/torrents/downloads

# Watch a directory for new torrents
# SET your watch directory here --v
schedule = watch_directory,5,5,$HOME/torrents/watch/*.torrent

port_range = 60125-64125
port_random = yes
dht = auto

# UDP port to use for DHT.
dht_port = 63425

# Enable peer exchange (for torrents not marked private)
peer_exchange = yes

# Check hash for finished torrents.
check_hash = yes

encryption = allow_incoming,try_outgoing ,enable_retry


Then it is a simple matter of "save as" into $HOME/torrents/watch.



Change $HOME/torrents/watch to whatever torrents subfolder you use, or at least $HOME to /home/username



Create a file and add the following script:



FILE: maglink-rtorrent.sh



#!/bin/bash

cd $HOME/torrents/watch # set your watch directory here
[[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"


Don't forget to make it executable



chmod +x maglink-rtorrent.sh


This also offers the ability to download from terminal by:



cd $HOME/torrents/watch
./maglink-rtorrent.sh "MAGNET-LINK-HERE"


Further awesome Service Tips and rTorrent setup options here.



Futher credits:




  • magnet links and command line 1

  • magnet links and command line 2


Update 2:



If not using rTorrent, but kTorrent or qBittorent, then this following is the way to get that running:



# check defaults
xdg-mime query default x-scheme-handler/magnet
gvfs-mime --query x-scheme-handler/magnet

# set defaults
xdg-mime default qBittorent.desktop x-scheme-handler/magnet
gvfs-mime --set x-scheme-handler/magnet qBittorrent.desktop


There's a further setting (from memory) for whether you require commandline.



For rTorrent though, this link is the FlexGet rTorrent Magnet URI Handler



Full information here.



Hope this helps.






share|improve this answer





















  • 2





    I have managed to crack this one on my own using: paxmontem.blogspot.com.au/2012/03/… but I would be more than happy to award the bonus if you can bend your answer this way...

    – andrew.46
    Jul 8 '16 at 5:32











  • Ha! I was going to add that script to my answer, but chose not to for it being a terminal option - where I thought you were after a pure browser one-click option. link

    – greg.arnott
    Jul 8 '16 at 6:05











  • Not so much the terminal script on the bottom of your link. Looks like the Browser can be set to pass the magnet link to a script to clean it up and pass it to the rtorrent watch directory. I used this page: paxmontem.blogspot.com.au/2012/03/… but it all feeds off the ARCH wiki page...

    – andrew.46
    Jul 8 '16 at 6:18



















1














The following script is a spin on Max Gonzih's code that works both with regular .torrent files and magnet links:



#!/bin/bash

torrent_file_or_magnet_link="$1"

# Edit rtorrent.rc to automatically start downloads when a .torrent file
# appears in this directory.
cd "$HOME/.rtorrent/watch/start/"

# XT stands for "exact topic".
# BTIH is the BitTorrent info hash:
# https://en.wikipedia.org/wiki/Magnet_URI_scheme#BitTorrent_info_hash_(BTIH)
# This is the hex-encoded SHA-1 hash of the torrent file info section
magnet_regex="xt=urn:btih:([^&/]+)"
if [[ "$torrent_file_or_magnet_link" =~ $magnet_regex ]]; then
torrent_hash=${BASH_REMATCH[1]};
magnet_link_length=${#torrent_file_or_magnet_link}
# To conform with the bencode encoding, the magnet link's number of characters
# must be part of the torrent file, otherwise rTorrent can't read it.
# Same for the "e" at the end.
# See https://en.wikipedia.org/wiki/Bencode
torrent_file_content="d10:magnet-uri${magnet_link_length}:${torrent_file_or_magnet_link}e"

# Note that rTorrent will read this torrent file, start downloading
# the file and then remove the torrent file
echo "$torrent_file_content" > "$torrent_hash.torrent"
else
cp "$torrent_file_or_magnet_link" .
fi


You can use this in a script (let's call it pass_to_rtorrent.sh) and have Firefox pass the torrent file or magnet link to the script:



Firefox rTorrent screenshot



Make sure the script is executable: chmod +x pass_to_rtorrent.sh






share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f787100%2fhow-to-open-magnet-torrent-links-from-firefox-in-rtorrent%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5





    +50









    The problems usually lie with mime type and default handlers.



    Firstly, have you changed Firefox's about:config settings? ie:



    network.protocol-handler.expose.magnet -> false


    and reset other options
    as per this Firefox deluge Q&A.



    Have you set up rTorrent to watch any particular directory?



    FILE: ~/.rtorrent.rc



    # Maximum and minimum number of peers to connect to per torrent.
    min_peers = 50
    max_peers = 80

    # Maximum number of simultanious uploads per torrent.
    max_uploads = 5

    # Global upload and download rate in KiB. "0" for unlimited.
    download_rate = 0
    upload_rate = 50

    # Default directory to save the downloaded torrents.
    directory = $HOME/torrents/downloads

    # Watch a directory for new torrents
    # SET your watch directory here --v
    schedule = watch_directory,5,5,$HOME/torrents/watch/*.torrent

    port_range = 60125-64125
    port_random = yes
    dht = auto

    # UDP port to use for DHT.
    dht_port = 63425

    # Enable peer exchange (for torrents not marked private)
    peer_exchange = yes

    # Check hash for finished torrents.
    check_hash = yes

    encryption = allow_incoming,try_outgoing ,enable_retry


    Then it is a simple matter of "save as" into $HOME/torrents/watch.



    Change $HOME/torrents/watch to whatever torrents subfolder you use, or at least $HOME to /home/username



    Create a file and add the following script:



    FILE: maglink-rtorrent.sh



    #!/bin/bash

    cd $HOME/torrents/watch # set your watch directory here
    [[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
    echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"


    Don't forget to make it executable



    chmod +x maglink-rtorrent.sh


    This also offers the ability to download from terminal by:



    cd $HOME/torrents/watch
    ./maglink-rtorrent.sh "MAGNET-LINK-HERE"


    Further awesome Service Tips and rTorrent setup options here.



    Futher credits:




    • magnet links and command line 1

    • magnet links and command line 2


    Update 2:



    If not using rTorrent, but kTorrent or qBittorent, then this following is the way to get that running:



    # check defaults
    xdg-mime query default x-scheme-handler/magnet
    gvfs-mime --query x-scheme-handler/magnet

    # set defaults
    xdg-mime default qBittorent.desktop x-scheme-handler/magnet
    gvfs-mime --set x-scheme-handler/magnet qBittorrent.desktop


    There's a further setting (from memory) for whether you require commandline.



    For rTorrent though, this link is the FlexGet rTorrent Magnet URI Handler



    Full information here.



    Hope this helps.






    share|improve this answer





















    • 2





      I have managed to crack this one on my own using: paxmontem.blogspot.com.au/2012/03/… but I would be more than happy to award the bonus if you can bend your answer this way...

      – andrew.46
      Jul 8 '16 at 5:32











    • Ha! I was going to add that script to my answer, but chose not to for it being a terminal option - where I thought you were after a pure browser one-click option. link

      – greg.arnott
      Jul 8 '16 at 6:05











    • Not so much the terminal script on the bottom of your link. Looks like the Browser can be set to pass the magnet link to a script to clean it up and pass it to the rtorrent watch directory. I used this page: paxmontem.blogspot.com.au/2012/03/… but it all feeds off the ARCH wiki page...

      – andrew.46
      Jul 8 '16 at 6:18
















    5





    +50









    The problems usually lie with mime type and default handlers.



    Firstly, have you changed Firefox's about:config settings? ie:



    network.protocol-handler.expose.magnet -> false


    and reset other options
    as per this Firefox deluge Q&A.



    Have you set up rTorrent to watch any particular directory?



    FILE: ~/.rtorrent.rc



    # Maximum and minimum number of peers to connect to per torrent.
    min_peers = 50
    max_peers = 80

    # Maximum number of simultanious uploads per torrent.
    max_uploads = 5

    # Global upload and download rate in KiB. "0" for unlimited.
    download_rate = 0
    upload_rate = 50

    # Default directory to save the downloaded torrents.
    directory = $HOME/torrents/downloads

    # Watch a directory for new torrents
    # SET your watch directory here --v
    schedule = watch_directory,5,5,$HOME/torrents/watch/*.torrent

    port_range = 60125-64125
    port_random = yes
    dht = auto

    # UDP port to use for DHT.
    dht_port = 63425

    # Enable peer exchange (for torrents not marked private)
    peer_exchange = yes

    # Check hash for finished torrents.
    check_hash = yes

    encryption = allow_incoming,try_outgoing ,enable_retry


    Then it is a simple matter of "save as" into $HOME/torrents/watch.



    Change $HOME/torrents/watch to whatever torrents subfolder you use, or at least $HOME to /home/username



    Create a file and add the following script:



    FILE: maglink-rtorrent.sh



    #!/bin/bash

    cd $HOME/torrents/watch # set your watch directory here
    [[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
    echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"


    Don't forget to make it executable



    chmod +x maglink-rtorrent.sh


    This also offers the ability to download from terminal by:



    cd $HOME/torrents/watch
    ./maglink-rtorrent.sh "MAGNET-LINK-HERE"


    Further awesome Service Tips and rTorrent setup options here.



    Futher credits:




    • magnet links and command line 1

    • magnet links and command line 2


    Update 2:



    If not using rTorrent, but kTorrent or qBittorent, then this following is the way to get that running:



    # check defaults
    xdg-mime query default x-scheme-handler/magnet
    gvfs-mime --query x-scheme-handler/magnet

    # set defaults
    xdg-mime default qBittorent.desktop x-scheme-handler/magnet
    gvfs-mime --set x-scheme-handler/magnet qBittorrent.desktop


    There's a further setting (from memory) for whether you require commandline.



    For rTorrent though, this link is the FlexGet rTorrent Magnet URI Handler



    Full information here.



    Hope this helps.






    share|improve this answer





















    • 2





      I have managed to crack this one on my own using: paxmontem.blogspot.com.au/2012/03/… but I would be more than happy to award the bonus if you can bend your answer this way...

      – andrew.46
      Jul 8 '16 at 5:32











    • Ha! I was going to add that script to my answer, but chose not to for it being a terminal option - where I thought you were after a pure browser one-click option. link

      – greg.arnott
      Jul 8 '16 at 6:05











    • Not so much the terminal script on the bottom of your link. Looks like the Browser can be set to pass the magnet link to a script to clean it up and pass it to the rtorrent watch directory. I used this page: paxmontem.blogspot.com.au/2012/03/… but it all feeds off the ARCH wiki page...

      – andrew.46
      Jul 8 '16 at 6:18














    5





    +50







    5





    +50



    5




    +50





    The problems usually lie with mime type and default handlers.



    Firstly, have you changed Firefox's about:config settings? ie:



    network.protocol-handler.expose.magnet -> false


    and reset other options
    as per this Firefox deluge Q&A.



    Have you set up rTorrent to watch any particular directory?



    FILE: ~/.rtorrent.rc



    # Maximum and minimum number of peers to connect to per torrent.
    min_peers = 50
    max_peers = 80

    # Maximum number of simultanious uploads per torrent.
    max_uploads = 5

    # Global upload and download rate in KiB. "0" for unlimited.
    download_rate = 0
    upload_rate = 50

    # Default directory to save the downloaded torrents.
    directory = $HOME/torrents/downloads

    # Watch a directory for new torrents
    # SET your watch directory here --v
    schedule = watch_directory,5,5,$HOME/torrents/watch/*.torrent

    port_range = 60125-64125
    port_random = yes
    dht = auto

    # UDP port to use for DHT.
    dht_port = 63425

    # Enable peer exchange (for torrents not marked private)
    peer_exchange = yes

    # Check hash for finished torrents.
    check_hash = yes

    encryption = allow_incoming,try_outgoing ,enable_retry


    Then it is a simple matter of "save as" into $HOME/torrents/watch.



    Change $HOME/torrents/watch to whatever torrents subfolder you use, or at least $HOME to /home/username



    Create a file and add the following script:



    FILE: maglink-rtorrent.sh



    #!/bin/bash

    cd $HOME/torrents/watch # set your watch directory here
    [[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
    echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"


    Don't forget to make it executable



    chmod +x maglink-rtorrent.sh


    This also offers the ability to download from terminal by:



    cd $HOME/torrents/watch
    ./maglink-rtorrent.sh "MAGNET-LINK-HERE"


    Further awesome Service Tips and rTorrent setup options here.



    Futher credits:




    • magnet links and command line 1

    • magnet links and command line 2


    Update 2:



    If not using rTorrent, but kTorrent or qBittorent, then this following is the way to get that running:



    # check defaults
    xdg-mime query default x-scheme-handler/magnet
    gvfs-mime --query x-scheme-handler/magnet

    # set defaults
    xdg-mime default qBittorent.desktop x-scheme-handler/magnet
    gvfs-mime --set x-scheme-handler/magnet qBittorrent.desktop


    There's a further setting (from memory) for whether you require commandline.



    For rTorrent though, this link is the FlexGet rTorrent Magnet URI Handler



    Full information here.



    Hope this helps.






    share|improve this answer















    The problems usually lie with mime type and default handlers.



    Firstly, have you changed Firefox's about:config settings? ie:



    network.protocol-handler.expose.magnet -> false


    and reset other options
    as per this Firefox deluge Q&A.



    Have you set up rTorrent to watch any particular directory?



    FILE: ~/.rtorrent.rc



    # Maximum and minimum number of peers to connect to per torrent.
    min_peers = 50
    max_peers = 80

    # Maximum number of simultanious uploads per torrent.
    max_uploads = 5

    # Global upload and download rate in KiB. "0" for unlimited.
    download_rate = 0
    upload_rate = 50

    # Default directory to save the downloaded torrents.
    directory = $HOME/torrents/downloads

    # Watch a directory for new torrents
    # SET your watch directory here --v
    schedule = watch_directory,5,5,$HOME/torrents/watch/*.torrent

    port_range = 60125-64125
    port_random = yes
    dht = auto

    # UDP port to use for DHT.
    dht_port = 63425

    # Enable peer exchange (for torrents not marked private)
    peer_exchange = yes

    # Check hash for finished torrents.
    check_hash = yes

    encryption = allow_incoming,try_outgoing ,enable_retry


    Then it is a simple matter of "save as" into $HOME/torrents/watch.



    Change $HOME/torrents/watch to whatever torrents subfolder you use, or at least $HOME to /home/username



    Create a file and add the following script:



    FILE: maglink-rtorrent.sh



    #!/bin/bash

    cd $HOME/torrents/watch # set your watch directory here
    [[ "$1" =~ xt=urn:btih:([^&/]+) ]] || exit;
    echo "d10:magnet-uri${#1}:${1}e" > "meta-${BASH_REMATCH[1]}.torrent"


    Don't forget to make it executable



    chmod +x maglink-rtorrent.sh


    This also offers the ability to download from terminal by:



    cd $HOME/torrents/watch
    ./maglink-rtorrent.sh "MAGNET-LINK-HERE"


    Further awesome Service Tips and rTorrent setup options here.



    Futher credits:




    • magnet links and command line 1

    • magnet links and command line 2


    Update 2:



    If not using rTorrent, but kTorrent or qBittorent, then this following is the way to get that running:



    # check defaults
    xdg-mime query default x-scheme-handler/magnet
    gvfs-mime --query x-scheme-handler/magnet

    # set defaults
    xdg-mime default qBittorent.desktop x-scheme-handler/magnet
    gvfs-mime --set x-scheme-handler/magnet qBittorrent.desktop


    There's a further setting (from memory) for whether you require commandline.



    For rTorrent though, this link is the FlexGet rTorrent Magnet URI Handler



    Full information here.



    Hope this helps.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 13 '17 at 12:25









    Community

    1




    1










    answered Jul 8 '16 at 5:25









    greg.arnottgreg.arnott

    21613




    21613








    • 2





      I have managed to crack this one on my own using: paxmontem.blogspot.com.au/2012/03/… but I would be more than happy to award the bonus if you can bend your answer this way...

      – andrew.46
      Jul 8 '16 at 5:32











    • Ha! I was going to add that script to my answer, but chose not to for it being a terminal option - where I thought you were after a pure browser one-click option. link

      – greg.arnott
      Jul 8 '16 at 6:05











    • Not so much the terminal script on the bottom of your link. Looks like the Browser can be set to pass the magnet link to a script to clean it up and pass it to the rtorrent watch directory. I used this page: paxmontem.blogspot.com.au/2012/03/… but it all feeds off the ARCH wiki page...

      – andrew.46
      Jul 8 '16 at 6:18














    • 2





      I have managed to crack this one on my own using: paxmontem.blogspot.com.au/2012/03/… but I would be more than happy to award the bonus if you can bend your answer this way...

      – andrew.46
      Jul 8 '16 at 5:32











    • Ha! I was going to add that script to my answer, but chose not to for it being a terminal option - where I thought you were after a pure browser one-click option. link

      – greg.arnott
      Jul 8 '16 at 6:05











    • Not so much the terminal script on the bottom of your link. Looks like the Browser can be set to pass the magnet link to a script to clean it up and pass it to the rtorrent watch directory. I used this page: paxmontem.blogspot.com.au/2012/03/… but it all feeds off the ARCH wiki page...

      – andrew.46
      Jul 8 '16 at 6:18








    2




    2





    I have managed to crack this one on my own using: paxmontem.blogspot.com.au/2012/03/… but I would be more than happy to award the bonus if you can bend your answer this way...

    – andrew.46
    Jul 8 '16 at 5:32





    I have managed to crack this one on my own using: paxmontem.blogspot.com.au/2012/03/… but I would be more than happy to award the bonus if you can bend your answer this way...

    – andrew.46
    Jul 8 '16 at 5:32













    Ha! I was going to add that script to my answer, but chose not to for it being a terminal option - where I thought you were after a pure browser one-click option. link

    – greg.arnott
    Jul 8 '16 at 6:05





    Ha! I was going to add that script to my answer, but chose not to for it being a terminal option - where I thought you were after a pure browser one-click option. link

    – greg.arnott
    Jul 8 '16 at 6:05













    Not so much the terminal script on the bottom of your link. Looks like the Browser can be set to pass the magnet link to a script to clean it up and pass it to the rtorrent watch directory. I used this page: paxmontem.blogspot.com.au/2012/03/… but it all feeds off the ARCH wiki page...

    – andrew.46
    Jul 8 '16 at 6:18





    Not so much the terminal script on the bottom of your link. Looks like the Browser can be set to pass the magnet link to a script to clean it up and pass it to the rtorrent watch directory. I used this page: paxmontem.blogspot.com.au/2012/03/… but it all feeds off the ARCH wiki page...

    – andrew.46
    Jul 8 '16 at 6:18













    1














    The following script is a spin on Max Gonzih's code that works both with regular .torrent files and magnet links:



    #!/bin/bash

    torrent_file_or_magnet_link="$1"

    # Edit rtorrent.rc to automatically start downloads when a .torrent file
    # appears in this directory.
    cd "$HOME/.rtorrent/watch/start/"

    # XT stands for "exact topic".
    # BTIH is the BitTorrent info hash:
    # https://en.wikipedia.org/wiki/Magnet_URI_scheme#BitTorrent_info_hash_(BTIH)
    # This is the hex-encoded SHA-1 hash of the torrent file info section
    magnet_regex="xt=urn:btih:([^&/]+)"
    if [[ "$torrent_file_or_magnet_link" =~ $magnet_regex ]]; then
    torrent_hash=${BASH_REMATCH[1]};
    magnet_link_length=${#torrent_file_or_magnet_link}
    # To conform with the bencode encoding, the magnet link's number of characters
    # must be part of the torrent file, otherwise rTorrent can't read it.
    # Same for the "e" at the end.
    # See https://en.wikipedia.org/wiki/Bencode
    torrent_file_content="d10:magnet-uri${magnet_link_length}:${torrent_file_or_magnet_link}e"

    # Note that rTorrent will read this torrent file, start downloading
    # the file and then remove the torrent file
    echo "$torrent_file_content" > "$torrent_hash.torrent"
    else
    cp "$torrent_file_or_magnet_link" .
    fi


    You can use this in a script (let's call it pass_to_rtorrent.sh) and have Firefox pass the torrent file or magnet link to the script:



    Firefox rTorrent screenshot



    Make sure the script is executable: chmod +x pass_to_rtorrent.sh






    share|improve this answer






























      1














      The following script is a spin on Max Gonzih's code that works both with regular .torrent files and magnet links:



      #!/bin/bash

      torrent_file_or_magnet_link="$1"

      # Edit rtorrent.rc to automatically start downloads when a .torrent file
      # appears in this directory.
      cd "$HOME/.rtorrent/watch/start/"

      # XT stands for "exact topic".
      # BTIH is the BitTorrent info hash:
      # https://en.wikipedia.org/wiki/Magnet_URI_scheme#BitTorrent_info_hash_(BTIH)
      # This is the hex-encoded SHA-1 hash of the torrent file info section
      magnet_regex="xt=urn:btih:([^&/]+)"
      if [[ "$torrent_file_or_magnet_link" =~ $magnet_regex ]]; then
      torrent_hash=${BASH_REMATCH[1]};
      magnet_link_length=${#torrent_file_or_magnet_link}
      # To conform with the bencode encoding, the magnet link's number of characters
      # must be part of the torrent file, otherwise rTorrent can't read it.
      # Same for the "e" at the end.
      # See https://en.wikipedia.org/wiki/Bencode
      torrent_file_content="d10:magnet-uri${magnet_link_length}:${torrent_file_or_magnet_link}e"

      # Note that rTorrent will read this torrent file, start downloading
      # the file and then remove the torrent file
      echo "$torrent_file_content" > "$torrent_hash.torrent"
      else
      cp "$torrent_file_or_magnet_link" .
      fi


      You can use this in a script (let's call it pass_to_rtorrent.sh) and have Firefox pass the torrent file or magnet link to the script:



      Firefox rTorrent screenshot



      Make sure the script is executable: chmod +x pass_to_rtorrent.sh






      share|improve this answer




























        1












        1








        1







        The following script is a spin on Max Gonzih's code that works both with regular .torrent files and magnet links:



        #!/bin/bash

        torrent_file_or_magnet_link="$1"

        # Edit rtorrent.rc to automatically start downloads when a .torrent file
        # appears in this directory.
        cd "$HOME/.rtorrent/watch/start/"

        # XT stands for "exact topic".
        # BTIH is the BitTorrent info hash:
        # https://en.wikipedia.org/wiki/Magnet_URI_scheme#BitTorrent_info_hash_(BTIH)
        # This is the hex-encoded SHA-1 hash of the torrent file info section
        magnet_regex="xt=urn:btih:([^&/]+)"
        if [[ "$torrent_file_or_magnet_link" =~ $magnet_regex ]]; then
        torrent_hash=${BASH_REMATCH[1]};
        magnet_link_length=${#torrent_file_or_magnet_link}
        # To conform with the bencode encoding, the magnet link's number of characters
        # must be part of the torrent file, otherwise rTorrent can't read it.
        # Same for the "e" at the end.
        # See https://en.wikipedia.org/wiki/Bencode
        torrent_file_content="d10:magnet-uri${magnet_link_length}:${torrent_file_or_magnet_link}e"

        # Note that rTorrent will read this torrent file, start downloading
        # the file and then remove the torrent file
        echo "$torrent_file_content" > "$torrent_hash.torrent"
        else
        cp "$torrent_file_or_magnet_link" .
        fi


        You can use this in a script (let's call it pass_to_rtorrent.sh) and have Firefox pass the torrent file or magnet link to the script:



        Firefox rTorrent screenshot



        Make sure the script is executable: chmod +x pass_to_rtorrent.sh






        share|improve this answer















        The following script is a spin on Max Gonzih's code that works both with regular .torrent files and magnet links:



        #!/bin/bash

        torrent_file_or_magnet_link="$1"

        # Edit rtorrent.rc to automatically start downloads when a .torrent file
        # appears in this directory.
        cd "$HOME/.rtorrent/watch/start/"

        # XT stands for "exact topic".
        # BTIH is the BitTorrent info hash:
        # https://en.wikipedia.org/wiki/Magnet_URI_scheme#BitTorrent_info_hash_(BTIH)
        # This is the hex-encoded SHA-1 hash of the torrent file info section
        magnet_regex="xt=urn:btih:([^&/]+)"
        if [[ "$torrent_file_or_magnet_link" =~ $magnet_regex ]]; then
        torrent_hash=${BASH_REMATCH[1]};
        magnet_link_length=${#torrent_file_or_magnet_link}
        # To conform with the bencode encoding, the magnet link's number of characters
        # must be part of the torrent file, otherwise rTorrent can't read it.
        # Same for the "e" at the end.
        # See https://en.wikipedia.org/wiki/Bencode
        torrent_file_content="d10:magnet-uri${magnet_link_length}:${torrent_file_or_magnet_link}e"

        # Note that rTorrent will read this torrent file, start downloading
        # the file and then remove the torrent file
        echo "$torrent_file_content" > "$torrent_hash.torrent"
        else
        cp "$torrent_file_or_magnet_link" .
        fi


        You can use this in a script (let's call it pass_to_rtorrent.sh) and have Firefox pass the torrent file or magnet link to the script:



        Firefox rTorrent screenshot



        Make sure the script is executable: chmod +x pass_to_rtorrent.sh







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 16 '18 at 18:46

























        answered Dec 16 '18 at 18:25









        Matthias BraunMatthias Braun

        257310




        257310






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f787100%2fhow-to-open-magnet-torrent-links-from-firefox-in-rtorrent%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to send String Array data to Server using php in android

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Is anime1.com a legal site for watching anime?