diff --git a/src/Magnet.php b/src/Magnet.php new file mode 100644 index 0000000..f90a59a --- /dev/null +++ b/src/Magnet.php @@ -0,0 +1,119 @@ + null, + 'xl' => 0, + 'xt' => [], + 'tr' => [], + 'ws' => [], + 'as' => [], + 'xs' => [], + 'kt' => [], + 'mt' => [], + 'so' => [], + 'x.pe' => [], + ]; + + if (!self::is($link)) + { + return false; + } + + $link = urldecode($link); + + $link = str_replace( + [ + 'magnet:', + '?', + 'xt=', + 'tr=', + 'ws=', + 'as=', + 'xs=', + 'mt=', + 'x.pe=', + ], + [ + false, + false, + 'xt[]=', + 'tr[]=', + 'ws[]=', + 'as[]=', + 'xs[]=', + 'mt[]=', + 'x.pe[]=', + ], + $link + ); + + parse_str($link, $attributes); + + switch (true) + { + case empty($attributes['xt']): + case empty($attributes['tr']): + // ... + + return false; + } + + foreach ((array) $attributes as $key => $value) + { + + switch ($key) + { + case 'kt': + + foreach ((array) explode(' ', $value) as $keyword) + { + $result[$key][] = trim($keyword); + } + + break; + default: + + $result[$key] = $value; + } + } + + return (object) $result; + } +} \ No newline at end of file diff --git a/src/Url.php b/src/Url.php index c4bcfd1..93b3eff 100644 --- a/src/Url.php +++ b/src/Url.php @@ -1,6 +1,6 @@ implode(':', $part), + 'parts' => $part, + ]; + + return (object) $result; + } + + return false; + } +} \ No newline at end of file diff --git a/tests/UrlTest.php b/tests/UrlTest.php index 19707f6..b8117d1 100644 --- a/tests/UrlTest.php +++ b/tests/UrlTest.php @@ -1,6 +1,6 @@