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

rs_torrent_magnet

解析种子文件并将其转换为磁力链接URI

2个不稳定版本

0.2.0 2024年4月5日
0.1.0 2024年4月4日

#1078 in 网络编程

每月25次下载

MIT/Apache

25KB
114

解析种子文件并将其转换为磁力链接URI

  • 从种子文件中获取磁力链接URI
        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");
  • 从种子原始数据中获取磁力链接URI
        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");
  • 获取种子详情
        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()));

依赖项

~1–1.6MB
~37K SLoC