Compare commits

..

6 commits
0.2.0 ... main

Author SHA1 Message Date
ghost
74de022cd5 fix namespace 2023-10-09 04:52:01 +03:00
ghost
26111fce28 remove neitanod/forceutf8 dependency 2023-09-20 15:18:16 +03:00
ghost
47c7d13697 add neitanod/forceutf8 dependency 2023-09-20 14:28:52 +03:00
ghost
81f019be7a fix 0x1220 multihash prefix for v2 btmh part 2023-09-05 19:15:29 +03:00
ghost
c32a3b5f7d add trim to filterInfoHash method 2023-09-04 01:38:55 +03:00
ghost
6c73a68024 add info hash v2 support 2023-09-04 00:16:37 +03:00
4 changed files with 32 additions and 5 deletions

View file

@ -1,6 +1,6 @@
<?php
namespace YGGverse\Parser;
namespace Yggverse\Parser;
class Magnet {
@ -9,13 +9,38 @@ class Magnet {
return ('magnet' == parse_url($link, PHP_URL_SCHEME));
}
public static function isXTv1(string $xt) : bool
{
return ('urn' == parse_url($xt, PHP_URL_SCHEME) && false !== strpos($xt, ':btih:'));
}
public static function isXTv2(string $xt) : bool
{
return ('urn' == parse_url($xt, PHP_URL_SCHEME) && false !== strpos($xt, ':btmh:1220'));
}
public static function filterInfoHash(string $value) : string
{
return trim(
str_replace(
[
'urn:',
'btih:',
'btmh:1220',
],
false,
$value
)
);
}
public static function parse(string $link) : mixed
{
$result =
[
'xt' => null,
'dn' => null,
'xl' => 0,
'xt' => [],
'tr' => [],
'ws' => [],
'as' => [],
@ -37,6 +62,7 @@ class Magnet {
[
'magnet:',
'?',
'xt=',
'tr=',
'ws=',
'as=',
@ -47,6 +73,7 @@ class Magnet {
[
false,
false,
'xt[]=',
'tr[]=',
'ws[]=',
'as[]=',

View file

@ -1,6 +1,6 @@
<?php
namespace YGGverse\Parser;
namespace Yggverse\Parser;
class Url {

View file

@ -1,6 +1,6 @@
<?php
namespace YGGverse\Parser;
namespace Yggverse\Parser;
class Urn {

View file

@ -1,6 +1,6 @@
<?php
namespace YGGverse\Parser\Tests;
namespace Yggverse\Parser\Tests;
use PHPUnit\Framework\TestCase;