#bittorrent #magnet #uri #parse #convert #data

rs_torrent_magnet

Parse torrent file and convert to Magnet URI

3 releases (breaking)

new 0.3.0 Dec 12, 2024
0.2.0 Apr 5, 2024
0.1.0 Apr 4, 2024

#1080 in Network programming

Download history 11/week @ 2024-09-23 20/week @ 2024-09-30 1/week @ 2024-10-07 147/week @ 2024-12-09

147 downloads per month

MIT/Apache

26KB
136 lines

Parse torrent file and transform Torrent Files to a magnet URI

  • Get Magnet URI from torrent file
        let path = PathBuf::from_str("test_data/big-buck-bunny.torrent").unwrap();
        let result = magnet_from_torrent_file(path);
        assert_eq!(result, "magnet:?xt=urn:btih:3WBFL3G4PSSV7MF37AJSHWDQMLNR63I4&dn=Big%20Buck%20Bunny&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.fastcast.nz");
  • Get Magnet URI from torrent raw data
        let mut file = File::open("test_data/big-buck-bunny.torrent").unwrap();
        let mut encoded = Vec::new();
        file.read_to_end(&mut encoded).unwrap();

        let result = magnet_from_torrent(encoded);
        assert_eq!(result, "magnet:?xt=urn:btih:3WBFL3G4PSSV7MF37AJSHWDQMLNR63I4&dn=Big%20Buck%20Bunny&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.fastcast.nz");
  • Get torrent details
        let path = PathBuf::from_str("test_data/big-buck-bunny.torrent").unwrap();
        let result = decode_file(path);
        assert_eq!(result.hash, "3WBFL3G4PSSV7MF37AJSHWDQMLNR63I4");
        assert_eq!(result.torrent.info.name, Some("Big Buck Bunny".to_owned()));

Dependencies

~1.6–2.3MB
~50K SLoC