0

Does anyone here know of a magnet-URI-parser for PHP? To validate it, or maybe to extract some information from it?

hakre
  • 193,403
  • 52
  • 435
  • 836
Wieger
  • 663
  • 1
  • 9
  • 24
  • What's your problem to extract some data from a magnet-URI? Please explain what you have done so far and into which problem you've run. – hakre Jul 09 '11 at 10:17
  • Probably related: [Problem creating info hash of torrent file](http://stackoverflow.com/questions/6527357/problem-creating-info-hash-of-torrent-file) – hakre Jul 09 '11 at 10:17

3 Answers3

3

If you only need the fields, here is a quick and dirty one liner:

$link = 'magnet:?xt=urn:btih:0eb69459a28b08400c5f05bad3e63235b9853021&dn=Splinter.Cell.Blacklist-RELOADED&tr=udp%3A%2F%2Ftracker.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337';

parse_str(str_replace('tr=','tr[]=',parse_url($link,PHP_URL_QUERY)),$query);

print_r($query);

Should yield:

 Array
 (
    [xt] => urn:btih:0eb69459a28b08400c5f05bad3e63235b9853021
    [dn] => Splinter.Cell.Blacklist-RELOADED
    [tr] => Array
        (
            [0] => udp://tracker.com:80
            [1] => udp://tracker.publicbt.com:80
            [2] => udp://tracker.istole.it:6969
            [3] => udp://tracker.ccc.de:80
            [4] => udp://open.demonii.com:1337
        )
)
Noener
  • 31
  • 2
2

In case you're looking for something like this:

Magnet URI: magnet:?xt=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C (valid)

  Display Name .... (dn): 
  eXact Length .... (xl): 
  eXact Topic ..... (xt): urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C
  Acceptable Source (as): 
  eXact Source .... (xs): 
  Keyword Topic ... (kt): 
  Manifest Topic .. (mt): 
  address TRacker . (tr): 

take a look at the Demo.

Can't say if this matches your need, your question was sort of unspecific. So leave a comment.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • I know how to extract name/value-pairs, but I would have thought there were more complicated validation rules. And also, how can I resolve the Exact Topic to a filename and size? – Wieger Jul 11 '11 at 07:24
  • No magnet links are dead simple, there are not more complicated validation rules for the URI. You can however validate the data that can be extracted from that URI. However, that's a domain of it's own per data-type. E.g. validation for keywords depends on how you would like them to validate. Exact topic is not a filename and does not cover size, so you can not find the filename or size. You can only search p2p magnet lookup services for the URI itself. But that's totally unrelated to URI parsing and validation for which you have asked. – hakre Jul 11 '11 at 10:00
0
<?php
include_once "alfa.hash2mui.class.php";
$h2m=new Hash2mui();
echo $h2m->grab_mui("11A2AC68A11634E980F265CB1433C599D017A759");
?>

source https://github.com/alfredfrancis/Info-Hash-To-Magnet-URI/blob/master/example.php

Alfred Francis
  • 451
  • 1
  • 6
  • 20