{"id":17338858,"url":"https://github.com/billyb2/magnet-url-rs","last_synced_at":"2025-04-14T17:30:36.370Z","repository":{"id":37487242,"uuid":"339234225","full_name":"billyb2/magnet-url-rs","owner":"billyb2","description":" A simple, hackable magnet url parser in Rust ","archived":false,"fork":false,"pushed_at":"2022-11-10T04:08:12.000Z","size":53,"stargazers_count":15,"open_issues_count":3,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-05T11:07:51.464Z","etag":null,"topics":["magnet","parser","parsing","torrent"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/billyb2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-15T23:22:01.000Z","updated_at":"2024-08-01T16:58:52.000Z","dependencies_parsed_at":"2023-01-21T12:01:35.529Z","dependency_job_id":null,"html_url":"https://github.com/billyb2/magnet-url-rs","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billyb2%2Fmagnet-url-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billyb2%2Fmagnet-url-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billyb2%2Fmagnet-url-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billyb2%2Fmagnet-url-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/billyb2","download_url":"https://codeload.github.com/billyb2/magnet-url-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219843431,"owners_count":16556506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["magnet","parser","parsing","torrent"],"created_at":"2024-10-15T15:39:58.104Z","updated_at":"2024-10-15T15:39:58.670Z","avatar_url":"https://github.com/billyb2.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# What is a magnet url\nA magnet is a URI scheme that identifies files by their hash,\nnormally used in peer to peer file sharing networks (like\nBittorrent). Basically, a magnet link identifies a torrent you\nwant to download, and tells the torrent client how to download\nit. They make it very easy to share files over the internet,\nand use a combination of DHT and trackers to tell your torrent\nclient where other peers who can share the file with you are.\n\n# Why is magnet_url\nWhile working on a side project, I realized that I had the\nmisfortune of trying to get the component parts of a magnet-url\nand then do further processing of them. I quickly wrote some\nRegex for it, but then I realized that this would be really\nuseful for other projects that are dealing with torrents in\nRust. By making it modifiable, too, it would allow for the\ncreation of custom magnet links, which would also be useful for\ntorrent based projects.\n\n# Why use magnet_url\nmagnet_url has the goal of, as you may have guessed, parsing the parts of magnets. It does\nthis using some relatively simple regexes. The crate is designed to be very simple and efficient,\nwith a lot of flexibility. It's also designed to be relatively easy to handle errors, and\nmodification of its source is greatly encouraged through documentation and its license.\n\n## How to use this crate\nParsing a magnet is very simple:\n\n ```rust\n use magnet_url::Magnet;\n let magneturl = Magnet::new(\"magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10\u0026dn=Sintel\u0026tr=udp%3A%2F%2Fexplodie.org%3A6969\u0026tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969\u0026tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337\u0026tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969\u0026tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337\u0026tr=wss%3A%2F%2Ftracker.btorrent.xyz\u0026tr=wss%3A%2F%2Ftracker.fastcast.nz\u0026tr=wss%3A%2F%2Ftracker.openwebtorrent.com\u0026ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F\u0026xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent\");\n ```\n\nThis returns the Magnet struct, which is made up of the fields listed below this section. To\naccess one of these fields is also very simple:\n\n ```rust\n use magnet_url::Magnet;\n let magneturl = Magnet::new(\"magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10\u0026dn=Sintel\u0026tr=udp%3A%2F%2Fexplodie.org%3A6969\u0026tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969\u0026tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337\u0026tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969\u0026tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337\u0026tr=wss%3A%2F%2Ftracker.btorrent.xyz\u0026tr=wss%3A%2F%2Ftracker.fastcast.nz\u0026tr=wss%3A%2F%2Ftracker.openwebtorrent.com\u0026ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F\u0026xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent\");\n println!(\"{:?}\", magneturl.dn);\n ```\n\nIf you'd like to modify parts of the magnet_url to customize it, that can be done as well!\n\n ```rust\n use magnet_url::Magnet;\n let mut magneturl = Magnet::new(\"magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10\u0026dn=Sintel\u0026tr=udp%3A%2F%2Fexplodie.org%3A6969\u0026tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969\u0026tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337\u0026tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969\u0026tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337\u0026tr=wss%3A%2F%2Ftracker.btorrent.xyz\u0026tr=wss%3A%2F%2Ftracker.fastcast.nz\u0026tr=wss%3A%2F%2Ftracker.openwebtorrent.com\u0026ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F\u0026xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent\");\n println!(\"{:?}\", magneturl.dn);\n magneturl.dn = String::from(\"hello_world\");\n println!(\"{:?}\", magneturl.dn);\n ```\n\nIn fact, you can construct your own magnet url as well, as long as you fill in all the\nparameters!\n\n ```rust\n use magnet_url::Magnet;\n //Note, this magnet won't actually download, sorry :/\n Magnet {\n     dn: \"hello_world\".to_string(),\n     hash_type: \"sha1\".to_string(),\n     xt: \"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed\".to_string(),\n     xl: 1234567890,\n     tr:\n         {\n             let mut tr_vec = Vec::new();\n             tr_vec.push(\"https://example.com/\".to_string());\n             tr_vec\n         },\n     kt: \"cool+stuff\".to_string(),\n     ws: String::new(),\n     acceptable_source: String::new(),\n     mt: String::new(),\n     xs: String::new(),\n };\n ```\n\nFrom a Magnet struct, you can generate a magnet string again\n\n ```rust\n use magnet_url::Magnet;\n //Note, this magnet won't actually download, sorry :/\n let magnet_struct = Magnet {\n     dn: \"hello_world\".to_string(),\n     hash_type: \"sha1\".to_string(),\n     xt: \"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed\".to_string(),\n     xl: 1234567890,\n     tr: vec![\"https://example.com/\".to_string()],\n     kt: \"cool+stuff\".to_string(),\n     ws: String::new(),\n     acceptable_source: String::new(),\n     mt: String::new(),\n     xs: String::new(),\n };\n\n let magnet_string = magnet_struct.to_string();\n println!(\"{}\", magnet_string);\n ```\n\nInvalid magnet url's will result in a `panic!` (This will be changed to an error in v2.0.0\n ```rust\n use magnet_url::Magnet;\n #[should_panic]\n let _magnet_link = Magnet::new(\"https://example.com\");\n ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbillyb2%2Fmagnet-url-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbillyb2%2Fmagnet-url-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbillyb2%2Fmagnet-url-rs/lists"}